Bundle size optimization #1
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request reduces the total JS size of a Next.js application down by as much as 65%. It achieves this for modern JavaScript output, which means it's best paired with @janicklas-ralph's module/nomodule PR.
Here's a summary the changes:
next/*client libraries as modern JS. This was already being done in part, but I've further reduced their size by tuning all configurations. Client-side next modules are processed by the same Babel configuration as userland JavaScript code, so it's okay to assume a baseline of ES2018 support.basicintegration test app. This amounts to movingschedulerandnext/*packages into the commons chunk.if (module.hot) {}- usingDefinePluginto replacemodule.hot=falseduring production builds removes the unnecessary HMR code from every route. Similarly, Webpack's default behavior is to inject shims for various Node features (setImmediate,Buffer, etc). While it's possible some users would like to have these available, the fact that they're not used by Next.js itself means it would make more sense to include them conditionally (via config or usage detection).To test out the changes: