Skip to content

mightyaleksey/postcss-modules-extract-exports

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

postcss-modules-extract-exports

Extracts ICSS exports that are represented in CSS. Saves ICSS exports to the tokens property in the Root node which is generated by PostCSS.

Description

Usually, when you use postcss-modules-scope, you get :export selectors in CSS:

:export {
  continueButton: __buttons_continueButton_djd347adcxz9;
}
.__buttons_continueButton_djd347adcxz9 {
  color: green;
}

which are the part of ICSS format and are used by CSS Modules to export internal data to the consumer.

This module reads those exports, converts them to the plain object and saves to the tokens property at the Root node. Also removes them from the CSS. Example of usage:

const postcss = require('postcss');

const LocalByDefault = require('postcss-modules-local-by-default');
const ExtractImports = require('postcss-modules-extract-imports');
const Scope = require('postcss-modules-scope');
const ExtractExports = require('postcss-modules-extract-exports');

const css = '.continueButton\n{\n  color: green;\n}';
const filepath = '..'; // somefile

const tokens = postcss([LocalByDefault, ExtractImports, Scope, ExtractExports])
  .process(css, {from: filepath})
  .root.tokens;
// => {
//  continueButton: '__buttons_continueButton_djd347adcxz9',
// };

About

Extracts ICSS exports that are represented in CSS

Resources

License

Stars

Watchers

Forks

Packages

No packages published