Skip to content

Commit 417aaba

Browse files
docs: recommend (#1313)
1 parent ab92c82 commit 417aaba

File tree

1 file changed

+32
-8
lines changed

1 file changed

+32
-8
lines changed

README.md

+32-8
Original file line numberDiff line numberDiff line change
@@ -1131,6 +1131,38 @@ module.exports = {
11311131

11321132
## Examples
11331133

1134+
### Recommend
1135+
1136+
For `production` builds it's recommended to extract the CSS from your bundle being able to use parallel loading of CSS/JS resources later on.
1137+
This can be achieved by using the [mini-css-extract-plugin](https://github.com/webpack-contrib/mini-css-extract-plugin), because it creates separate css files.
1138+
For `development` mode (including `webpack-dev-server`) you can use [style-loader](https://github.com/webpack-contrib/style-loader), because it injects CSS into the DOM using multiple <style></style> and works faster.
1139+
1140+
> i Do not use together `style-loader` and `mini-css-extract-plugin`.
1141+
1142+
**webpack.config.js**
1143+
1144+
```js
1145+
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
1146+
const devMode = process.env.NODE_ENV !== "production";
1147+
1148+
module.exports = {
1149+
module: {
1150+
rules: [
1151+
{
1152+
test: /\.(sa|sc|c)ss$/,
1153+
use: [
1154+
devMode ? "style-loader" : MiniCssExtractPlugin.loader,
1155+
"css-loader",
1156+
"postcss-loader",
1157+
"sass-loader",
1158+
],
1159+
},
1160+
],
1161+
},
1162+
plugins: [].concat(devMode ? [] : [new MiniCssExtractPlugin()]),
1163+
};
1164+
```
1165+
11341166
### Disable url resolving using the `/* webpackIgnore: true */` comment
11351167

11361168
With the help of the `/* webpackIgnore: true */`comment, it is possible to disable sources handling for rules and for individual declarations.
@@ -1235,14 +1267,6 @@ module.exports = {
12351267
};
12361268
```
12371269

1238-
### Extract
1239-
1240-
For production builds it's recommended to extract the CSS from your bundle being able to use parallel loading of CSS/JS resources later on.
1241-
1242-
- This can be achieved by using the [mini-css-extract-plugin](https://github.com/webpack-contrib/mini-css-extract-plugin) to extract the CSS when running in production mode.
1243-
1244-
- As an alternative, if seeking better development performance and css outputs that mimic production. [extract-css-chunks-webpack-plugin](https://github.com/faceyspacey/extract-css-chunks-webpack-plugin) offers a hot module reload friendly, extended version of mini-css-extract-plugin. HMR real CSS files in dev, works like mini-css in non-dev
1245-
12461270
### Pure CSS, CSS modules and PostCSS
12471271

12481272
When you have pure CSS (without CSS modules), CSS modules and PostCSS in your project you can use this setup:

0 commit comments

Comments
 (0)