webpack 4.41.6 → 4.44.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -75,12 +75,15 @@ const compareEntries = (a, b) => {
75
75
  const bSizeReduce = b.size * (b.chunks.size - 1);
76
76
  const diffSizeReduce = aSizeReduce - bSizeReduce;
77
77
  if (diffSizeReduce) return diffSizeReduce;
78
- // 4. by number of modules (to be able to compare by identifier)
78
+ // 4. by cache group index
79
+ const indexDiff = a.cacheGroupIndex - b.cacheGroupIndex;
80
+ if (indexDiff) return indexDiff;
81
+ // 5. by number of modules (to be able to compare by identifier)
79
82
  const modulesA = a.modules;
80
83
  const modulesB = b.modules;
81
84
  const diff = modulesA.size - modulesB.size;
82
85
  if (diff) return diff;
83
- // 5. by module identifiers
86
+ // 6. by module identifiers
84
87
  modulesA.sort();
85
88
  modulesB.sort();
86
89
  const aI = modulesA[Symbol.iterator]();
@@ -114,6 +117,7 @@ module.exports = class SplitChunksPlugin {
114
117
  options.chunks || "all"
115
118
  ),
116
119
  minSize: options.minSize || 0,
120
+ enforceSizeThreshold: options.enforceSizeThreshold || 0,
117
121
  maxSize: options.maxSize || 0,
118
122
  minChunks: options.minChunks || 1,
119
123
  maxAsyncRequests: options.maxAsyncRequests || 1,
@@ -286,6 +290,7 @@ module.exports = class SplitChunksPlugin {
286
290
  ),
287
291
  enforce: option.enforce,
288
292
  minSize: option.minSize,
293
+ enforceSizeThreshold: option.enforceSizeThreshold,
289
294
  maxSize: option.maxSize,
290
295
  minChunks: option.minChunks,
291
296
  maxAsyncRequests: option.maxAsyncRequests,
@@ -458,8 +463,8 @@ module.exports = class SplitChunksPlugin {
458
463
  * @typedef {Object} ChunksInfoItem
459
464
  * @property {SortableSet} modules
460
465
  * @property {TODO} cacheGroup
466
+ * @property {number} cacheGroupIndex
461
467
  * @property {string} name
462
- * @property {boolean} validateSize
463
468
  * @property {number} size
464
469
  * @property {Set<Chunk>} chunks
465
470
  * @property {Set<Chunk>} reuseableChunks
@@ -473,6 +478,7 @@ module.exports = class SplitChunksPlugin {
473
478
 
474
479
  /**
475
480
  * @param {TODO} cacheGroup the current cache group
481
+ * @param {number} cacheGroupIndex the index of the cache group of ordering
476
482
  * @param {Chunk[]} selectedChunks chunks selected for this module
477
483
  * @param {string} selectedChunksKey a key of selectedChunks
478
484
  * @param {Module} module the current module
@@ -480,6 +486,7 @@ module.exports = class SplitChunksPlugin {
480
486
  */
481
487
  const addModuleToChunksInfoMap = (
482
488
  cacheGroup,
489
+ cacheGroupIndex,
483
490
  selectedChunks,
484
491
  selectedChunksKey,
485
492
  module
@@ -507,8 +514,8 @@ module.exports = class SplitChunksPlugin {
507
514
  (info = {
508
515
  modules: new SortableSet(undefined, sortByIdentifier),
509
516
  cacheGroup,
517
+ cacheGroupIndex,
510
518
  name,
511
- validateSize: cacheGroup.minSize > 0,
512
519
  size: 0,
513
520
  chunks: new Set(),
514
521
  reuseableChunks: new Set(),
@@ -517,9 +524,7 @@ module.exports = class SplitChunksPlugin {
517
524
  );
518
525
  }
519
526
  info.modules.add(module);
520
- if (info.validateSize) {
521
- info.size += module.size();
522
- }
527
+ info.size += module.size();
523
528
  if (!info.chunksKeys.has(selectedChunksKey)) {
524
529
  info.chunksKeys.add(selectedChunksKey);
525
530
  for (const chunk of selectedChunks) {
@@ -544,22 +549,31 @@ module.exports = class SplitChunksPlugin {
544
549
  combinationsCache.set(chunksKey, combs);
545
550
  }
546
551
 
552
+ let cacheGroupIndex = 0;
547
553
  for (const cacheGroupSource of cacheGroups) {
554
+ const minSize =
555
+ cacheGroupSource.minSize !== undefined
556
+ ? cacheGroupSource.minSize
557
+ : cacheGroupSource.enforce
558
+ ? 0
559
+ : this.options.minSize;
560
+ const enforceSizeThreshold =
561
+ cacheGroupSource.enforceSizeThreshold !== undefined
562
+ ? cacheGroupSource.enforceSizeThreshold
563
+ : cacheGroupSource.enforce
564
+ ? 0
565
+ : this.options.enforceSizeThreshold;
548
566
  const cacheGroup = {
549
567
  key: cacheGroupSource.key,
550
568
  priority: cacheGroupSource.priority || 0,
551
569
  chunksFilter:
552
570
  cacheGroupSource.chunksFilter || this.options.chunksFilter,
553
- minSize:
554
- cacheGroupSource.minSize !== undefined
555
- ? cacheGroupSource.minSize
556
- : cacheGroupSource.enforce
557
- ? 0
558
- : this.options.minSize,
571
+ minSize,
559
572
  minSizeForMaxSize:
560
573
  cacheGroupSource.minSize !== undefined
561
574
  ? cacheGroupSource.minSize
562
575
  : this.options.minSize,
576
+ enforceSizeThreshold,
563
577
  maxSize:
564
578
  cacheGroupSource.maxSize !== undefined
565
579
  ? cacheGroupSource.maxSize
@@ -596,7 +610,9 @@ module.exports = class SplitChunksPlugin {
596
610
  cacheGroupSource.automaticNameDelimiter !== undefined
597
611
  ? cacheGroupSource.automaticNameDelimiter
598
612
  : this.options.automaticNameDelimiter,
599
- reuseExistingChunk: cacheGroupSource.reuseExistingChunk
613
+ reuseExistingChunk: cacheGroupSource.reuseExistingChunk,
614
+ _validateSize: minSize > 0,
615
+ _conditionalEnforce: enforceSizeThreshold > 0
600
616
  };
601
617
  // For all combination of chunk selection
602
618
  for (const chunkCombination of combs) {
@@ -613,18 +629,23 @@ module.exports = class SplitChunksPlugin {
613
629
 
614
630
  addModuleToChunksInfoMap(
615
631
  cacheGroup,
632
+ cacheGroupIndex,
616
633
  selectedChunks,
617
634
  selectedChunksKey,
618
635
  module
619
636
  );
620
637
  }
638
+ cacheGroupIndex++;
621
639
  }
622
640
  }
623
641
 
624
642
  // Filter items were size < minSize
625
643
  for (const pair of chunksInfoMap) {
626
644
  const info = pair[1];
627
- if (info.validateSize && info.size < info.cacheGroup.minSize) {
645
+ if (
646
+ info.cacheGroup._validateSize &&
647
+ info.size < info.cacheGroup.minSize
648
+ ) {
628
649
  chunksInfoMap.delete(pair[0]);
629
650
  }
630
651
  }
@@ -684,24 +705,30 @@ module.exports = class SplitChunksPlugin {
684
705
  }
685
706
  // Check if maxRequests condition can be fulfilled
686
707
 
687
- const usedChunks = Array.from(item.chunks).filter(chunk => {
708
+ const selectedChunks = Array.from(item.chunks).filter(chunk => {
688
709
  // skip if we address ourself
689
710
  return (
690
711
  (!chunkName || chunk.name !== chunkName) && chunk !== newChunk
691
712
  );
692
713
  });
693
714
 
715
+ const enforced =
716
+ item.cacheGroup._conditionalEnforce &&
717
+ item.size >= item.cacheGroup.enforceSizeThreshold;
718
+
694
719
  // Skip when no chunk selected
695
- if (usedChunks.length === 0) continue;
720
+ if (selectedChunks.length === 0) continue;
696
721
 
697
- let validChunks = usedChunks;
722
+ const usedChunks = new Set(selectedChunks);
698
723
 
724
+ // Check if maxRequests condition can be fulfilled
699
725
  if (
700
- Number.isFinite(item.cacheGroup.maxInitialRequests) ||
701
- Number.isFinite(item.cacheGroup.maxAsyncRequests)
726
+ !enforced &&
727
+ (Number.isFinite(item.cacheGroup.maxInitialRequests) ||
728
+ Number.isFinite(item.cacheGroup.maxAsyncRequests))
702
729
  ) {
703
- validChunks = validChunks.filter(chunk => {
704
- // respect max requests when not enforced
730
+ for (const chunk of usedChunks) {
731
+ // respect max requests
705
732
  const maxRequests = chunk.isOnlyInitial()
706
733
  ? item.cacheGroup.maxInitialRequests
707
734
  : chunk.canBeInitial()
@@ -710,26 +737,33 @@ module.exports = class SplitChunksPlugin {
710
737
  item.cacheGroup.maxAsyncRequests
711
738
  )
712
739
  : item.cacheGroup.maxAsyncRequests;
713
- return (
714
- !isFinite(maxRequests) || getRequests(chunk) < maxRequests
715
- );
716
- });
740
+ if (
741
+ isFinite(maxRequests) &&
742
+ getRequests(chunk) >= maxRequests
743
+ ) {
744
+ usedChunks.delete(chunk);
745
+ }
746
+ }
717
747
  }
718
748
 
719
- validChunks = validChunks.filter(chunk => {
749
+ outer: for (const chunk of usedChunks) {
720
750
  for (const module of item.modules) {
721
- if (chunk.containsModule(module)) return true;
751
+ if (chunk.containsModule(module)) continue outer;
722
752
  }
723
- return false;
724
- });
753
+ usedChunks.delete(chunk);
754
+ }
725
755
 
726
- if (validChunks.length < usedChunks.length) {
727
- if (validChunks.length >= item.cacheGroup.minChunks) {
756
+ // Were some (invalid) chunks removed from usedChunks?
757
+ // => readd all modules to the queue, as things could have been changed
758
+ if (usedChunks.size < selectedChunks.length) {
759
+ if (usedChunks.size >= item.cacheGroup.minChunks) {
760
+ const chunksArr = Array.from(usedChunks);
728
761
  for (const module of item.modules) {
729
762
  addModuleToChunksInfoMap(
730
763
  item.cacheGroup,
731
- validChunks,
732
- getKey(validChunks),
764
+ item.cacheGroupIndex,
765
+ chunksArr,
766
+ getKey(usedChunks),
733
767
  module
734
768
  );
735
769
  }
@@ -819,28 +853,24 @@ module.exports = class SplitChunksPlugin {
819
853
 
820
854
  // remove all modules from other entries and update size
821
855
  for (const [key, info] of chunksInfoMap) {
822
- if (isOverlap(info.chunks, item.chunks)) {
823
- if (info.validateSize) {
824
- // update modules and total size
825
- // may remove it from the map when < minSize
826
- const oldSize = info.modules.size;
827
- for (const module of item.modules) {
828
- info.modules.delete(module);
829
- }
856
+ if (isOverlap(info.chunks, usedChunks)) {
857
+ // update modules and total size
858
+ // may remove it from the map when < minSize
859
+ const oldSize = info.modules.size;
860
+ for (const module of item.modules) {
861
+ info.modules.delete(module);
862
+ }
863
+ if (info.modules.size !== oldSize) {
830
864
  if (info.modules.size === 0) {
831
865
  chunksInfoMap.delete(key);
832
866
  continue;
833
867
  }
834
- if (info.modules.size !== oldSize) {
835
- info.size = getModulesSize(info.modules);
836
- if (info.size < info.cacheGroup.minSize) {
837
- chunksInfoMap.delete(key);
838
- }
839
- }
840
- } else {
841
- // only update the modules
842
- for (const module of item.modules) {
843
- info.modules.delete(module);
868
+ info.size = getModulesSize(info.modules);
869
+ if (
870
+ info.cacheGroup._validateSize &&
871
+ info.size < info.cacheGroup.minSize
872
+ ) {
873
+ chunksInfoMap.delete(key);
844
874
  }
845
875
  if (info.modules.size === 0) {
846
876
  chunksInfoMap.delete(key);
package/package.json CHANGED
@@ -1,32 +1,32 @@
1
1
  {
2
2
  "name": "webpack",
3
- "version": "4.41.6",
3
+ "version": "4.44.0",
4
4
  "author": "Tobias Koppers @sokra",
5
5
  "description": "Packs CommonJs/AMD modules for the browser. Allows to split your codebase into multiple bundles, which can be loaded on demand. Support loaders to preprocess files, i.e. json, jsx, es7, css, less, ... and your custom stuff.",
6
6
  "license": "MIT",
7
7
  "dependencies": {
8
- "@webassemblyjs/ast": "1.8.5",
9
- "@webassemblyjs/helper-module-context": "1.8.5",
10
- "@webassemblyjs/wasm-edit": "1.8.5",
11
- "@webassemblyjs/wasm-parser": "1.8.5",
12
- "acorn": "^6.2.1",
8
+ "@webassemblyjs/ast": "1.9.0",
9
+ "@webassemblyjs/helper-module-context": "1.9.0",
10
+ "@webassemblyjs/wasm-edit": "1.9.0",
11
+ "@webassemblyjs/wasm-parser": "1.9.0",
12
+ "acorn": "^6.4.1",
13
13
  "ajv": "^6.10.2",
14
14
  "ajv-keywords": "^3.4.1",
15
15
  "chrome-trace-event": "^1.0.2",
16
- "enhanced-resolve": "^4.1.0",
16
+ "enhanced-resolve": "^4.3.0",
17
17
  "eslint-scope": "^4.0.3",
18
18
  "json-parse-better-errors": "^1.0.2",
19
19
  "loader-runner": "^2.4.0",
20
20
  "loader-utils": "^1.2.3",
21
21
  "memory-fs": "^0.4.1",
22
22
  "micromatch": "^3.1.10",
23
- "mkdirp": "^0.5.1",
23
+ "mkdirp": "^0.5.3",
24
24
  "neo-async": "^2.6.1",
25
25
  "node-libs-browser": "^2.2.1",
26
26
  "schema-utils": "^1.0.0",
27
27
  "tapable": "^1.1.3",
28
28
  "terser-webpack-plugin": "^1.4.3",
29
- "watchpack": "^1.6.0",
29
+ "watchpack": "^1.7.4",
30
30
  "webpack-sources": "^1.4.1"
31
31
  },
32
32
  "devDependencies": {
@@ -80,6 +80,7 @@
80
80
  "vm-browserify": "~1.1.0",
81
81
  "wast-loader": "^1.5.5",
82
82
  "webpack-dev-middleware": "^3.5.1",
83
+ "webassembly-feature": "1.3.0",
83
84
  "worker-loader": "^2.0.0",
84
85
  "xxhashjs": "^0.2.1"
85
86
  },
@@ -612,6 +612,10 @@
612
612
  "description": "Ignore minimum size, minimum chunks and maximum requests and always create chunks for this cache group",
613
613
  "type": "boolean"
614
614
  },
615
+ "enforceSizeThreshold": {
616
+ "description": "Size threshold at which splitting is enforced and other restrictions (maxAsyncRequests, maxInitialRequests) are ignored.",
617
+ "type": "number"
618
+ },
615
619
  "filename": {
616
620
  "description": "Sets the template for the filename for created chunks (Only works for initial chunks)",
617
621
  "type": "string",
@@ -722,6 +726,10 @@
722
726
  }
723
727
  ]
724
728
  },
729
+ "enforceSizeThreshold": {
730
+ "description": "Size threshold at which splitting is enforced and other restrictions (maxAsyncRequests, maxInitialRequests) are ignored.",
731
+ "type": "number"
732
+ },
725
733
  "fallbackCacheGroup": {
726
734
  "description": "Options for modules not selected by any other cache group",
727
735
  "type": "object",
@@ -940,16 +948,8 @@
940
948
  },
941
949
  "hotUpdateChunkFilename": {
942
950
  "description": "The filename of the Hot Update Chunks. They are inside the output.path directory.",
943
- "anyOf": [
944
- {
945
- "type": "string",
946
- "absolutePath": false
947
- },
948
- {
949
- "instanceof": "Function",
950
- "tsType": "Function"
951
- }
952
- ]
951
+ "type": "string",
952
+ "absolutePath": false
953
953
  },
954
954
  "hotUpdateFunction": {
955
955
  "description": "The JSONP function used by webpack for async loading of hot update chunks.",
@@ -1229,6 +1229,14 @@
1229
1229
  "resolver": {
1230
1230
  "description": "Custom resolver"
1231
1231
  },
1232
+ "roots": {
1233
+ "description": "A list of directories in which requests that are server-relative URLs (starting with '/') are resolved. On non-windows system these requests are tried to resolve as absolute path first.",
1234
+ "type": "array",
1235
+ "items": {
1236
+ "description": "Directory in which requests that are server-relative URLs (starting with '/') are resolved.",
1237
+ "type": "string"
1238
+ }
1239
+ },
1232
1240
  "symlinks": {
1233
1241
  "description": "Enable resolving symlinks to the original location",
1234
1242
  "type": "boolean"