Last active
December 8, 2021 20:24
-
-
Save ebidel/2964a01cd33a1186ce601838d4159fe4 to your computer and use it in GitHub Desktop.
NextJS/webpack bundle chunking
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
What's the best way to prevent large components from a tree shakeable library from being bundled | |
together in a common bundle by webpack/next's default strategy? | |
Thread at https://twitter.com/ebidel/status/1467938411772219393. | |
# Example | |
## Page1.ts | |
``` | |
import { A, B } from '@shared/lib'; | |
// use <A> and <B> on page | |
``` | |
## Page2.ts | |
``` | |
import { C, D } from '@shared/lib'; | |
// use <C> and <D> on page | |
``` | |
With this setup, Next will produce something like page1.js, page2.js, and a sharedlib.1234.js bundle which contains all the used components (A,B,C,D). | |
If C & D are quite large, this will have an impact on Page 1's loading performance. Since these components are never | |
used on Page 1, it doesn't make sense to load them. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment