@@ -465,11 +465,7 @@ module.exports = class SplitChunksPlugin { |
465 | 465 | module |
466 | 466 | ) => { |
467 | 467 | // 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; |
473 | 469 | // Determine name for split chunk |
474 | 470 | const name = cacheGroup.getName( |
475 | 471 | module, |
@@ -492,7 +488,7 @@ module.exports = class SplitChunksPlugin { |
492 | 488 | modules: new SortableSet(undefined, sortByIdentifier), |
493 | 489 | cacheGroup, |
494 | 490 | name, |
495 | | - validateSize: !cacheGroup.enforce && cacheGroup.minSize > 0, |
| 491 | + validateSize: cacheGroup.minSize > 0, |
496 | 492 | size: 0, |
497 | 493 | chunks: new Set(), |
498 | 494 | reuseableChunks: new Set(), |
@@ -534,27 +530,40 @@ module.exports = class SplitChunksPlugin { |
534 | 530 | priority: cacheGroupSource.priority || 0, |
535 | 531 | chunksFilter: |
536 | 532 | cacheGroupSource.chunksFilter || this.options.chunksFilter, |
537 | | - enforce: cacheGroupSource.enforce, |
538 | 533 | minSize: |
| 534 | + cacheGroupSource.minSize !== undefined |
| 535 | + ? cacheGroupSource.minSize |
| 536 | + : cacheGroupSource.enforce |
| 537 | + ? 0 |
| 538 | + : this.options.minSize, |
| 539 | + minSizeForMaxSize: |
539 | 540 | cacheGroupSource.minSize !== undefined |
540 | 541 | ? cacheGroupSource.minSize |
541 | 542 | : this.options.minSize, |
542 | 543 | maxSize: |
543 | 544 | cacheGroupSource.maxSize !== undefined |
544 | 545 | ? cacheGroupSource.maxSize |
545 | | - : this.options.maxSize, |
| 546 | + : cacheGroupSource.enforce |
| 547 | + ? 0 |
| 548 | + : this.options.maxSize, |
546 | 549 | minChunks: |
547 | 550 | cacheGroupSource.minChunks !== undefined |
548 | 551 | ? cacheGroupSource.minChunks |
549 | | - : this.options.minChunks, |
| 552 | + : cacheGroupSource.enforce |
| 553 | + ? 1 |
| 554 | + : this.options.minChunks, |
550 | 555 | maxAsyncRequests: |
551 | 556 | cacheGroupSource.maxAsyncRequests !== undefined |
552 | 557 | ? cacheGroupSource.maxAsyncRequests |
553 | | - : this.options.maxAsyncRequests, |
| 558 | + : cacheGroupSource.enforce |
| 559 | + ? Infinity |
| 560 | + : this.options.maxAsyncRequests, |
554 | 561 | maxInitialRequests: |
555 | 562 | cacheGroupSource.maxInitialRequests !== undefined |
556 | 563 | ? cacheGroupSource.maxInitialRequests |
557 | | - : this.options.maxInitialRequests, |
| 564 | + : cacheGroupSource.enforce |
| 565 | + ? Infinity |
| 566 | + : this.options.maxInitialRequests, |
558 | 567 | getName: |
559 | 568 | cacheGroupSource.getName !== undefined |
560 | 569 | ? cacheGroupSource.getName |
@@ -572,11 +581,7 @@ module.exports = class SplitChunksPlugin { |
572 | 581 | // For all combination of chunk selection |
573 | 582 | for (const chunkCombination of combs) { |
574 | 583 | // 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; |
580 | 585 | // Select chunks by configuration |
581 | 586 | const { |
582 | 587 | chunks: selectedChunks, |
@@ -586,14 +591,12 @@ module.exports = class SplitChunksPlugin { |
586 | 591 | cacheGroup.chunksFilter |
587 | 592 | ); |
588 | 593 |
|
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 | + ); |
597 | 600 | } |
598 | 601 | } |
599 | 602 | } |
@@ -672,9 +675,8 @@ module.exports = class SplitChunksPlugin { |
672 | 675 | if (usedChunks.length === 0) continue; |
673 | 676 |
|
674 | 677 | 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) |
678 | 680 | ) { |
679 | 681 | const chunkInLimit = usedChunks.filter(chunk => { |
680 | 682 | // respect max requests when not enforced |
@@ -692,8 +694,6 @@ module.exports = class SplitChunksPlugin { |
692 | 694 | }); |
693 | 695 |
|
694 | 696 | if (chunkInLimit.length < usedChunks.length) { |
695 | | - // We do not need to check enforce here as it was |
696 | | - // already checked above. |
697 | 697 | if (chunkInLimit.length >= item.cacheGroup.minChunks) { |
698 | 698 | for (const module of item.modules) { |
699 | 699 | addModuleToChunksInfoMap( |
@@ -775,7 +775,7 @@ module.exports = class SplitChunksPlugin { |
775 | 775 | maxSizeQueueMap.set(newChunk, { |
776 | 776 | minSize: Math.max( |
777 | 777 | oldMaxSizeSettings ? oldMaxSizeSettings.minSize : 0, |
778 | | - item.cacheGroup.minSize |
| 778 | + item.cacheGroup.minSizeForMaxSize |
779 | 779 | ), |
780 | 780 | maxSize: Math.min( |
781 | 781 | oldMaxSizeSettings ? oldMaxSizeSettings.maxSize : Infinity, |
|