Skip to content

Add option to skip dynamic chunks#112

Open
neocoder wants to merge 1 commit intocatamphetamine:masterfrom
neocoder:feature/include-only-initial-chunks
Open

Add option to skip dynamic chunks#112
neocoder wants to merge 1 commit intocatamphetamine:masterfrom
neocoder:feature/include-only-initial-chunks

Conversation

@neocoder
Copy link

@neocoder neocoder commented Nov 4, 2019

This PR adds an option to filter non-initial chunks that are loaded dynamically.

@catamphetamine
Copy link
Owner

Hi.
I can see README.md got replaced entirely.
Can you reduce it to a small diff?

@neocoder neocoder force-pushed the feature/include-only-initial-chunks branch from 9889a10 to 3789b89 Compare November 5, 2019 08:08
@neocoder
Copy link
Author

neocoder commented Nov 5, 2019

Sure. It's fixed now. I think VSCode replaced line endings the first time.

@catamphetamine
Copy link
Owner

@neocoder
So, if expressed in a more specific way, what would the effect of the effect skipDynamicChunks option be?
"This PR adds an option to filter non-initial chunks that are loaded dynamically" is not descriptive enough.

@neocoder
Copy link
Author

neocoder commented Nov 5, 2019

@catamphetamine
Yeah, maybe it was not descriptive enough. Maybe you can help with a better description?
Basically, when you use Webpack's dynamic import() statements it generates two types of chunks: initial chunks ( that must be loaded with the page ) and dynamic chunks ( that will be loaded by Webpack dynamically ). Before the PR, filename_info() function collected all JS chunks ( including dynamic ones ) that later ended up in the initial HTML page. This broke the idea of loading part of the code dynamically when it's actually needed. So skipDynamicChunks option filters the dynamic chunks from the initial page HTML. I wasn't sure if the fix could possibly break some other code, so I decided to make it as an option to leave current behavior intact.

@catamphetamine
Copy link
Owner

@neocoder So, supposed you have a webpack-chunks.json file with both "initial" and "dynamic" chunk filenames.
How do they end up included on a page though?
They're just filenames, as far as I see, not the actual chunks content.
Unless you include them manually via <script/> I guess they won't be included.
Or provide a proof of otherwise.

@neocoder
Copy link
Author

neocoder commented Nov 5, 2019

@catamphetamine
yes, they are included manually into the page with the <script /> tags but there's no info on whether the chunk is initial or dynamic in the JSON file. You can't differentiate them in the current code. The other option to fix the issue might be to include info on the type of the chunk into the JSON file and I think it's just a matter of opinion on whether dynamic chunks must be included in the JSON or not. If the purpose of JSON is to specify chunks that must be included in the page then, I guess not. It's up to you to decide. If you like the other solution better, I can make another PR. I don't want to leave my fork, which I don't have time to maintain, in production on this project :)

@catamphetamine
Copy link
Owner

@neocoder

I think it's just a matter of opinion on whether dynamic chunks must be included in the JSON or not. If the purpose of JSON is to specify chunks that must be included in the page then, I guess not.

Your point's valid: "dynamic" chunks shouldn't be part of the list.
But how exactly do they end up included in your project?
This library doesn't include anything, it just provides the list of files.

@neocoder
Copy link
Author

neocoder commented Nov 5, 2019

@catamphetamine
In your original code, there was an iteration on the json.assetsByChunkName and this list includes both initial and dynamic chunks. It's the json.chunks object which includes the info on whether the chunk is initial or dynamic. Not sure why Webpack authors decided to keep it this way.

@catamphetamine
Copy link
Owner

@neocoder
Can you be more specific?
What code exactly does iterate json.assetsByChunkName?
Where did you get it?

@neocoder
Copy link
Author

neocoder commented Nov 5, 2019

@catamphetamine
I don't want to be rude, but did you see the actual code in the PR? I'm not quite following what else is missing in my description. There's an issue and there's a solution.

@catamphetamine
Copy link
Owner

@neocoder There's a possibility that your application may be doing something incorrectly, so to rule out such possibility first an examination is required.

@neocoder
Copy link
Author

neocoder commented Nov 5, 2019

@catamphetamine
Unfortunately, I cannot share the code with you but I can assure you that it does everything like in the docs. It calls the chunks() function which is passed to the main server function and then creates a script and link tags for assets returned by that function.

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

Successfully merging this pull request may close these issues.

2 participants

Comments