An open API service indexing awesome lists of open source software.

https://github.com/nitive/babel-plugin-css-modules-react


https://github.com/nitive/babel-plugin-css-modules-react

Last synced: about 1 year ago
JSON representation

Awesome Lists containing this project

README

          

# Babel Plugin CSS Modules React
[![Circle CI](https://circleci.com/gh/Nitive/babel-plugin-css-modules-react.svg?style=svg)](https://circleci.com/gh/Nitive/babel-plugin-css-modules-react)
[![codecov.io](https://codecov.io/github/Nitive/babel-plugin-css-modules-react/coverage.svg?branch=master)](https://codecov.io/github/Nitive/babel-plugin-css-modules-react?branch=master)

## What's the Problem?
webpack css-loader itself has several disadvantages:

- You have to use camelCase CSS class names.
- Mixing CSS Modules and global CSS classes is cumbersome.
- Reference to an undefined CSS Module resolves to undefined without a warning.

### Babel Plugin React CSS Modules make all work for you

#### Use classes as usual
```javascript
import styles from './styles.css'

class Button extends React.Component {
render() {
return { this.props.children }
}
}
```
Will be converted into:
```javascript
import styles from './styles.css'

class Button extends React.Component {
render() {
return { this.props.children }
}
}
```

#### Easy use global CSS
```javascript
import styles from './styles.css'

const Button = ({ children }) => (
{ children }
)
```

#### Get warnings when you are mistaken
```javascript
import styles from './styles.css'

const Button = ({ children }) => (
{ children } // Warning: Class .erroneous-class is not specified in your css file
)
```

### Requirements
You *must* keep your classes map inside `styles` variable

## Future plans
Load styles with decorator syntax

```javascript
@modulize('./styles.css')
class Button extends React.Component {
render() {
return { this.props.children }
}
}
```