New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

babel-plugin-transform-jsx-css-modules

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-transform-jsx-css-modules

Transform className attributes in JSX to reference CSS Modules

1.0.0
latest
Source
npm
Version published
Maintainers
1
Created
Source

babel-plugin-transform-jsx-css-modules

Transforms className attributes in JSX to get css-modules' references.

npm version CI Status

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 styleName="root">
    <h1 className="paragraph">Hello World</h1>
    <p className="global" styleName="local">I'm an example!</p>
  </div>
)

Will be transpiled into

import __CSSM__ from './styles.css'

const Component = () => (
  <div className={__CSSM__['root']}>
    <h1 className="paragraph">Hello World</h1>
    <p className={["global", __CSSM__["local"]].join(" ")}>I'm an example!</p>
  </div>
)

Usage

  • Install plugin

    npm install --save-dev babel-plugin-transform-jsx-css-modules
    
  • Add plugin to your .babelrc file

    {
      "plugins": [
        "transform-jsx-css-modules"
      ]
    }
    

Options

NameTypeDefaultDescription
pathToStylesRegExp/^\.\/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:

{
  "plugins": [
    ["transform-jsx-css-modules", {
      "pathToStyles": "^\\.\\/module\\.scss$"
    }]
  ]
}
import './module.scss'

Will be transformed into:

import __CSSM__ from './module.scss'

FAQs

Package last updated on 07 Sep 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts