Allow to define minimum chunk size limit#4705
Merged
Merged
Conversation
Thank you for your contribution! ❤️You can try out this pull request locally by installing Rollup via npm install rollup/rollup#min-chunk-sizeor load it into the REPL: |
8f320b4 to
94e6a49
Compare
Codecov Report
@@ Coverage Diff @@
## master #4705 +/- ##
=======================================
Coverage 99.02% 99.03%
=======================================
Files 215 216 +1
Lines 7599 7663 +64
Branches 2104 2116 +12
=======================================
+ Hits 7525 7589 +64
Misses 24 24
Partials 50 50
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
94e6a49 to
8672129
Compare
That way, we can easily ignore errors to include debug code
8672129 to
f696b4c
Compare
Member
Author
|
This PR has been released as part of rollup@3.3.0-0. Note that this is a pre-release, so to test it, you need to install Rollup via npm install rollup@3.3.0-0 or npm install rollup@beta. It will likely become part of a regular release later. |
Collaborator
|
This PR has been released as part of rollup@3.3.0. You can test it via |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 PR contains:
Are tests included?
Breaking Changes?
List any relevant issue numbers:
Description
This defines a new option
output.experimentalMinChunkSize: numberwhich defines a target lower limit for chunk sizes.This option is experimental, i.e. it can have breaking changes on minor releases, because I want to be able to release it soon, but I am not yet 100% sure about the final implementation. In the end, it could also become a plugin interface + corresponding plugin, but that would be quite a bit more work. The current implementation already gives an idea what information is needed and what the algorithm could look like.
If a positive integer number is specified for this option, rollup will add an additional phase to the chunk generation where it tries to find a suitable merge target for each chunk that does not have side effects when executed and is below the specified limit.
The chunk size determination is rather inaccurate at the moment, though. It takes tree-shaking into account, but otherwise it looks at the size of the generated code before any plugins like minifiers could do their work.
A suitable merge target is a chunk that is loaded under "similar" conditions based on the entry points that import that chunk. So basically it creates a metric between the chunks and tries to select the closest one. If there are several closest ones, it gives precedence to other chunks that are below the size limit. Chained merges are also possible, i.e. A is merged into B is merged into C etc.
The implementation should be fully functional and sufficiently tested. Still, real world testing would be very welcome. Not that this may not work with Vite 3, i.e. you may need to work against a Rollup 3 branch vitejs/vite#9870 .
Things to look for:
Infinityto get the absolute minimal number of chunks 😉--perfoption will print special timings for this option in a sectionoptimize chunks