Skip to content

Commit 7b9380a

Browse files
committed
Rephrase dev/prod dynamic adjustments to the config
1 parent 35402be commit 7b9380a

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

README.md

+6-3
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ A better option is to extract the CSS into a separate file. Using the `emitCss`
6565

6666
```javascript
6767
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
68-
const dev = mode == 'development';
68+
const mode = process.env.NODE_ENV || 'development';
69+
const prod = mode === 'production';
6970
...
7071
module: {
7172
rules: [
@@ -83,7 +84,7 @@ A better option is to extract the CSS into a separate file. Using the `emitCss`
8384
{
8485
test: /\.css$/,
8586
use: [
86-
dev ? 'style-loader' : MiniCssExtractPlugin.loader,
87+
prod ? MiniCssExtractPlugin.loader :'style-loader',
8788
{
8889
loader: 'css-loader',
8990
options: {
@@ -103,7 +104,9 @@ A better option is to extract the CSS into a separate file. Using the `emitCss`
103104
...
104105
```
105106

106-
Note that the configuration shown above switches off `MiniCssExtractPlugin` in development mode in favour of using CSS javascript injection. This is recommended by `MiniCssExtractPlugin` because it does not support hot reloading. `dev` is some boolean flag indicating that the build is development.
107+
Note that the configuration shown above switches off `MiniCssExtractPlugin` in development mode in favour of using CSS javascript injection. This is recommended by `MiniCssExtractPlugin` because it does not support hot reloading.
108+
109+
`prod` indicates, that `NODE_ENV=production` has been set from `package.json` or manually (`NODE_ENV=production npx webpack`) for production builds. We can rely on that to make dynamic adjustments to the config.
107110

108111
Additionally, if you're using multiple entrypoints, you may wish to change `new MiniCssExtractPlugin('styles.css')` for `new MiniCssExtractPlugin('[name].css')` to generate one CSS file per entrypoint.
109112

0 commit comments

Comments
 (0)