GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — enforce should not prevent using `minChunks` etc. on cacheGroup · webpack/webpack@b56727e

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • lib/optimize
    • SplitChunksPlugin.js
  • test/statsCases/split-chunks-automatic-name
    • webpack.config.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/optimize/SplitChunksPlugin.js‎

Copy file name to clipboardExpand all lines: lib/optimize/SplitChunksPlugin.js
+30-30Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -465,11 +465,7 @@ module.exports = class SplitChunksPlugin {
465465
module
466466
) => {
467467
// Break if minimum number of chunks is not reached
468-
if (
469-
!cacheGroup.enforce &&
470-
selectedChunks.length < cacheGroup.minChunks
471-
)
472-
return;
468+
if (selectedChunks.length < cacheGroup.minChunks) return;
473469
// Determine name for split chunk
474470
const name = cacheGroup.getName(
475471
module,
@@ -492,7 +488,7 @@ module.exports = class SplitChunksPlugin {
492488
modules: new SortableSet(undefined, sortByIdentifier),
493489
cacheGroup,
494490
name,
495-
validateSize: !cacheGroup.enforce && cacheGroup.minSize > 0,
491+
validateSize: cacheGroup.minSize > 0,
496492
size: 0,
497493
chunks: new Set(),
498494
reuseableChunks: new Set(),
@@ -534,27 +530,40 @@ module.exports = class SplitChunksPlugin {
534530
priority: cacheGroupSource.priority || 0,
535531
chunksFilter:
536532
cacheGroupSource.chunksFilter || this.options.chunksFilter,
537-
enforce: cacheGroupSource.enforce,
538533
minSize:
534+
cacheGroupSource.minSize !== undefined
535+
? cacheGroupSource.minSize
536+
: cacheGroupSource.enforce
537+
? 0
538+
: this.options.minSize,
539+
minSizeForMaxSize:
539540
cacheGroupSource.minSize !== undefined
540541
? cacheGroupSource.minSize
541542
: this.options.minSize,
542543
maxSize:
543544
cacheGroupSource.maxSize !== undefined
544545
? cacheGroupSource.maxSize
545-
: this.options.maxSize,
546+
: cacheGroupSource.enforce
547+
? 0
548+
: this.options.maxSize,
546549
minChunks:
547550
cacheGroupSource.minChunks !== undefined
548551
? cacheGroupSource.minChunks
549-
: this.options.minChunks,
552+
: cacheGroupSource.enforce
553+
? 1
554+
: this.options.minChunks,
550555
maxAsyncRequests:
551556
cacheGroupSource.maxAsyncRequests !== undefined
552557
? cacheGroupSource.maxAsyncRequests
553-
: this.options.maxAsyncRequests,
558+
: cacheGroupSource.enforce
559+
? Infinity
560+
: this.options.maxAsyncRequests,
554561
maxInitialRequests:
555562
cacheGroupSource.maxInitialRequests !== undefined
556563
? cacheGroupSource.maxInitialRequests
557-
: this.options.maxInitialRequests,
564+
: cacheGroupSource.enforce
565+
? Infinity
566+
: this.options.maxInitialRequests,
558567
getName:
559568
cacheGroupSource.getName !== undefined
560569
? cacheGroupSource.getName
@@ -572,11 +581,7 @@ module.exports = class SplitChunksPlugin {
572581
// For all combination of chunk selection
573582
for (const chunkCombination of combs) {
574583
// Break if minimum number of chunks is not reached
575-
if (
576-
!cacheGroup.enforce &&
577-
chunkCombination.size < cacheGroup.minChunks
578-
)
579-
continue;
584+
if (chunkCombination.size < cacheGroup.minChunks) continue;
580585
// Select chunks by configuration
581586
const {
582587
chunks: selectedChunks,
@@ -586,14 +591,12 @@ module.exports = class SplitChunksPlugin {
586591
cacheGroup.chunksFilter
587592
);
588593

589-
if (selectedChunks.length > 0) {
590-
addModuleToChunksInfoMap(
591-
cacheGroup,
592-
selectedChunks,
593-
selectedChunksKey,
594-
module
595-
);
596-
}
594+
addModuleToChunksInfoMap(
595+
cacheGroup,
596+
selectedChunks,
597+
selectedChunksKey,
598+
module
599+
);
597600
}
598601
}
599602
}
@@ -672,9 +675,8 @@ module.exports = class SplitChunksPlugin {
672675
if (usedChunks.length === 0) continue;
673676

674677
if (
675-
!item.cacheGroup.enforce &&
676-
(Number.isFinite(item.cacheGroup.maxInitialRequests) ||
677-
Number.isFinite(item.cacheGroup.maxAsyncRequests))
678+
Number.isFinite(item.cacheGroup.maxInitialRequests) ||
679+
Number.isFinite(item.cacheGroup.maxAsyncRequests)
678680
) {
679681
const chunkInLimit = usedChunks.filter(chunk => {
680682
// respect max requests when not enforced
@@ -692,8 +694,6 @@ module.exports = class SplitChunksPlugin {
692694
});
693695

694696
if (chunkInLimit.length < usedChunks.length) {
695-
// We do not need to check enforce here as it was
696-
// already checked above.
697697
if (chunkInLimit.length >= item.cacheGroup.minChunks) {
698698
for (const module of item.modules) {
699699
addModuleToChunksInfoMap(
@@ -775,7 +775,7 @@ module.exports = class SplitChunksPlugin {
775775
maxSizeQueueMap.set(newChunk, {
776776
minSize: Math.max(
777777
oldMaxSizeSettings ? oldMaxSizeSettings.minSize : 0,
778-
item.cacheGroup.minSize
778+
item.cacheGroup.minSizeForMaxSize
779779
),
780780
maxSize: Math.min(
781781
oldMaxSizeSettings ? oldMaxSizeSettings.maxSize : Infinity,
Collapse file

‎test/statsCases/split-chunks-automatic-name/webpack.config.js‎

Copy file name to clipboardExpand all lines: test/statsCases/split-chunks-automatic-name/webpack.config.js
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,18 @@ module.exports = {
1717
optimization: {
1818
splitChunks: {
1919
chunks: "all",
20-
minSize: 1,
2120
cacheGroups: {
2221
default: {
2322
automaticNamePrefix: "common",
2423
reuseExistingChunk: true,
2524
minChunks: 2,
26-
priority: -20
25+
priority: -20,
26+
enforce: true // minChunks should have higher priority
2727
},
2828
vendors: {
2929
automaticNamePrefix: "common",
3030
test: /[\\/]node_modules[\\/]/,
31+
minSize: 1,
3132
priority: -10
3233
}
3334
}

0 commit comments

Comments
0 (0)
You are visitor 01402605 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.