-
Notifications
You must be signed in to change notification settings - Fork 513
feat: extract && emit a CSS file per split point (import()/require.ensure) #455
Comments
cross posted on stackoverflow |
Have you tried?:
...
I'm using this approach with an I'm not quite sure how that plays with a require.ensure using commonJS... |
This is a very important feature with code splitting becoming easier and easier. You need to be able to get the css from code split chunks, not just specified entry chunks. Basically there needs to be a new option like Ultimately we just need to dig in their code and provide the PR. This is a must-have now. |
@jeffrey-l-turner we already do the new plugin instance for known entry chunks. But it's hard to know dynamic chunks in advance in every app. Also, it would require changing build configuration per app. It would be great if we consider this as an option in plugin configuration for this plugin like @faceyspacey mentioned. |
Id be interested in producing the PR. Any help to point me in the right direction would be appreciated. Are you saying that the option might require we specify an array of dynamic chunk names. I hope that's not the case. The stats contains the names of all chunks in the stat object for each module. It maintains an array of chunks it corresponds to. We should be able to get the css statically. |
You are right @faceyspacey about figuring out chunk names from stats. The intention here is to have one build configuration for multiple apps that figures out the chunks and extracts the files based on dynamic require.ensure chunks. |
Hey @osdevisnot my use case is the same. However, not able to find any solution uptil now. Were you able to resolve the issue? |
@faceyspacey Thanks 😄 |
@aseem2625 here's a private/unpublished launch article im releasing in a few days: it should also help you. feedback on anything u find confusing or that i could write better is much appreciated. |
@faceyspacey Thanks.. I'm implementing these stuffs right now only. So, I'll have a look and get back with feedbacks. 😄 |
@faceyspacey Also, i just wanted to point out that using
throws the following error.
Not using, |
that shouldnt be the case. ...my recommendation is to try one of the boilerplates here: https://github.com/faceyspacey/webpack-flush-chunks#boilerplates that best matches your setup. get it working, get comfortable with it. then copy/paste the code. im signing off for the day. post any issues on the ECCWP Issue tracker if it's a real issue. there is likely a minor mistake in how ur structuring the config options. |
Hi @faceyspacey However, in my case, it's SPA and it's having chunks for each route using Also, I feel that boilerplates should be renamed to the following
I would be using your solution when I would be moving my boilerplate to SSR, later this month. 😄 |
...cool i'll update the github caption at the top to those. ...we're adding more configuration options in the next couple of days to toggle off those things which you don't seem to need: faceyspacey/extract-css-chunks-webpack-plugin#14 Maybe that will solve your problem. Please comment on that issue if there is anything we're missing. |
add those 2 additional loaders to a boilerplate and see if it works. then we'll know :) ...u dont have to specify a fallback. |
@faceyspacey just wondering, is extract-css-chunks a go to plugin for this use case? |
@osdevisnot Not answering your ques. But check this article by @faceyspacey |
It's been a while and I'm on my phone, but based on the Issue title, yes. "Emit CSS file per split point." Yes indeed. |
@osdevisnot To answer your question, this plugin generates 3 files for that given js chunk.. @faceyspacey I hope I am correct. I'll give try to this plugin and v2 with my SSR repo and see what's the best thing. |
@faceyspacey @aseem2625 @jeffrey-l-turner At this point, I am successfully able to extract dynamic CSS chunks using The latest demo of my work is here: https://github.com/osdevisnot/extract-text-demo |
@osdevisnot I'm not sure how to do for SPA. But for SSR, you can created a |
@aseem2625, sorry I meant $.ExtractCssChunksPlugin() gets a separate file for dynamically imported chunk. And unfortunately, I need to solve this for SPA. Just to add more context, only issue we have now is downloading the css chunk and injecting it into head for SPA. |
@osdevisnot you are right, these tools were developed with SSR in mind. However good news: several of our users have developed SPA webpack plugins for your use case. Essentially you need to embed the cssHash into the page, containing what stylesheets are available. Search the repos and you will find it. I'll paste it when I'm back on my computer. |
@osdevisnot here's one such solution: https://github.com/mario-jerkovic/flush-css-chunks-webpack-plugin there are 2 others i believe, but i cant find them right now. |
ETWP entered maintenance mode and won't receive any feature updates, please open an issue in The |
Hello guys, I have the same requirement We just need to set file-loader for it |
While trying to implement page optimizations in our app, we want to have ability to generate separate CSS files per webpack chunk to improve page rendering performance for first page in our application. To achieve that, we have been trying to use extract-text-plugin in combination with require.ensure like so:
with app.js being:
and a.css being:
and b.css being:
and c.ss being:
Problem is we are getting only one CSS file
dist/app.e2e9da337e9ab8b0ca431717de3bea22.css
with content of all the 3 chunks:how do we go about extracting one css file per webpack chunk (require.ensure) in this case? should this even be supported by extract-text-plugin.
PS: Here is an example repository demonstrating this issue -- https://github.com/osdevisnot/extract-text-demo
The text was updated successfully, but these errors were encountered: