You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
extract-mini-css-plugin supports hot reloading of actual css files in development. Some options are provided to enable HMR of both standard stylesheets and locally scoped CSS or CSS modules. Below is an example configuration of mini-css for HMR use with CSS modules.
169
+
170
+
171
+
While we attempt to hmr css-modules. It is not easy to perform when code-splitting with custom chunk names. `reloadAll` is an option that should only be enabled if HMR isn't working correctly. The core challenge with css-modules is that when code-split, the chunk ids can and do end up different compared to the filename.
// Options similar to the same options in webpackOptions.output
183
+
// both options are optional
184
+
filename:"[name].css",
185
+
chunkFilename:"[id].css"
186
+
})
187
+
],
188
+
module: {
189
+
rules: [
190
+
{
191
+
test:/\.css$/,
192
+
use: [
193
+
{
194
+
loader:MiniCssExtractPlugin.loader,
195
+
options: {
196
+
// only enable hot in development
197
+
hmr:process.env.NODE_ENV==='development',
198
+
// if hmr does not work, this is a forceful method.
199
+
reloadAll:true
200
+
}
201
+
},
202
+
"css-loader"
203
+
]
204
+
}
205
+
]
206
+
}
207
+
}
208
+
```
209
+
210
+
163
211
### Minimizing For Production
164
212
165
213
While webpack 5 is likely to come with a CSS minimizer built-in, with webpack 4 you need to bring your own. To minify the output, use a plugin like [optimize-css-assets-webpack-plugin](https://github.com/NMFR/optimize-css-assets-webpack-plugin). Setting `optimization.minimizer` overrides the defaults provided by webpack, so make sure to also specify a JS minimizer:
@@ -314,6 +362,10 @@ module.exports = {
314
362
315
363
For long term caching use `filename: "[contenthash].css"`. Optionally add `[name]`.
316
364
365
+
### Remove Order Warnings
366
+
367
+
If the terminal is getting bloated with chunk order warnings. You can filter by configuring [warningsFilter](https://webpack.js.org/configuration/stats/) withing the webpack stats option
368
+
317
369
### Media Query Plugin
318
370
319
371
If you'd like to extract the media queries from the extracted CSS (so mobile users don't need to load desktop or tablet specific CSS anymore) you should use one of the following plugins:
0 commit comments