webpack 4.1.0 → 4.4.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.
Files changed (118) hide show
  1. package/README.md +719 -721
  2. package/bin/webpack.js +69 -10
  3. package/lib/APIPlugin.js +84 -84
  4. package/lib/AmdMainTemplatePlugin.js +75 -77
  5. package/lib/AsyncDependencyToInitialChunkError.js +21 -23
  6. package/lib/BannerPlugin.js +101 -101
  7. package/lib/Chunk.js +477 -469
  8. package/lib/ChunkTemplate.js +51 -53
  9. package/lib/Compilation.js +1858 -1851
  10. package/lib/Compiler.js +493 -478
  11. package/lib/ConcurrentCompilationError.js +19 -0
  12. package/lib/ContextModule.js +696 -685
  13. package/lib/ContextModuleFactory.js +245 -243
  14. package/lib/DefinePlugin.js +197 -197
  15. package/lib/DelegatedModule.js +101 -101
  16. package/lib/DependenciesBlockVariable.js +51 -52
  17. package/lib/Dependency.js +53 -52
  18. package/lib/DllModule.js +54 -54
  19. package/lib/DllModuleFactory.js +29 -29
  20. package/lib/EnvironmentPlugin.js +65 -67
  21. package/lib/EvalDevToolModuleTemplatePlugin.js +60 -60
  22. package/lib/EvalSourceMapDevToolModuleTemplatePlugin.js +105 -105
  23. package/lib/ExportPropertyMainTemplatePlugin.js +40 -40
  24. package/lib/ExternalModule.js +159 -159
  25. package/lib/FunctionModuleTemplatePlugin.js +98 -98
  26. package/lib/HotModuleReplacement.runtime.js +631 -631
  27. package/lib/HotModuleReplacementPlugin.js +407 -406
  28. package/lib/HotUpdateChunkTemplate.js +78 -80
  29. package/lib/JavascriptGenerator.js +228 -229
  30. package/lib/JavascriptModulesPlugin.js +184 -158
  31. package/lib/JsonGenerator.js +42 -42
  32. package/lib/MainTemplate.js +406 -402
  33. package/lib/Module.js +343 -340
  34. package/lib/ModuleBuildError.js +42 -42
  35. package/lib/ModuleError.js +28 -28
  36. package/lib/ModuleFilenameHelpers.js +166 -166
  37. package/lib/ModuleTemplate.js +77 -79
  38. package/lib/ModuleWarning.js +30 -30
  39. package/lib/MultiCompiler.js +271 -259
  40. package/lib/MultiModule.js +78 -75
  41. package/lib/MultiModuleFactory.js +23 -23
  42. package/lib/MultiWatching.js +38 -37
  43. package/lib/NoModeWarning.js +23 -21
  44. package/lib/NormalModule.js +478 -470
  45. package/lib/NormalModuleFactory.js +483 -481
  46. package/lib/OptionsDefaulter.js +80 -86
  47. package/lib/Parser.js +2074 -2071
  48. package/lib/ProgressPlugin.js +231 -231
  49. package/lib/RawModule.js +54 -55
  50. package/lib/RecordIdsPlugin.js +160 -160
  51. package/lib/RemovedPluginError.js +13 -13
  52. package/lib/ResolverFactory.js +64 -67
  53. package/lib/RuntimeTemplate.js +267 -297
  54. package/lib/SetVarMainTemplatePlugin.js +57 -57
  55. package/lib/SourceMapDevToolPlugin.js +302 -308
  56. package/lib/Stats.js +1234 -1212
  57. package/lib/Template.js +205 -205
  58. package/lib/TemplatedPathPlugin.js +170 -143
  59. package/lib/UmdMainTemplatePlugin.js +264 -269
  60. package/lib/Watching.js +193 -193
  61. package/lib/WebAssemblyParser.js +50 -54
  62. package/lib/WebpackOptionsApply.js +401 -401
  63. package/lib/WebpackOptionsDefaulter.js +337 -317
  64. package/lib/WebpackOptionsValidationError.js +316 -319
  65. package/lib/debug/ProfilingPlugin.js +409 -405
  66. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +328 -311
  67. package/lib/dependencies/AMDRequireContextDependency.js +20 -20
  68. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +270 -241
  69. package/lib/dependencies/HarmonyAcceptImportDependency.js +23 -23
  70. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +620 -606
  71. package/lib/dependencies/HarmonyExportSpecifierDependency.js +53 -53
  72. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +214 -214
  73. package/lib/dependencies/HarmonyImportSpecifierDependency.js +154 -156
  74. package/lib/dependencies/ImportDependenciesBlock.js +17 -17
  75. package/lib/dependencies/ImportDependency.js +34 -34
  76. package/lib/dependencies/ImportEagerDependency.js +32 -32
  77. package/lib/dependencies/ImportParserPlugin.js +175 -179
  78. package/lib/dependencies/ImportWeakDependency.js +34 -34
  79. package/lib/dependencies/JsonExportsDependency.js +25 -25
  80. package/lib/dependencies/ModuleDependency.js +20 -20
  81. package/lib/dependencies/NullDependency.js +20 -20
  82. package/lib/dependencies/RequireContextDependency.js +22 -22
  83. package/lib/dependencies/RequireIncludeDependency.js +40 -40
  84. package/lib/dependencies/WebpackMissingModule.js +20 -22
  85. package/lib/node/NodeChunkTemplatePlugin.js +31 -31
  86. package/lib/node/NodeHotUpdateChunkTemplatePlugin.js +36 -36
  87. package/lib/node/NodeMainTemplatePlugin.js +320 -273
  88. package/lib/node/ReadFileCompileWasmMainTemplatePlugin.js +113 -115
  89. package/lib/optimize/AggressiveSplittingPlugin.js +281 -281
  90. package/lib/optimize/ConcatenatedModule.js +1364 -1366
  91. package/lib/optimize/RemoveParentModulesPlugin.js +114 -114
  92. package/lib/optimize/SplitChunksPlugin.js +519 -491
  93. package/lib/performance/SizeLimitsPlugin.js +105 -105
  94. package/lib/util/TrackingSet.js +35 -35
  95. package/lib/util/objectToMap.js +10 -10
  96. package/lib/wasm/WasmModuleTemplatePlugin.js +106 -106
  97. package/lib/web/JsonpChunkTemplatePlugin.js +47 -47
  98. package/lib/web/JsonpExportMainTemplatePlugin.js +47 -47
  99. package/lib/web/JsonpHotUpdateChunkTemplatePlugin.js +39 -39
  100. package/lib/web/JsonpMainTemplatePlugin.js +425 -403
  101. package/lib/webpack.js +182 -179
  102. package/lib/webworker/WebWorkerChunkTemplatePlugin.js +35 -35
  103. package/lib/webworker/WebWorkerHotUpdateChunkTemplatePlugin.js +40 -40
  104. package/lib/webworker/WebWorkerMainTemplatePlugin.js +177 -154
  105. package/package.json +9 -8
  106. package/schemas/WebpackOptions.json +1973 -1951
  107. package/schemas/ajv.absolutePath.js +55 -29
  108. package/schemas/plugins/BannerPlugin.json +85 -85
  109. package/schemas/plugins/DllPlugin.json +28 -28
  110. package/schemas/plugins/DllReferencePlugin.json +99 -99
  111. package/schemas/plugins/HashedModuleIdsPlugin.json +24 -24
  112. package/schemas/plugins/LoaderOptionsPlugin.json +26 -26
  113. package/schemas/plugins/SourceMapDevToolPlugin.json +187 -187
  114. package/schemas/plugins/WatchIgnorePlugin.json +16 -16
  115. package/schemas/plugins/debug/ProfilingPlugin.json +12 -12
  116. package/schemas/plugins/optimize/AggressiveSplittingPlugin.json +22 -22
  117. package/schemas/plugins/optimize/LimitChunkCountPlugin.json +15 -15
  118. package/schemas/plugins/optimize/MinChunkSizePlugin.json +13 -13
@@ -1,281 +1,281 @@
1
- /*
2
- MIT License http://www.opensource.org/licenses/mit-license.php
3
- Author Tobias Koppers @sokra
4
- */
5
- "use strict";
6
-
7
- const identifierUtils = require("../util/identifier");
8
- const intersect = require("../util/SetHelpers").intersect;
9
- const validateOptions = require("schema-utils");
10
- const schema = require("../../schemas/plugins/optimize/AggressiveSplittingPlugin.json");
11
-
12
- const moveModuleBetween = (oldChunk, newChunk) => {
13
- return module => {
14
- oldChunk.moveModule(module, newChunk);
15
- };
16
- };
17
-
18
- const isNotAEntryModule = entryModule => {
19
- return module => {
20
- return entryModule !== module;
21
- };
22
- };
23
-
24
- class AggressiveSplittingPlugin {
25
- constructor(options) {
26
- validateOptions(schema, options || {}, "Aggressive Splitting Plugin");
27
-
28
- this.options = options || {};
29
- if (typeof this.options.minSize !== "number")
30
- this.options.minSize = 30 * 1024;
31
- if (typeof this.options.maxSize !== "number")
32
- this.options.maxSize = 50 * 1024;
33
- if (typeof this.options.chunkOverhead !== "number")
34
- this.options.chunkOverhead = 0;
35
- if (typeof this.options.entryChunkMultiplicator !== "number")
36
- this.options.entryChunkMultiplicator = 1;
37
- }
38
- apply(compiler) {
39
- compiler.hooks.thisCompilation.tap(
40
- "AggressiveSplittingPlugin",
41
- compilation => {
42
- let needAdditionalSeal = false;
43
- let newSplits;
44
- let fromAggressiveSplittingSet;
45
- let chunkSplitDataMap;
46
- compilation.hooks.optimize.tap("AggressiveSplittingPlugin", () => {
47
- newSplits = [];
48
- fromAggressiveSplittingSet = new Set();
49
- chunkSplitDataMap = new Map();
50
- });
51
- compilation.hooks.optimizeChunksAdvanced.tap(
52
- "AggressiveSplittingPlugin",
53
- chunks => {
54
- // Precompute stuff
55
- const nameToModuleMap = new Map();
56
- const moduleToNameMap = new Map();
57
- for (const m of compilation.modules) {
58
- const name = identifierUtils.makePathsRelative(
59
- compiler.context,
60
- m.identifier(),
61
- compilation.cache
62
- );
63
- nameToModuleMap.set(name, m);
64
- moduleToNameMap.set(m, name);
65
- }
66
-
67
- // Check used chunk ids
68
- const usedIds = new Set();
69
- for (const chunk of chunks) {
70
- usedIds.add(chunk.id);
71
- }
72
-
73
- const recordedSplits =
74
- (compilation.records && compilation.records.aggressiveSplits) ||
75
- [];
76
- const usedSplits = newSplits
77
- ? recordedSplits.concat(newSplits)
78
- : recordedSplits;
79
-
80
- const minSize = this.options.minSize;
81
- const maxSize = this.options.maxSize;
82
-
83
- const applySplit = splitData => {
84
- // Cannot split if id is already taken
85
- if (splitData.id !== undefined && usedIds.has(splitData.id))
86
- return false;
87
-
88
- // Get module objects from names
89
- const selectedModules = splitData.modules.map(name =>
90
- nameToModuleMap.get(name)
91
- );
92
-
93
- // Does the modules exist at all?
94
- if (!selectedModules.every(Boolean)) return false;
95
-
96
- // Check if size matches (faster than waiting for hash)
97
- const size = selectedModules.reduce(
98
- (sum, m) => sum + m.size(),
99
- 0
100
- );
101
- if (size !== splitData.size) return false;
102
-
103
- // get chunks with all modules
104
- const selectedChunks = intersect(
105
- selectedModules.map(m => new Set(m.chunksIterable))
106
- );
107
-
108
- // No relevant chunks found
109
- if (selectedChunks.size === 0) return false;
110
-
111
- // The found chunk is already the split or similar
112
- if (
113
- selectedChunks.size === 1 &&
114
- Array.from(selectedChunks)[0].getNumberOfModules() ===
115
- selectedModules.length
116
- ) {
117
- const chunk = Array.from(selectedChunks)[0];
118
- if (fromAggressiveSplittingSet.has(chunk)) return false;
119
- fromAggressiveSplittingSet.add(chunk);
120
- chunkSplitDataMap.set(chunk, splitData);
121
- return true;
122
- }
123
-
124
- // split the chunk into two parts
125
- const newChunk = compilation.addChunk();
126
- newChunk.chunkReason = "aggressive splitted";
127
- for (const chunk of selectedChunks) {
128
- selectedModules.forEach(moveModuleBetween(chunk, newChunk));
129
- chunk.split(newChunk);
130
- chunk.name = null;
131
- }
132
- fromAggressiveSplittingSet.add(newChunk);
133
- chunkSplitDataMap.set(newChunk, splitData);
134
-
135
- if (splitData.id !== null && splitData.id !== undefined) {
136
- newChunk.id = splitData.id;
137
- }
138
- return true;
139
- };
140
-
141
- // try to restore to recorded splitting
142
- let changed = false;
143
- for (let j = 0; j < usedSplits.length; j++) {
144
- const splitData = usedSplits[j];
145
- if (applySplit(splitData)) changed = true;
146
- }
147
-
148
- // for any chunk which isn't splitted yet, split it and create a new entry
149
- // start with the biggest chunk
150
- const sortedChunks = chunks.slice().sort((a, b) => {
151
- const diff1 = b.modulesSize() - a.modulesSize();
152
- if (diff1) return diff1;
153
- const diff2 = a.getNumberOfModules() - b.getNumberOfModules();
154
- if (diff2) return diff2;
155
- const modulesA = Array.from(a.modulesIterable);
156
- const modulesB = Array.from(b.modulesIterable);
157
- modulesA.sort();
158
- modulesB.sort();
159
- const aI = modulesA[Symbol.iterator]();
160
- const bI = modulesB[Symbol.iterator]();
161
- // eslint-disable-next-line no-constant-condition
162
- while (true) {
163
- const aItem = aI.next();
164
- const bItem = bI.next();
165
- if (aItem.done) return 0;
166
- const aModuleIdentifier = aItem.value.identifier();
167
- const bModuleIdentifier = bItem.value.identifier();
168
- if (aModuleIdentifier > bModuleIdentifier) return -1;
169
- if (aModuleIdentifier < bModuleIdentifier) return 1;
170
- }
171
- });
172
- for (const chunk of sortedChunks) {
173
- if (fromAggressiveSplittingSet.has(chunk)) continue;
174
- const size = chunk.modulesSize();
175
- if (size > maxSize && chunk.getNumberOfModules() > 1) {
176
- const modules = chunk
177
- .getModules()
178
- .filter(isNotAEntryModule(chunk.entryModule))
179
- .sort((a, b) => {
180
- a = a.identifier();
181
- b = b.identifier();
182
- if (a > b) return 1;
183
- if (a < b) return -1;
184
- return 0;
185
- });
186
- const selectedModules = [];
187
- let selectedModulesSize = 0;
188
- for (let k = 0; k < modules.length; k++) {
189
- const module = modules[k];
190
- const newSize = selectedModulesSize + module.size();
191
- if (newSize > maxSize && selectedModulesSize >= minSize)
192
- break;
193
- selectedModulesSize = newSize;
194
- selectedModules.push(module);
195
- }
196
- if (selectedModules.length === 0) continue;
197
- const splitData = {
198
- modules: selectedModules
199
- .map(m => moduleToNameMap.get(m))
200
- .sort(),
201
- size: selectedModulesSize
202
- };
203
-
204
- if (applySplit(splitData)) {
205
- newSplits = (newSplits || []).concat(splitData);
206
- changed = true;
207
- }
208
- }
209
- }
210
- if (changed) return true;
211
- }
212
- );
213
- compilation.hooks.recordHash.tap(
214
- "AggressiveSplittingPlugin",
215
- records => {
216
- // 4. save made splittings to records
217
- const allSplits = new Set();
218
- const invalidSplits = new Set();
219
-
220
- // Check if some splittings are invalid
221
- // We remove invalid splittings and try again
222
- for (const chunk of compilation.chunks) {
223
- const splitData = chunkSplitDataMap.get(chunk);
224
- if (splitData !== undefined) {
225
- if (splitData.hash && chunk.hash !== splitData.hash) {
226
- // Split was successful, but hash doesn't equal
227
- // We can throw away the split since it's useless now
228
- invalidSplits.add(splitData);
229
- }
230
- }
231
- }
232
-
233
- if (invalidSplits.size > 0) {
234
- records.aggressiveSplits = records.aggressiveSplits.filter(
235
- splitData => !invalidSplits.has(splitData)
236
- );
237
- needAdditionalSeal = true;
238
- } else {
239
- // set hash and id values on all (new) splittings
240
- for (const chunk of compilation.chunks) {
241
- const splitData = chunkSplitDataMap.get(chunk);
242
- if (splitData !== undefined) {
243
- splitData.hash = chunk.hash;
244
- splitData.id = chunk.id;
245
- allSplits.add(splitData);
246
- // set flag for stats
247
- chunk.recorded = true;
248
- }
249
- }
250
-
251
- // Also add all unused historial splits (after the used ones)
252
- // They can still be used in some future compilation
253
- const recordedSplits =
254
- compilation.records && compilation.records.aggressiveSplits;
255
- if (recordedSplits) {
256
- for (const splitData of recordedSplits) {
257
- if (!invalidSplits.has(splitData)) allSplits.add(splitData);
258
- }
259
- }
260
-
261
- // record all splits
262
- records.aggressiveSplits = Array.from(allSplits);
263
-
264
- needAdditionalSeal = false;
265
- }
266
- }
267
- );
268
- compilation.hooks.needAdditionalSeal.tap(
269
- "AggressiveSplittingPlugin",
270
- () => {
271
- if (needAdditionalSeal) {
272
- needAdditionalSeal = false;
273
- return true;
274
- }
275
- }
276
- );
277
- }
278
- );
279
- }
280
- }
281
- module.exports = AggressiveSplittingPlugin;
1
+ /*
2
+ MIT License http://www.opensource.org/licenses/mit-license.php
3
+ Author Tobias Koppers @sokra
4
+ */
5
+ "use strict";
6
+
7
+ const identifierUtils = require("../util/identifier");
8
+ const { intersect } = require("../util/SetHelpers");
9
+ const validateOptions = require("schema-utils");
10
+ const schema = require("../../schemas/plugins/optimize/AggressiveSplittingPlugin.json");
11
+
12
+ const moveModuleBetween = (oldChunk, newChunk) => {
13
+ return module => {
14
+ oldChunk.moveModule(module, newChunk);
15
+ };
16
+ };
17
+
18
+ const isNotAEntryModule = entryModule => {
19
+ return module => {
20
+ return entryModule !== module;
21
+ };
22
+ };
23
+
24
+ class AggressiveSplittingPlugin {
25
+ constructor(options) {
26
+ validateOptions(schema, options || {}, "Aggressive Splitting Plugin");
27
+
28
+ this.options = options || {};
29
+ if (typeof this.options.minSize !== "number")
30
+ this.options.minSize = 30 * 1024;
31
+ if (typeof this.options.maxSize !== "number")
32
+ this.options.maxSize = 50 * 1024;
33
+ if (typeof this.options.chunkOverhead !== "number")
34
+ this.options.chunkOverhead = 0;
35
+ if (typeof this.options.entryChunkMultiplicator !== "number")
36
+ this.options.entryChunkMultiplicator = 1;
37
+ }
38
+ apply(compiler) {
39
+ compiler.hooks.thisCompilation.tap(
40
+ "AggressiveSplittingPlugin",
41
+ compilation => {
42
+ let needAdditionalSeal = false;
43
+ let newSplits;
44
+ let fromAggressiveSplittingSet;
45
+ let chunkSplitDataMap;
46
+ compilation.hooks.optimize.tap("AggressiveSplittingPlugin", () => {
47
+ newSplits = [];
48
+ fromAggressiveSplittingSet = new Set();
49
+ chunkSplitDataMap = new Map();
50
+ });
51
+ compilation.hooks.optimizeChunksAdvanced.tap(
52
+ "AggressiveSplittingPlugin",
53
+ chunks => {
54
+ // Precompute stuff
55
+ const nameToModuleMap = new Map();
56
+ const moduleToNameMap = new Map();
57
+ for (const m of compilation.modules) {
58
+ const name = identifierUtils.makePathsRelative(
59
+ compiler.context,
60
+ m.identifier(),
61
+ compilation.cache
62
+ );
63
+ nameToModuleMap.set(name, m);
64
+ moduleToNameMap.set(m, name);
65
+ }
66
+
67
+ // Check used chunk ids
68
+ const usedIds = new Set();
69
+ for (const chunk of chunks) {
70
+ usedIds.add(chunk.id);
71
+ }
72
+
73
+ const recordedSplits =
74
+ (compilation.records && compilation.records.aggressiveSplits) ||
75
+ [];
76
+ const usedSplits = newSplits
77
+ ? recordedSplits.concat(newSplits)
78
+ : recordedSplits;
79
+
80
+ const minSize = this.options.minSize;
81
+ const maxSize = this.options.maxSize;
82
+
83
+ const applySplit = splitData => {
84
+ // Cannot split if id is already taken
85
+ if (splitData.id !== undefined && usedIds.has(splitData.id))
86
+ return false;
87
+
88
+ // Get module objects from names
89
+ const selectedModules = splitData.modules.map(name =>
90
+ nameToModuleMap.get(name)
91
+ );
92
+
93
+ // Does the modules exist at all?
94
+ if (!selectedModules.every(Boolean)) return false;
95
+
96
+ // Check if size matches (faster than waiting for hash)
97
+ const size = selectedModules.reduce(
98
+ (sum, m) => sum + m.size(),
99
+ 0
100
+ );
101
+ if (size !== splitData.size) return false;
102
+
103
+ // get chunks with all modules
104
+ const selectedChunks = intersect(
105
+ selectedModules.map(m => new Set(m.chunksIterable))
106
+ );
107
+
108
+ // No relevant chunks found
109
+ if (selectedChunks.size === 0) return false;
110
+
111
+ // The found chunk is already the split or similar
112
+ if (
113
+ selectedChunks.size === 1 &&
114
+ Array.from(selectedChunks)[0].getNumberOfModules() ===
115
+ selectedModules.length
116
+ ) {
117
+ const chunk = Array.from(selectedChunks)[0];
118
+ if (fromAggressiveSplittingSet.has(chunk)) return false;
119
+ fromAggressiveSplittingSet.add(chunk);
120
+ chunkSplitDataMap.set(chunk, splitData);
121
+ return true;
122
+ }
123
+
124
+ // split the chunk into two parts
125
+ const newChunk = compilation.addChunk();
126
+ newChunk.chunkReason = "aggressive splitted";
127
+ for (const chunk of selectedChunks) {
128
+ selectedModules.forEach(moveModuleBetween(chunk, newChunk));
129
+ chunk.split(newChunk);
130
+ chunk.name = null;
131
+ }
132
+ fromAggressiveSplittingSet.add(newChunk);
133
+ chunkSplitDataMap.set(newChunk, splitData);
134
+
135
+ if (splitData.id !== null && splitData.id !== undefined) {
136
+ newChunk.id = splitData.id;
137
+ }
138
+ return true;
139
+ };
140
+
141
+ // try to restore to recorded splitting
142
+ let changed = false;
143
+ for (let j = 0; j < usedSplits.length; j++) {
144
+ const splitData = usedSplits[j];
145
+ if (applySplit(splitData)) changed = true;
146
+ }
147
+
148
+ // for any chunk which isn't splitted yet, split it and create a new entry
149
+ // start with the biggest chunk
150
+ const sortedChunks = chunks.slice().sort((a, b) => {
151
+ const diff1 = b.modulesSize() - a.modulesSize();
152
+ if (diff1) return diff1;
153
+ const diff2 = a.getNumberOfModules() - b.getNumberOfModules();
154
+ if (diff2) return diff2;
155
+ const modulesA = Array.from(a.modulesIterable);
156
+ const modulesB = Array.from(b.modulesIterable);
157
+ modulesA.sort();
158
+ modulesB.sort();
159
+ const aI = modulesA[Symbol.iterator]();
160
+ const bI = modulesB[Symbol.iterator]();
161
+ // eslint-disable-next-line no-constant-condition
162
+ while (true) {
163
+ const aItem = aI.next();
164
+ const bItem = bI.next();
165
+ if (aItem.done) return 0;
166
+ const aModuleIdentifier = aItem.value.identifier();
167
+ const bModuleIdentifier = bItem.value.identifier();
168
+ if (aModuleIdentifier > bModuleIdentifier) return -1;
169
+ if (aModuleIdentifier < bModuleIdentifier) return 1;
170
+ }
171
+ });
172
+ for (const chunk of sortedChunks) {
173
+ if (fromAggressiveSplittingSet.has(chunk)) continue;
174
+ const size = chunk.modulesSize();
175
+ if (size > maxSize && chunk.getNumberOfModules() > 1) {
176
+ const modules = chunk
177
+ .getModules()
178
+ .filter(isNotAEntryModule(chunk.entryModule))
179
+ .sort((a, b) => {
180
+ a = a.identifier();
181
+ b = b.identifier();
182
+ if (a > b) return 1;
183
+ if (a < b) return -1;
184
+ return 0;
185
+ });
186
+ const selectedModules = [];
187
+ let selectedModulesSize = 0;
188
+ for (let k = 0; k < modules.length; k++) {
189
+ const module = modules[k];
190
+ const newSize = selectedModulesSize + module.size();
191
+ if (newSize > maxSize && selectedModulesSize >= minSize)
192
+ break;
193
+ selectedModulesSize = newSize;
194
+ selectedModules.push(module);
195
+ }
196
+ if (selectedModules.length === 0) continue;
197
+ const splitData = {
198
+ modules: selectedModules
199
+ .map(m => moduleToNameMap.get(m))
200
+ .sort(),
201
+ size: selectedModulesSize
202
+ };
203
+
204
+ if (applySplit(splitData)) {
205
+ newSplits = (newSplits || []).concat(splitData);
206
+ changed = true;
207
+ }
208
+ }
209
+ }
210
+ if (changed) return true;
211
+ }
212
+ );
213
+ compilation.hooks.recordHash.tap(
214
+ "AggressiveSplittingPlugin",
215
+ records => {
216
+ // 4. save made splittings to records
217
+ const allSplits = new Set();
218
+ const invalidSplits = new Set();
219
+
220
+ // Check if some splittings are invalid
221
+ // We remove invalid splittings and try again
222
+ for (const chunk of compilation.chunks) {
223
+ const splitData = chunkSplitDataMap.get(chunk);
224
+ if (splitData !== undefined) {
225
+ if (splitData.hash && chunk.hash !== splitData.hash) {
226
+ // Split was successful, but hash doesn't equal
227
+ // We can throw away the split since it's useless now
228
+ invalidSplits.add(splitData);
229
+ }
230
+ }
231
+ }
232
+
233
+ if (invalidSplits.size > 0) {
234
+ records.aggressiveSplits = records.aggressiveSplits.filter(
235
+ splitData => !invalidSplits.has(splitData)
236
+ );
237
+ needAdditionalSeal = true;
238
+ } else {
239
+ // set hash and id values on all (new) splittings
240
+ for (const chunk of compilation.chunks) {
241
+ const splitData = chunkSplitDataMap.get(chunk);
242
+ if (splitData !== undefined) {
243
+ splitData.hash = chunk.hash;
244
+ splitData.id = chunk.id;
245
+ allSplits.add(splitData);
246
+ // set flag for stats
247
+ chunk.recorded = true;
248
+ }
249
+ }
250
+
251
+ // Also add all unused historial splits (after the used ones)
252
+ // They can still be used in some future compilation
253
+ const recordedSplits =
254
+ compilation.records && compilation.records.aggressiveSplits;
255
+ if (recordedSplits) {
256
+ for (const splitData of recordedSplits) {
257
+ if (!invalidSplits.has(splitData)) allSplits.add(splitData);
258
+ }
259
+ }
260
+
261
+ // record all splits
262
+ records.aggressiveSplits = Array.from(allSplits);
263
+
264
+ needAdditionalSeal = false;
265
+ }
266
+ }
267
+ );
268
+ compilation.hooks.needAdditionalSeal.tap(
269
+ "AggressiveSplittingPlugin",
270
+ () => {
271
+ if (needAdditionalSeal) {
272
+ needAdditionalSeal = false;
273
+ return true;
274
+ }
275
+ }
276
+ );
277
+ }
278
+ );
279
+ }
280
+ }
281
+ module.exports = AggressiveSplittingPlugin;