Skip to content

Work with async CommonsChunkPlugin #47

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
joaovieira opened this issue Oct 24, 2017 · 5 comments
Closed

Work with async CommonsChunkPlugin #47

joaovieira opened this issue Oct 24, 2017 · 5 comments

Comments

@joaovieira
Copy link

Thought I'd ask this here as I can't seem to find a solution anywhere.

Here's my goal:

  • 1 vendor bundle
  • 1 entry bundle + CSS
  • multiple async chunks + CSS
  • 1 common async chunk with common code form all async chunks + CSS

All of the Webpack output is correct as seen below (there's also a CSS chunk for each chunk):

screen shot 2017-10-24 at 10 26 27

All the async chunks are loaded nicely together with the CSS chunk using babel-dual-import.

The problem arrises with the common chunk. It is created via CommonsChunkPlugin, which adds the dynamic import logic itself (i.e. there's no import()), hence it doesn't load the corresponding CSS for that common chunk.

Is there any way around this? How to import the css for an automatically generated async chunk?

screen shot 2017-10-24 at 10 35 05

@faceyspacey
Copy link
Owner

The solution is to override the generated chunks manually to include the async chunks if one of the chunks that goes along with it is present. That's the best we have been able to come up with. Somewhere around here or the other universal packages is an issue showing what someone else did.

@joaovieira
Copy link
Author

@faceyspacey I've been searching for a while in all the related repos (react-universal-component, flush-chunks, universal-demo, extract-text-plugin, dual-import, universal-import) and couldn't find it. Do you have any other clue? Also, not sure I understood that solution summary. How and where to override? Post-build, coding in the fetch request?

@faceyspacey
Copy link
Owner

Basically you get an array of scripts from flushChunks right. So you can look into the scripts and see the names of what you received, and if one of those names requires an async chunk, you can push that async chunk's name on to the array before rendering the array to HTML.

As far as client-side dynamic imports on user navigation, I forget what the solution was. There might not have been one.

The previous issue was in babel-plugin-universal-import or webpack-flush-chunks. But basically I don't think we have a satisfactory solution for ya here.

@faceyspacey
Copy link
Owner

maybe this helps:

faceyspacey/webpack-flush-chunks#21

@faceyspacey
Copy link
Owner

faceyspacey commented Oct 24, 2017

the other part of the solution would be PRing this file:

https://github.com/faceyspacey/babel-plugin-universal-import/blob/master/importCss.js#L32

to Promise.all request an array of css files in the cssHash. I think i mention that in the above issue. That wouln't solve async common chunks of js--but is webpack handling that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants