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
If you like our work, check out our Redux-based router <ahref="https://github.com/faceyspacey/redux-first-router"target="_blank">redux-first-router</a> or its sucessor which, <ahref="https://github.com/respond-framework/rudy"target="_blank">Rudy<a>
16
2
17
3
# extract-css-chunks-webpack-plugin
18
4
19
-
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.
<h2align="center">🍾🍾🍾It's our absolute pleasure to announce Webpack 4 Support 🚀🚀🚀</h2>
31
28
32
-
To begin, you'll need to install `extract-css-chunks-webpack-plugin`:
29
+
> **HEADLINES (May 2018): Now Independently supports Webpack 4:**
30
+
> Yep that's right. The universal family is now fully Webpack 4. Thank you to all our users for your loyalty and patience! If you love Universal, then you are gonna fall head over heels when we bring out the main course!
So... why did we rebuild `extract-css-chunks`? What does it offer?
37
33
38
-
It's recommended to combine `extract-css-chunks-webpack-plugin` with the [`css-loader`](https://github.com/webpack-contrib/css-loader)
34
+
It's got all the goodness of `mini-css-extract-plugin`but with 2 gleaming, sought after benefits.
39
35
40
-
Then add the loader and the plugin to your `webpack` config. For example:
36
+
Compared to the existing loaders, we are offering a single solution as opposed to needing to depend on multiple loaders to cater for different features:
41
37
42
-
**style.css**
38
+
## Perks
43
39
44
-
```css
45
-
body {
46
-
background: green;
47
-
}
48
-
```
40
+
-**HMR:** It also has first-class support for **Hot Module Replacement** across ALL those css files/chunks!!!
41
+
- cacheable stylesheets
42
+
- smallest total bytes sent compared to "render-path" css-in-js solutions that include your CSS definitions in JS
43
+
- Faster than the V2!
44
+
- Async loading
45
+
- No duplicate compilation (performance)
46
+
- Easier to use
47
+
- Specific to CSS
48
+
- SSR Friendly development build, focused on frontend DX
49
+
- Works seamlessly with the Universal family
50
+
- Works fantastically as a standalone style loader (You can use it for any webpack project! with no extra dependencies!)
51
+
- Async styles do not render block webkit browsers, if you use the `insert` option
49
52
50
-
**component.js**
53
+
Additionally, if you are already a user of the universal family -- we will be waving goodbye to the mandatory `window.__CSS_CHUNKS__`.
51
54
52
-
```js
53
-
import'./style.css';
54
-
```
55
+
The functionality is still available to you via chunk flushing, and it can come in super handy when needing to easily resolve style assets as urls that might need to be passed to a third party.
55
56
56
57
**webpack.config.js**
57
58
@@ -63,6 +64,7 @@ module.exports = {
63
64
module: {
64
65
rules: [
65
66
{
67
+
test:/\.css$/i,
66
68
test:/\.css$/i,
67
69
use: [ExtractCssChunks.loader, 'css-loader'],
68
70
},
@@ -317,7 +319,7 @@ module.exports = {
317
319
318
320
The `extract-css-chunks-webpack-plugin` supports hot reloading of actual css files in development.
319
321
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.
322
+
Below is an example configuration of `extract-css-chunks` for HMR use with CSS modules.
321
323
322
324
While we attempt to hmr css-modules. It is not easy to perform when code-splitting with custom chunk names.
323
325
`reloadAll` is an option that should only be enabled if HMR isn't working correctly.
@@ -583,7 +585,7 @@ module.exports = {
583
585
Type: `String|Function`
584
586
Default: `head`
585
587
586
-
By default, the `mini-css-extract-plugin` appends styles (`<link>` elements) to `document.head` of the current `window`.
588
+
By default, the `extract-css-chunks-plugin` appends styles (`<link>` elements) to `document.head` of the current `window`.
587
589
588
590
However in some circumstances it might be necessary to have finer control over the append target or even delay `link` elements instertion. For example this is the case when you asynchronously load styles for an application that runs inside of an iframe. In such cases `insert` can be configured to be a function or a custom selector.
589
591
@@ -594,7 +596,7 @@ If you target an [iframe](https://developer.mozilla.org/en-US/docs/Web/API/HTMLI
594
596
Allows to configure a [CSS selector](https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelector) that will be used to find the element where to append the styles (`link` elements).
595
597
596
598
```js
597
-
newMiniCssExtractPlugin({
599
+
newExtractCssChunksPlugin({
598
600
insert:'#my-container',
599
601
});
600
602
```
@@ -610,7 +612,7 @@ Allows to override default behavior and insert styles at any position.
610
612
> ⚠ The `insert` function is serialized to string and passed to the plugin. This means that it won't have access to the scope of the webpack configuration module.
0 commit comments