fix(splitChunks): splitChunks maxSize not work as expected if size of some type is small #9285
+9,071
−45
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.
Summary
Align: https://github.com/webpack/webpack/blob/3919c844eca394d73ca930e4fc5506fb86e2b094/lib/util/deterministicGrouping.js#L326.
there is a chunk contains following modules (use 0 represents module)
User set maxSize, and total size of these modules is greater than maxSize, so we need to split it
From left, we find a position which can just fulfill the minSize
From right, we also find a position which can just fulfill the minSize
Case 1:
Perfact splitting
Split it into 2 chunks, left and right are all greater than minSize
Case 2:
Split it based on some special algorithm, still, the 2 chunks are all greater than minSize, so it's fine
Case 3:
Left and Right has overlaps, if split left, right part doesn't satisfy minSize, for current version before this pr, we just ignore this, and do not split this chunk at all.
But when size is smaller than minSize, there is a possibility that not all module type's size is smaller than minSize,
eg. the right 3 modules has only 1 module that contains css, the total css size is smaller than minSize but the total js size is larger than minSize.
In this case move the module that contains that css into a existing result chunk, and re-check the maxSize
Align this logic in this pr
Checklist