postcss-modules-extract-exports

Extracts ICSS exports that are represented in CSS

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
postcss-modules-extract-exports
101.0.08 years ago8 years agoMinified + gzip package size for postcss-modules-extract-exports in KB

Readme

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',
// };