Babel plugin transform and extract PostCSS and CSS Modules to static CSS
This plugin is still at a very early stage and features are incomplete.
// index.js
import styles from './index.module.css'
// or
const styles = require('./index.module.css')
/* index.module.css */
.root {
display: flex;
}
Into an object that has properties mirroring the styles name in the compiled JS file:
// index.js
var styles = {"root":"_root_amfqe_1"};
And extract to styles.css
/* styles.css */
._root_amfqe_1 {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
}
Install from NPM
$ yarn add @envato/babel-plugin-postcss-cssmodules-transform -D
Add the plugin to .babelrc
.
{
"presets": [
["@babel/env", {
"targets": {
"browsers": ["last 2 versions"]
}
}],
"@babel/stage-3",
"@babel/react",
"@babel/typescript"
],
"plugins": [
["@envato/babel-plugin-postcss-cssmodules-transform", {
"extractCss": "./dist/styles.css"
}]
]
}
Check the /example
folder for a complete example.
- support
postcss.config.js
- unit test
This plugin is based on the two plugins below, and modified to support extractCss
option with full postcss
plugin support.
MIT