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 extracts CSS into separate files. It creates a CSS file per JS file which contains CSS. It supports On-Demand-Loading of CSS and SourceMaps.
17
20
@@ -24,24 +27,132 @@ Compared to the extract-text-webpack-plugin:
24
27
- Easier to use
25
28
- Specific to CSS
26
29
27
-
<h2align="center">Install</h2>
30
+
## Getting Started
31
+
32
+
To begin, you'll need to install `mini-css-extract-plugin`:
28
33
29
34
```bash
30
35
npm install --save-dev mini-css-extract-plugin
31
36
```
32
37
33
-
<h2align="center">Usage</h2>
38
+
It's recommended to combine `mini-css-extract-plugin` with the [`css-loader`](https://github.com/webpack-contrib/css-loader)
39
+
40
+
Then add the loader and the plugin to your `webpack` config. For example:
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`.
161
275
@@ -199,16 +313,21 @@ module.exports = {
199
313
};
200
314
```
201
315
202
-
####Hot Module Reloading (HMR)
316
+
### Hot Module Reloading (HMR)
203
317
204
-
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.
318
+
The `mini-css-extract-plugin` supports hot reloading of actual css files in development.
319
+
Some options are provided to enable HMR of both standard stylesheets and locally scoped CSS or CSS modules.
320
+
Below is an example configuration of mini-css for HMR use with CSS modules.
205
321
206
-
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.
322
+
While we attempt to hmr css-modules. It is not easy to perform when code-splitting with custom chunk names.
323
+
`reloadAll` is an option that should only be enabled if HMR isn't working correctly.
324
+
The core challenge with css-modules is that when code-split, the chunk ids can and do end up different compared to the filename.
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:
364
+
To minify the output, use a plugin like [optimize-css-assets-webpack-plugin](https://github.com/NMFR/optimize-css-assets-webpack-plugin).
365
+
Setting `optimization.minimizer` overrides the defaults provided by webpack, so make sure to also specify a JS minimizer:
The runtime code detects already added CSS via `<link>` or `<style>` tag.
279
398
This can be useful when injecting CSS on server-side for Server-Side-Rendering.
280
399
The `href` of the `<link>` tag has to match the URL that will be used for loading the CSS chunk.
281
400
The `data-href` attribute can be used for `<link>` and `<style>` too.
282
401
When inlining CSS `data-href` must be used.
283
402
284
-
####Extracting all CSS in a single file
403
+
### Extracting all CSS in a single file
285
404
286
-
Similar to what [extract-text-webpack-plugin](https://github.com/webpack-contrib/extract-text-webpack-plugin) does, the CSS
287
-
can be extracted in one CSS file using `optimization.splitChunks.cacheGroups`.
405
+
Similar to what [extract-text-webpack-plugin](https://github.com/webpack-contrib/extract-text-webpack-plugin) does, the CSS can be extracted in one CSS file using `optimization.splitChunks.cacheGroups`.
With the `moduleFilename` option you can use chunk data to customize the filename. This is particularly useful when dealing with multiple entry points and wanting to get more control out of the filename for a given entry point/chunk. In the example below, we'll use `moduleFilename` to output the generated css into a different directory.
For projects where css ordering has been mitigated through consistent use of scoping or naming conventions, the css order warnings can be disabled by setting the ignoreOrder flag to true for the plugin.
0 commit comments