Skip to content

Commit 3d017a2

Browse files
docs: improve readme (#616)
1 parent 2946edc commit 3d017a2

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

README.md

+37
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,43 @@ module.exports = {
352352
};
353353
```
354354

355+
### Common use case
356+
357+
`mini-css-extract-plugin` is more often used in `production` mode to get separate css files.
358+
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.
359+
360+
> i Do not use together `style-loader` and `mini-css-extract-plugin`.
361+
362+
**webpack.config.js**
363+
364+
```js
365+
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
366+
const devMode = process.env.NODE_ENV !== 'production';
367+
368+
const plugins = [];
369+
if (!devMode) {
370+
// enable in production only
371+
plugins.push(new MiniCssExtractPlugin());
372+
}
373+
374+
module.exports = {
375+
plugins,
376+
module: {
377+
rules: [
378+
{
379+
test: /\.(sa|sc|c)ss$/,
380+
use: [
381+
devMode ? 'style-loader' : MiniCssExtractPlugin.loader,
382+
'css-loader',
383+
'postcss-loader',
384+
'sass-loader',
385+
],
386+
},
387+
],
388+
},
389+
};
390+
```
391+
355392
### The `publicPath` option as function
356393

357394
**webpack.config.js**

0 commit comments

Comments
 (0)