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
Copy file name to clipboardExpand all lines: README.md
+39-40Lines changed: 39 additions & 40 deletions
Original file line number
Diff line number
Diff line change
@@ -29,11 +29,15 @@ Its got all the goodness of `mini-css-extract-plugin` but with 2 gleaming, sough
29
29
30
30
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:
31
31
32
+
## Perks
33
+
***HMR:** It also has first-class support for **Hot Module Replacement** across ALL those css files/chunks!!!
34
+
* cacheable stylesheets
35
+
* smallest total bytes sent compared to "render-path" css-in-js solutions that include your CSS definitions in JS
36
+
* Faster than the V2!
32
37
* Async loading
33
38
* No duplicate compilation (performance)
34
39
* Easier to use
35
40
* Specific to CSS
36
-
* True **Hot Module Reloading** - that means no `style-loader`
37
41
* SSR Friendly development build, focused on frontend DX
38
42
* Works seamlessly with the Universal family
39
43
* Works fantastically as a standalone style loader (You can use it for any webpack project! with no extra dependencies!)
@@ -49,7 +53,7 @@ If you want to test this alpha branch, which is currently not published to the N
49
53
50
54
Add the following to your package.json file, then
51
55
52
-
npm i extract-css-chunks-webpack-plugin@next
56
+
yarn add extract-css-chunks-webpack-plugin@next
53
57
54
58
55
59
## Webpack 4 Standalone Installation:
@@ -112,10 +116,6 @@ If you do need Webpack 3, make sure to stick with the latest `v2.x.x` release. `
Like `extract-text-webpack-plugin`, but creates multiple css files (one per chunk). Then, as part of server side rendering, you can deliver just the css chunks needed by the current request. The result is the most minimal CSS initially served compared to emerging "render path" solutions.
117
-
118
-
For a demo, `git clone`: [universal-demo](https://github.com/faceyspacey/universal-demo)
<!-- stylsheets that will be requested when import() on user navigation is called -->
179
-
<script>
180
-
window.__CSS_CHUNKS__ = {
181
-
Foo: '/static/Foo.css',
182
-
Bar: '/static/Bar.css'
183
-
}
184
-
</script>
185
178
</body>
186
179
```
187
180
188
-
[webpack-flush-chunks](https://github.com/faceyspacey/webpack-flush-chunks) will scoop up the exact stylesheets to embed in your response. It essentially automates producing the above.
181
+
If you need to resolve your stylesheets on the client side, for whatever reason.
182
+
183
+
[webpack-flush-chunks](https://github.com/faceyspacey/webpack-flush-chunks) will scoop up the exact stylesheets to embed in your response. It will give you an object which can be embedded on page
<!-- not needed unless you want to access css chunks urls manually -->
217
214
${cssHash}
215
+
<!-- extract-css-chunks takes care of loading the css assets automatically -->
218
216
${js}
219
217
</body>
220
218
</html>
@@ -223,30 +221,21 @@ res.send(`
223
221
224
222
***As for asynchronous calls to `import()` on user navigation,***[babel-plugin-universal-import](https://github.com/faceyspacey/babel-plugin-universal-import) is required if you're using [react-universal-component](https://github.com/faceyspacey/react-universal-component). And if you aren't, you must use: [babel-plugin-dual-import](https://github.com/faceyspacey/babel-plugin-dual-import).
225
223
226
-
These babel plugins request both your js + your css. *Very Nice!* This is the new feature of the 2.0. Read *Sokra's* (author of webpack) article on how [on how this is the future of CSS for webpack](https://medium.com/webpack/the-new-css-workflow-step-1-79583bd107d7). Use this and be in the future today.
227
-
228
-
## Perks
229
-
-**HMR:** It also has first-class support for **Hot Module Replacement** across ALL those css files/chunks!!!
230
-
- cacheable stylesheets
231
-
- smallest total bytes sent compared to "render-path" css-in-js solutions that include your CSS definitions in JS
232
-
- Faster than the V1!
233
-
234
224
225
+
These babel plugins request both your js + your css. *Very Nice!* This is the new feature of the 2.0. Read *Sokra's* (author of webpack) article on how [on how this is the future of CSS for webpack](https://medium.com/webpack/the-new-css-workflow-step-1-79583bd107d7). Use this and be in the future today.
235
226
236
227
237
228
## API
238
-
You can pass the same options as `extract-text-webpack-plugin` to `new ExtractCssChunks`, such as:
229
+
You can pass the same options as `mini-css-extract` to `new ExtractCssChunks`, such as:
Keep in mind, by default `[name].css` is used when `process.env.NODE_ENV === 'development'` and `[name].[contenthash].css` during production, so you can likely forget about having to pass anything.
247
-
248
-
The 2 exceptions are: `allChunks` will no longer do anything, and `fallback` will no longer do anything when passed to to `extract`. Basically just worry about passing your `css-loader` string and `localIdentName` 🤓
249
-
238
+
>Keep in mind, by default `[name].css` is used when `process.env.NODE_ENV === 'development'` and `[name].[contenthash].css` during production, so you can likely forget about having to pass anything.
250
239
251
240
### HMR Pitfall
252
241
@@ -274,8 +263,12 @@ For example, when running the build using some form of npm script:
274
263
```
275
264
[cross-env](https://www.npmjs.com/package/cross-env) is optional but recommended.
276
265
277
-
## What about Glamorous, Styled Components, Styled-Jsx, Aphrodite, etc?
278
266
267
+
What about Glamorous, Styled Components, Styled-Jsx, Aphrodite, etc?
268
+
<details>
269
+
<summary>
270
+
<spanstyle="color:blue">Click to Read</span>.
271
+
</summary>
279
272
If you effectively use code-splitting, **Exract Css Chunks** can be a far better option than using emerging solutions like *Glamorous*, *Styled Components*, and slightly older tools like *Aphrodite*, *Glamor*, etc. We aren't fans of either rounds of tools because of several issues, but particularly because they all have a runtime overhead. Every time your React component is rendered with those, CSS is generated and updated within the DOM. On the server, you're going to also see unnecessary cycles for flushing the CSS along the critical render path. *Next.js's*`styled-jsx`, by the way, doesn't even work on the server--*not so good when it comes to flash of unstyled content (FOUC).*
280
273
281
274
The reason *Extract CSS Chunk* can be a better option is because *we also generate multiple sets of CSS based on what is actually "used",****but without the runtime overhead***. The difference is our definition of "used" is modules determined *statically* (which may not in fact be rendered) vs. what is in the "critical render path" (as is the case with the other tools).
@@ -285,6 +278,12 @@ So yes, our CSS may be mildly larger and include unnecessary css, but our `no_cs
285
278
On top of that, those are extra packages all with a huge number of issues in their Github repos corresponding to various limitations in the CSS they generate--something that is prevented when your definition for "CSS-in-JS" is simply importing CSS files compiled as normal by powerful proven CSS-specific processors.
286
279
287
280
Lastly, those solutions don't provide cacheable stylesheets. They do a lot of work--but they will *continue* doing it for you when you could have been done in one go long ago. Cloudflare is free--serve them through their CDN and you're winning. I love true javascript in css--don't get me wrong--but first I'd have to see they generate cacheable stylesheets. In my opinion, for now, it's best for environments that natively support it such as React Native.
281
+
<details>
282
+
<details><summary>See Old Docs</summary>
283
+
284
+
For a demo, `git clone`: [universal-demo](https://github.com/faceyspacey/universal-demo)
0 commit comments