Skip to content
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

plugin-webpack: fixes / improvements to default splitChunks config #1616

Merged
merged 1 commit into from
Nov 16, 2020
Merged

plugin-webpack: fixes / improvements to default splitChunks config #1616

merged 1 commit into from
Nov 16, 2020

Conversation

mxmul
Copy link
Contributor

@mxmul mxmul commented Nov 16, 2020

Changes

  • Fixes two bugs with the "large lib" chunks.
    1. Searches /web_modules rather than /node_modules for large third-party JS modules.
    2. Sets a unique chunk name for each library; the current config had all large modules going into a single vendor chunk, which wasn't the intent.
  • Decrease the size threshold for extracting large modules into a "large lib" chunk to 100KB. The compact: true setting in our babel-loader config compressed files a bit before getting to splitChunks, and allowed some pretty large libraries (like Moment) to get under the 150KB threshold.
  • Pass the correct numEntries value to getSplitChunksConfig
  • Disable the commons chunk entirely when there is only one entry point.

Testing

Manually tested against a small project that has one entrypoint and imports Moment (a large JS dependency). Before, all modules were pulled into a commons chunk and Moment wasn't pulled out into its own chunk; after this patch, the commons chunk is gone and lib-moment.HASH.js is emitted.

Screen Shot 2020-11-15 at 10 13 28 PM

I also tested adding a second entry point to the project, and it introduces a commons chunk as expected:

Screen Shot 2020-11-15 at 10 27 22 PM

Docs

None; bug fixes only.

@vercel
Copy link

vercel bot commented Nov 16, 2020

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/pikapkg/snowpack/49v12wzwk
✅ Preview: https://snowpack-git-split-chunks-improvements.pikapkg.vercel.app

Copy link
Owner

@FredKSchott FredKSchott left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! All changes make sense (appreciate the detailed explanation)

@FredKSchott FredKSchott merged commit 5b08af0 into FredKSchott:master Nov 16, 2020
@mxmul mxmul deleted the split-chunks-improvements branch November 16, 2020 18:45
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