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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow to define minimum chunk size limit #4705
Conversation
Thank you for your contribution! 鉂わ笍You can try out this pull request locally by installing Rollup via npm install rollup/rollup#min-chunk-size or 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
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. |
This PR has been released as part of rollup@3.3.0. You can test it via |
This PR contains:
Are tests included?
Breaking Changes?
List any relevant issue numbers:
Description
This defines a new option
output.experimentalMinChunkSize: number
which 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:
Infinity
to get the absolute minimal number of chunks 馃槈--perf
option will print special timings for this option in a sectionoptimize chunks