Skip to content

Commit

Permalink
docs: improve readme (#616)
Browse files Browse the repository at this point in the history
  • Loading branch information
cap-Bernardito authored Oct 13, 2020
1 parent 2946edc commit 3d017a2
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,43 @@ module.exports = {
};
```

### Common use case

`mini-css-extract-plugin` is more often used in `production` mode to get separate css files.
For `development` mode (including `webpack-dev-server`) you can use `style-loader`, because it injects CSS into the DOM using multiple <style></style> and works faster.

> i Do not use together `style-loader` and `mini-css-extract-plugin`.
**webpack.config.js**

```js
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const devMode = process.env.NODE_ENV !== 'production';

const plugins = [];
if (!devMode) {
// enable in production only
plugins.push(new MiniCssExtractPlugin());
}

module.exports = {
plugins,
module: {
rules: [
{
test: /\.(sa|sc|c)ss$/,
use: [
devMode ? 'style-loader' : MiniCssExtractPlugin.loader,
'css-loader',
'postcss-loader',
'sass-loader',
],
},
],
},
};
```

### The `publicPath` option as function

**webpack.config.js**
Expand Down

0 comments on commit 3d017a2

Please sign in to comment.