-
Notifications
You must be signed in to change notification settings - Fork 512
ExtractTextPlugin extracts from asynchronous split point chunks #120
Comments
+1, the same problem here probably, CSS should not be extracted from async bundles |
@sokra should I try to produce a pull request to do this? |
@chrispesto I use bundle-loader to extract async modules, |
you have three entries however |
+1 this is a real problem. In our case we have a tests chunk which has all of the tests and the asynchronous chunks baked into it, whilst in the actual app they are only loaded asynchronously. So all of the CSS from these chunks ends up extracted into |
Of course, the question is, what should the behaviour be if a file is referenced synchronously from one entry chunk and asynchronously from another? Should the text be included in both the bundle and in the extracted CSS from the synchronously-requiring chunk, or not be extracted at all? |
I agree too, that it's a problem. |
+1 @sokra Is there any way to keep the styles in the chunks that are split via @chrispesto did you figure this out? |
+1 Wondering if it's possible for ExtractTextWebpackPlugin to generate CSS files for each of the split points. I really need this. |
+1 is there any updates on this? I cannot get the splitted CSS using require.ensure |
+1 |
2 similar comments
+1 |
+1 |
i finnally found use |
just require the css in your async loaded source file |
the most important is the style-loader with ''/url" option |
+1 |
+1, have the same problem |
+1 |
1 similar comment
+1 |
+1 |
@biblesyme I've tried your suggestion but it's not working. Do you have a example somewhere? Thanks in advance. |
@satazor this is my implementation based on React, hope it help U App.js
route.js
webpack.config
|
I want to create a dynamic split point. so I have changed my route to this:
After introducing require.ensure. Webpack has started throwing below error:
CSS Loader configuration in webpack:
Any idea on why the module build started failing and it is unable to resolve CSS variables? |
@biblesyme thanks. it works. But is there a way to set the |
I solve the problem by setting |
+1 having this issue @sokra, lot of interest in this issue from many people, none of the work arounds are acceptable cause they all give something up, your input would be very valuable, at least do u think of this as bug, as designed, or enhancement. We are migrating a huge site to react/react-router/webpack, if we have your input we could maybe work on a patch. to summarize the original issue in my own words
I think fix to this issue is essential if one wants to be able to render pages on both server side (and avoid flash of unstyled content) and client side. For now we have |
I think around this area in the code: https://github.com/webpack-contrib/extract-text-webpack-plugin/blob/master/index.js#L267 we should now allow for the capability to extract css per chunk into their own file, and then packages like React Loadable can discover the the css files it needs to embed in the initial page. In fact, I'm working on a PR to complete React Loadable's capabilities so it can properly (and synchronously) embed within served html the chunks used in the current request. So this may make obsolete the need to manually make entry points on behalf of dynamic ones to generate their CSS file. However, using this feature would come at the cost of having to insure you're using something like React Loadable to get those css chunk files to the client. At the end of the day, a robust and general solution to handle the marriage of code splitting + server rendering is needed, and that's precisely what I'm working on with React Loadable. ...Anyone have any ideas what needs to be done to modify My first inclination is to change:
to
I.e. make it always extract. But obviously there's more to it. Somewhere it's specifying that the results from all chunks go to an output file corresponding to the entry chunk. It looks like this might have something to do with it: Basically it seems like we need to undo its forcing of all output into a single file. It probably requires less code to just insure an output file per chunk as the code loops through chunks and modules. This is my first time looking at the code, any tips are more than welcome. |
Hey everyone, the following is a fork I made that supports individual css files per chunk (including dynamic split chunks): https://github.com/faceyspacey/extract-css-chunks-webpack-plugin It also has HMR working. You should use it just for your client webpack config, as it has HMR built in. This is intended for use with an upcoming PR to React Loadable, which will handle your split points in an effective way along with server side rendering. What that means is that when using React Loadable server side, split points are synchronously required on the server and synchronously required on the client if it's the initial page load. This allows you to render once on the client without the checksum match failing, while having all the chunks (including CSS chunks) available for synchronous requiring. I'll keep you posted as to when React Loadable supports this. |
commit e2631af Author: David Heidrich <[email protected]> Date: Mon Jun 19 19:08:13 2017 +0200 removed dead code, cleanup commit d8943d7 Author: David Heidrich <[email protected]> Date: Mon Jun 19 15:48:51 2017 +0200 restored console log commit 0d7c94a Author: David Heidrich <[email protected]> Date: Mon Jun 19 00:30:34 2017 +0200 fixed async loading (keep original style loader in async chunks) commit 950d7ef Author: David Heidrich <[email protected]> Date: Sun Jun 18 15:52:41 2017 +0200 fixed exporting module informations commit 8b97ee5 Author: David Heidrich <[email protected]> Date: Sun Jun 18 14:27:51 2017 +0200 fixed line length commit 6898aa4 Author: David Heidrich <[email protected]> Date: Sun Jun 18 14:26:34 2017 +0200 respect all chunks commit bbc93ab Author: David Heidrich <[email protected]> Date: Sun Jun 18 12:33:09 2017 +0200 adjusted test to be env agnostic commit 3eba627 Author: David Heidrich <[email protected]> Date: Sun Jun 18 12:25:16 2017 +0200 adjusted tests to use css-loader, added tests for allChunks, remove module from initial chunk commit 09ac8cb Author: David Heidrich <[email protected]> Date: Sat Jun 17 22:36:09 2017 +0200 adjusted tests, remove module from base if extracted commit 1791796 Author: David Heidrich <[email protected]> Date: Sat Jun 17 21:23:58 2017 +0200 added testcase for issue webpack-contrib#120
@faceyspacey can your provide information what exactly does not work as expected or wrong? Maybe we can fix it into |
Having looked into this for a while, I feel @faceyspacey's solution is super overkill (it requires multiple loaders and plugins, it requires magic strings added to the window object, it makes a number of assumptions about server-side-rendering). It's a great solution for a specific few cases (and I use it and love it), but it doesn't work if you just want to dynamically load a css file on-demand. I think the actual TLDR ask here is to replace: /***/ "./path/to/your/dynamic/split/file.css":
/***/ (function(module, exports) {
// removed by extract-text-webpack-plugin
/***/ }), with (assuming /***/ "./path/to/your/dynamic/split/file.css":
/***/ (function(module, exports) {
loadCss(`/static/0.7739c3c60ea45ec5e06ab85046aba848.css`);
/***/ }), Where I know there's a long-term plan in webpack to make styles (and webasm) first-class module types in addition to javascript, but in the interim is it possible to configure an extract-text-webpack-plugin instance with a means of dynamically loading a chunk at runtime? |
none of the solutions here seems to work for me. I'm working on a big solution (multiple websites in one solution - I can't split the project) which brings me to code-splitting and lazy-loading. Each of the websites is basically wrapped in a route component (react-router). For now I can use I wish I could do just like webpack
Is there any plan to allow this kind of behavior ? |
@VincentCharpentier there are big changes coming to CSS in Webpack 4 and I think this is one of the things that will be possible. https://medium.com/webpack/road-to-webpack-4-week-20-21-1641d03ce06e |
@sheepsteak So This is gonna be standard webpack ? What a great news, thanks for the info. I think I can just fallback to style-loader in the meantime. |
@VincentCharpentier I believe so 😄 In the first link it says:
I've been waiting a long time for this too! |
It is very old issue, closing in favor #120 (new issue and have PR). Don't worry we remember about issue. Feel free to PR. |
@evilebottnawi this issue is #120. Did you intend to reference a different issue/PR? |
I have a webpack.config.js like:
And a client router like:
The ExtractTextPlugin creates index.js/index.css, create.js/create.css, etc, with the extracted CSS for each containing only what is directly required from each of those entry points. It also generates 1.1.js, 2.2.js, and 3.3.js for the split points to load pages asynchronously, but the CSS is removed from them as well. I.e. (from 1.1.js):
This means as you navigate between pages the CSS for the asynchronously-loaded splits do not get added to the page, only their JS. You only have the CSS from the initial entry point.
It seems like 1.1.js, etc should still contain their inline CSS and inject it, like when you aren't using the ExtractTextPlugin. That way you can get the benefits of the extracted entry point CSS for the initial pageload and avoid an FOUC, but after that everything works as a single page app.
I thought the plugin would work that way from the documentation, which says "by default it extracts only from the initial chunk(s)." And I tried explicitly setting 'allChunks: false'.
The text was updated successfully, but these errors were encountered: