mirror of https://github.com/webpack/webpack.git
Merge pull request #8466 from webpack/bugfix/splitChunks-enforce
enforce should not prevent using `minChunks` etc. on cacheGroup
This commit is contained in:
commit
f29ca64ebb
|
|
@ -465,11 +465,7 @@ module.exports = class SplitChunksPlugin {
|
||||||
module
|
module
|
||||||
) => {
|
) => {
|
||||||
// Break if minimum number of chunks is not reached
|
// Break if minimum number of chunks is not reached
|
||||||
if (
|
if (selectedChunks.length < cacheGroup.minChunks) return;
|
||||||
!cacheGroup.enforce &&
|
|
||||||
selectedChunks.length < cacheGroup.minChunks
|
|
||||||
)
|
|
||||||
return;
|
|
||||||
// Determine name for split chunk
|
// Determine name for split chunk
|
||||||
const name = cacheGroup.getName(
|
const name = cacheGroup.getName(
|
||||||
module,
|
module,
|
||||||
|
|
@ -492,7 +488,7 @@ module.exports = class SplitChunksPlugin {
|
||||||
modules: new SortableSet(undefined, sortByIdentifier),
|
modules: new SortableSet(undefined, sortByIdentifier),
|
||||||
cacheGroup,
|
cacheGroup,
|
||||||
name,
|
name,
|
||||||
validateSize: !cacheGroup.enforce && cacheGroup.minSize > 0,
|
validateSize: cacheGroup.minSize > 0,
|
||||||
size: 0,
|
size: 0,
|
||||||
chunks: new Set(),
|
chunks: new Set(),
|
||||||
reuseableChunks: new Set(),
|
reuseableChunks: new Set(),
|
||||||
|
|
@ -534,27 +530,40 @@ module.exports = class SplitChunksPlugin {
|
||||||
priority: cacheGroupSource.priority || 0,
|
priority: cacheGroupSource.priority || 0,
|
||||||
chunksFilter:
|
chunksFilter:
|
||||||
cacheGroupSource.chunksFilter || this.options.chunksFilter,
|
cacheGroupSource.chunksFilter || this.options.chunksFilter,
|
||||||
enforce: cacheGroupSource.enforce,
|
|
||||||
minSize:
|
minSize:
|
||||||
|
cacheGroupSource.minSize !== undefined
|
||||||
|
? cacheGroupSource.minSize
|
||||||
|
: cacheGroupSource.enforce
|
||||||
|
? 0
|
||||||
|
: this.options.minSize,
|
||||||
|
minSizeForMaxSize:
|
||||||
cacheGroupSource.minSize !== undefined
|
cacheGroupSource.minSize !== undefined
|
||||||
? cacheGroupSource.minSize
|
? cacheGroupSource.minSize
|
||||||
: this.options.minSize,
|
: this.options.minSize,
|
||||||
maxSize:
|
maxSize:
|
||||||
cacheGroupSource.maxSize !== undefined
|
cacheGroupSource.maxSize !== undefined
|
||||||
? cacheGroupSource.maxSize
|
? cacheGroupSource.maxSize
|
||||||
: this.options.maxSize,
|
: cacheGroupSource.enforce
|
||||||
|
? 0
|
||||||
|
: this.options.maxSize,
|
||||||
minChunks:
|
minChunks:
|
||||||
cacheGroupSource.minChunks !== undefined
|
cacheGroupSource.minChunks !== undefined
|
||||||
? cacheGroupSource.minChunks
|
? cacheGroupSource.minChunks
|
||||||
: this.options.minChunks,
|
: cacheGroupSource.enforce
|
||||||
|
? 1
|
||||||
|
: this.options.minChunks,
|
||||||
maxAsyncRequests:
|
maxAsyncRequests:
|
||||||
cacheGroupSource.maxAsyncRequests !== undefined
|
cacheGroupSource.maxAsyncRequests !== undefined
|
||||||
? cacheGroupSource.maxAsyncRequests
|
? cacheGroupSource.maxAsyncRequests
|
||||||
: this.options.maxAsyncRequests,
|
: cacheGroupSource.enforce
|
||||||
|
? Infinity
|
||||||
|
: this.options.maxAsyncRequests,
|
||||||
maxInitialRequests:
|
maxInitialRequests:
|
||||||
cacheGroupSource.maxInitialRequests !== undefined
|
cacheGroupSource.maxInitialRequests !== undefined
|
||||||
? cacheGroupSource.maxInitialRequests
|
? cacheGroupSource.maxInitialRequests
|
||||||
: this.options.maxInitialRequests,
|
: cacheGroupSource.enforce
|
||||||
|
? Infinity
|
||||||
|
: this.options.maxInitialRequests,
|
||||||
getName:
|
getName:
|
||||||
cacheGroupSource.getName !== undefined
|
cacheGroupSource.getName !== undefined
|
||||||
? cacheGroupSource.getName
|
? cacheGroupSource.getName
|
||||||
|
|
@ -572,11 +581,7 @@ module.exports = class SplitChunksPlugin {
|
||||||
// For all combination of chunk selection
|
// For all combination of chunk selection
|
||||||
for (const chunkCombination of combs) {
|
for (const chunkCombination of combs) {
|
||||||
// Break if minimum number of chunks is not reached
|
// Break if minimum number of chunks is not reached
|
||||||
if (
|
if (chunkCombination.size < cacheGroup.minChunks) continue;
|
||||||
!cacheGroup.enforce &&
|
|
||||||
chunkCombination.size < cacheGroup.minChunks
|
|
||||||
)
|
|
||||||
continue;
|
|
||||||
// Select chunks by configuration
|
// Select chunks by configuration
|
||||||
const {
|
const {
|
||||||
chunks: selectedChunks,
|
chunks: selectedChunks,
|
||||||
|
|
@ -586,14 +591,12 @@ module.exports = class SplitChunksPlugin {
|
||||||
cacheGroup.chunksFilter
|
cacheGroup.chunksFilter
|
||||||
);
|
);
|
||||||
|
|
||||||
if (selectedChunks.length > 0) {
|
addModuleToChunksInfoMap(
|
||||||
addModuleToChunksInfoMap(
|
cacheGroup,
|
||||||
cacheGroup,
|
selectedChunks,
|
||||||
selectedChunks,
|
selectedChunksKey,
|
||||||
selectedChunksKey,
|
module
|
||||||
module
|
);
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -672,9 +675,8 @@ module.exports = class SplitChunksPlugin {
|
||||||
if (usedChunks.length === 0) continue;
|
if (usedChunks.length === 0) continue;
|
||||||
|
|
||||||
if (
|
if (
|
||||||
!item.cacheGroup.enforce &&
|
Number.isFinite(item.cacheGroup.maxInitialRequests) ||
|
||||||
(Number.isFinite(item.cacheGroup.maxInitialRequests) ||
|
Number.isFinite(item.cacheGroup.maxAsyncRequests)
|
||||||
Number.isFinite(item.cacheGroup.maxAsyncRequests))
|
|
||||||
) {
|
) {
|
||||||
const chunkInLimit = usedChunks.filter(chunk => {
|
const chunkInLimit = usedChunks.filter(chunk => {
|
||||||
// respect max requests when not enforced
|
// respect max requests when not enforced
|
||||||
|
|
@ -692,8 +694,6 @@ module.exports = class SplitChunksPlugin {
|
||||||
});
|
});
|
||||||
|
|
||||||
if (chunkInLimit.length < usedChunks.length) {
|
if (chunkInLimit.length < usedChunks.length) {
|
||||||
// We do not need to check enforce here as it was
|
|
||||||
// already checked above.
|
|
||||||
if (chunkInLimit.length >= item.cacheGroup.minChunks) {
|
if (chunkInLimit.length >= item.cacheGroup.minChunks) {
|
||||||
for (const module of item.modules) {
|
for (const module of item.modules) {
|
||||||
addModuleToChunksInfoMap(
|
addModuleToChunksInfoMap(
|
||||||
|
|
@ -775,7 +775,7 @@ module.exports = class SplitChunksPlugin {
|
||||||
maxSizeQueueMap.set(newChunk, {
|
maxSizeQueueMap.set(newChunk, {
|
||||||
minSize: Math.max(
|
minSize: Math.max(
|
||||||
oldMaxSizeSettings ? oldMaxSizeSettings.minSize : 0,
|
oldMaxSizeSettings ? oldMaxSizeSettings.minSize : 0,
|
||||||
item.cacheGroup.minSize
|
item.cacheGroup.minSizeForMaxSize
|
||||||
),
|
),
|
||||||
maxSize: Math.min(
|
maxSize: Math.min(
|
||||||
oldMaxSizeSettings ? oldMaxSizeSettings.maxSize : Infinity,
|
oldMaxSizeSettings ? oldMaxSizeSettings.maxSize : Infinity,
|
||||||
|
|
|
||||||
|
|
@ -17,17 +17,18 @@ module.exports = {
|
||||||
optimization: {
|
optimization: {
|
||||||
splitChunks: {
|
splitChunks: {
|
||||||
chunks: "all",
|
chunks: "all",
|
||||||
minSize: 1,
|
|
||||||
cacheGroups: {
|
cacheGroups: {
|
||||||
default: {
|
default: {
|
||||||
automaticNamePrefix: "common",
|
automaticNamePrefix: "common",
|
||||||
reuseExistingChunk: true,
|
reuseExistingChunk: true,
|
||||||
minChunks: 2,
|
minChunks: 2,
|
||||||
priority: -20
|
priority: -20,
|
||||||
|
enforce: true // minChunks should have higher priority
|
||||||
},
|
},
|
||||||
vendors: {
|
vendors: {
|
||||||
automaticNamePrefix: "common",
|
automaticNamePrefix: "common",
|
||||||
test: /[\\/]node_modules[\\/]/,
|
test: /[\\/]node_modules[\\/]/,
|
||||||
|
minSize: 1,
|
||||||
priority: -10
|
priority: -10
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue