Skip to content

Commit

Permalink
Document how to enable CSS modules (#777)
Browse files Browse the repository at this point in the history
Document how to enable CSS modules
  • Loading branch information
ezuk authored and gauravtiwari committed Sep 8, 2017
1 parent f0ce2a5 commit ae84f5f
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions docs/webpack.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,29 @@ babelLoader.options.cacheDirectory = false
module.exports = environment
```

### Overriding Loader Options in Webpack 3+ (for CSS Modules etc.)

In Webpack 3+, if you'd like to specify additional or different options for a loader, edit `config/webpack/environment.js` and provide an options object to override. This is similar to the technique shown above, but the following example shows specifically how to apply CSS Modules, which is what you may be looking for:

```javascript
const { environment } = require('@rails/webpacker')
const merge = require('webpack-merge')

const myCssLoaderOptions = {
modules: true,
sourceMap: true,
localIdentName: '[name]__[local]___[hash:base64:5]'
}

const CSSLoader = environment.loaders.get('style').use.find(el => el.loader === 'css-loader')

CSSLoader.options = merge(CSSLoader.options, myCssLoaderOptions)

module.exports = environment
```

See [issue #756](https://github.com/rails/webpacker/issues/756#issuecomment-327148547) for additional discussion of this.


## Plugins

Expand Down

0 comments on commit ae84f5f

Please sign in to comment.