postcss-modules-extract-exports

1.0.0 • Public • Published

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 css = '.continueButton\n{\n  color: green;\n}';
const filepath = '..'; // somefile
 
const tokens = postcss([LocalByDefault, ExtractImports, Scope])
  .process(css, {from: filepath})
  .root.tokens;
// => {
//  continueButton: '__buttons_continueButton_djd347adcxz9',
// };

Dependents (0)

Package Sidebar

Install

npm i postcss-modules-extract-exports

Weekly Downloads

66

Version

1.0.0

License

MIT

Last publish

Collaborators

  • sullenor
  • evilebottnawi