-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Allow to filter chunks when using javascript_packs_with_chunks #1944
Comments
Consider my recommendations here: #1835 (comment) |
@jakeNiemiec your recommendations are valid if we're talking about user chunks, but in my issue I was talking more about runtime one which webpack is generated. The other approach would be just to include it into every chunk, but this is just a step back in terms of optimizations |
Let me illistrate how we do it:
<% @lazy_chunks[:thing_show] = true %> JS in <script>
//...
window.thingShow = <%= @lazy_chunks[:thing_show].present? %>
</script> JS in runtimeChunk if (lazyChunks.thingShow) {
import(/* webpackChunkName: "thingShow" */
/* webpackMode: "lazy" */
'./thing/thingShow.index');
} Basically, we use a single slim entry point as a "hub" for loading desired chunks. Not for everyone, but helpful enough for me to share when I can (even though it goes against some of webpacker's design decisions). |
@somebody32 I'm late to the party here, but I want to understand the problem better.
I agree this would be unpleasant. One way I could see this happening is if It would be nice if webpacker provided helpers to aid with this, which also typically would mean you'd want to set |
Thanks @rossta and @jakeNiemiec for the suggestions! 👍 |
We're using multiple entry-points on some of our pages and we've configured webpack to create only one runtime chunk across all of them with
runtimeChunk: "single"
to save space and minimize files.But then there is a problem when using
javascript_packs_with_chunks
because it includes all chunks for the entrypoint and the runtime one as well. So that could lead to the case when runtime chunk is executed multiple times which generates unpleasant side-effects.For now, I've created my own version of javascript_packs_with_chunks that allows filtering runtime chunk but I'm questioning the need to have something like that in webpacker itself.
The text was updated successfully, but these errors were encountered: