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
This plugin should be used only on `production` builds without `style-loader` in the loaders chain, especially if you want to have HMR in `development`.
157
+
158
+
Here is an example to have both HMR in `development` and your styles extracted in a file for `production` builds.
159
+
160
+
(Loaders options left out for clarity, adapt accordingly to your needs.)
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.
201
+
202
+
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
212
+
// both options are optional
213
+
filename:'[name].css',
214
+
chunkFilename:'[id].css',
215
+
}),
216
+
],
217
+
module: {
218
+
rules: [
219
+
{
220
+
test:/\.css$/,
221
+
use: [
222
+
{
223
+
loader:MiniCssExtractPlugin.loader,
224
+
options: {
225
+
// only enable hot in development
226
+
hot:process.env.NODE_ENV==='development',
227
+
// if hmr does not work, this is a forceful method.
228
+
reloadAll:true,
229
+
},
230
+
},
231
+
'css-loader',
232
+
],
233
+
},
234
+
],
235
+
},
236
+
};
237
+
```
238
+
239
+
### Minimizing For Production
240
+
241
+
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:
This is a breaking change. The entire loader has been fundamentally rewritten specifically for Webpack 4. Aiming to support our existing user base, allowing them to upgrade their infrastructure to support Webpack 4 based universally code-split server-side rendered react applications.
0 commit comments