babel-plugin-transform-jsx-css-modules
Transforms className
attributes in JSX to get css-modules' references.
Note: It does not turn on CSS Modules in your project, it assumes that you made it yourself (via webpack and css-loader for example).
Example
import './styles.css' const Component = <div ="root"> <h1 ="paragraph">Hello World</h1> <p ="global" ="local"> an example!</p> </div>
Will be transpiled into
import __CSSM__ from './styles.css' const Component = <div => <h1 ="paragraph">Hello World</h1> <p => an example!</p> </div>
Usage
-
Install plugin
npm install --save-dev babel-plugin-transform-jsx-css-modules -
Add plugin to your
.babelrc
file
Options
Name | Type | Default | Description |
---|---|---|---|
pathToStyles |
RegExp |
/^\.\/styles\.css$/ |
It specifies what imports should be transformed Note: Escape symbols if you specify it as a string |
pathToStyles
If you set it to /^\.\/module\.scss$/
it will handle imports which start and end with ./module.scss
:
import './module.scss'
Will be transformed into:
import __CSSM__ from './module.scss'