webpack 4.10.1 → 4.10.2
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.
- package/lib/AmdMainTemplatePlugin.js +3 -1
- package/lib/BannerPlugin.js +3 -1
- package/lib/BasicEvaluatedExpression.js +14 -11
- package/lib/CachePlugin.js +12 -5
- package/lib/Chunk.js +44 -16
- package/lib/ChunkGroup.js +13 -5
- package/lib/Compilation.js +70 -28
- package/lib/Compiler.js +22 -10
- package/lib/ConstPlugin.js +25 -9
- package/lib/ContextModule.js +88 -36
- package/lib/ContextModuleFactory.js +18 -7
- package/lib/ContextReplacementPlugin.js +14 -7
- package/lib/DefinePlugin.js +15 -6
- package/lib/DependenciesBlock.js +3 -1
- package/lib/DependenciesBlockVariable.js +2 -1
- package/lib/DllPlugin.js +4 -2
- package/lib/DynamicEntryPlugin.js +4 -2
- package/lib/ErrorHelpers.js +5 -2
- package/lib/EvalSourceMapDevToolPlugin.js +2 -1
- package/lib/FlagDependencyUsagePlugin.js +11 -5
- package/lib/FunctionModuleTemplatePlugin.js +8 -6
- package/lib/HotModuleReplacement.runtime.js +7 -3
- package/lib/HotModuleReplacementPlugin.js +13 -6
- package/lib/JavascriptGenerator.js +2 -1
- package/lib/JavascriptModulesPlugin.js +4 -9
- package/lib/JsonParser.js +2 -1
- package/lib/LibraryTemplatePlugin.js +2 -1
- package/lib/LoaderOptionsPlugin.js +2 -1
- package/lib/MainTemplate.js +2 -1
- package/lib/Module.js +9 -5
- package/lib/ModuleFilenameHelpers.js +20 -8
- package/lib/MultiCompiler.js +19 -7
- package/lib/MultiModule.js +5 -2
- package/lib/NodeStuffPlugin.js +2 -1
- package/lib/NormalModule.js +11 -4
- package/lib/NormalModuleFactory.js +30 -12
- package/lib/OptionsDefaulter.js +7 -3
- package/lib/Parser.js +137 -59
- package/lib/ParserHelpers.js +5 -2
- package/lib/ProgressPlugin.js +2 -2
- package/lib/RawModule.js +4 -2
- package/lib/RecordIdsPlugin.js +11 -7
- package/lib/RequestShortener.js +13 -6
- package/lib/RuleSet.js +39 -18
- package/lib/RuntimeTemplate.js +21 -10
- package/lib/SourceMapDevToolPlugin.js +4 -3
- package/lib/Stats.js +64 -28
- package/lib/Template.js +4 -2
- package/lib/TemplatedPathPlugin.js +6 -3
- package/lib/UmdMainTemplatePlugin.js +8 -3
- package/lib/WarnCaseSensitiveModulesPlugin.js +2 -1
- package/lib/Watching.js +3 -2
- package/lib/WebpackOptionsApply.js +32 -16
- package/lib/WebpackOptionsDefaulter.js +7 -4
- package/lib/WebpackOptionsValidationError.js +48 -19
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +17 -8
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +6 -3
- package/lib/dependencies/HarmonyDetectionParserPlugin.js +4 -2
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +7 -3
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +6 -3
- package/lib/dependencies/ImportParserPlugin.js +2 -1
- package/lib/dependencies/LoaderPlugin.js +12 -7
- package/lib/dependencies/LocalModulesHelpers.js +13 -6
- package/lib/dependencies/RequireContextPlugin.js +4 -2
- package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +8 -4
- package/lib/formatLocation.js +15 -7
- package/lib/node/NodeMainTemplateAsync.runtime.js +1 -1
- package/lib/node/NodeMainTemplatePlugin.js +6 -3
- package/lib/node/NodeSourcePlugin.js +9 -5
- package/lib/node/NodeWatchFileSystem.js +29 -12
- package/lib/optimize/AggressiveSplittingPlugin.js +12 -6
- package/lib/optimize/ConcatenatedModule.js +19 -8
- package/lib/optimize/MergeDuplicateChunksPlugin.js +6 -3
- package/lib/optimize/ModuleConcatenationPlugin.js +23 -10
- package/lib/optimize/OccurrenceOrderPlugin.js +11 -4
- package/lib/optimize/RemoveParentModulesPlugin.js +17 -7
- package/lib/optimize/SideEffectsFlagPlugin.js +3 -2
- package/lib/optimize/SplitChunksPlugin.js +33 -20
- package/lib/util/SortableSet.js +5 -2
- package/lib/util/StackedSetMap.js +12 -5
- package/lib/wasm/WasmMainTemplatePlugin.js +4 -2
- package/lib/wasm/WebAssemblyGenerator.js +7 -0
- package/lib/web/JsonpMainTemplate.runtime.js +2 -1
- package/lib/web/JsonpMainTemplatePlugin.js +2 -1
- package/lib/webpack.js +2 -1
- package/lib/webworker/WebWorkerMainTemplate.runtime.js +2 -1
- package/package.json +9 -9
@@ -17,22 +17,33 @@ class NodeWatchFileSystem {
|
|
17
17
|
}
|
18
18
|
|
19
19
|
watch(files, dirs, missing, startTime, options, callback, callbackUndelayed) {
|
20
|
-
if (!Array.isArray(files))
|
21
|
-
|
22
|
-
|
20
|
+
if (!Array.isArray(files)) {
|
21
|
+
throw new Error("Invalid arguments: 'files'");
|
22
|
+
}
|
23
|
+
if (!Array.isArray(dirs)) {
|
24
|
+
throw new Error("Invalid arguments: 'dirs'");
|
25
|
+
}
|
26
|
+
if (!Array.isArray(missing)) {
|
23
27
|
throw new Error("Invalid arguments: 'missing'");
|
24
|
-
|
28
|
+
}
|
29
|
+
if (typeof callback !== "function") {
|
25
30
|
throw new Error("Invalid arguments: 'callback'");
|
26
|
-
|
31
|
+
}
|
32
|
+
if (typeof startTime !== "number" && startTime) {
|
27
33
|
throw new Error("Invalid arguments: 'startTime'");
|
28
|
-
|
34
|
+
}
|
35
|
+
if (typeof options !== "object") {
|
29
36
|
throw new Error("Invalid arguments: 'options'");
|
30
|
-
|
37
|
+
}
|
38
|
+
if (typeof callbackUndelayed !== "function" && callbackUndelayed) {
|
31
39
|
throw new Error("Invalid arguments: 'callbackUndelayed'");
|
40
|
+
}
|
32
41
|
const oldWatcher = this.watcher;
|
33
42
|
this.watcher = new Watchpack(options);
|
34
43
|
|
35
|
-
if (callbackUndelayed)
|
44
|
+
if (callbackUndelayed) {
|
45
|
+
this.watcher.once("change", callbackUndelayed);
|
46
|
+
}
|
36
47
|
|
37
48
|
this.watcher.once("aggregated", (changes, removals) => {
|
38
49
|
changes = changes.concat(removals);
|
@@ -68,12 +79,18 @@ class NodeWatchFileSystem {
|
|
68
79
|
}
|
69
80
|
},
|
70
81
|
getFileTimestamps: () => {
|
71
|
-
if (this.watcher)
|
72
|
-
|
82
|
+
if (this.watcher) {
|
83
|
+
return objectToMap(this.watcher.getTimes());
|
84
|
+
} else {
|
85
|
+
return new Map();
|
86
|
+
}
|
73
87
|
},
|
74
88
|
getContextTimestamps: () => {
|
75
|
-
if (this.watcher)
|
76
|
-
|
89
|
+
if (this.watcher) {
|
90
|
+
return objectToMap(this.watcher.getTimes());
|
91
|
+
} else {
|
92
|
+
return new Map();
|
93
|
+
}
|
77
94
|
}
|
78
95
|
};
|
79
96
|
}
|
@@ -26,14 +26,18 @@ class AggressiveSplittingPlugin {
|
|
26
26
|
validateOptions(schema, options || {}, "Aggressive Splitting Plugin");
|
27
27
|
|
28
28
|
this.options = options || {};
|
29
|
-
if (typeof this.options.minSize !== "number")
|
29
|
+
if (typeof this.options.minSize !== "number") {
|
30
30
|
this.options.minSize = 30 * 1024;
|
31
|
-
|
31
|
+
}
|
32
|
+
if (typeof this.options.maxSize !== "number") {
|
32
33
|
this.options.maxSize = 50 * 1024;
|
33
|
-
|
34
|
+
}
|
35
|
+
if (typeof this.options.chunkOverhead !== "number") {
|
34
36
|
this.options.chunkOverhead = 0;
|
35
|
-
|
37
|
+
}
|
38
|
+
if (typeof this.options.entryChunkMultiplicator !== "number") {
|
36
39
|
this.options.entryChunkMultiplicator = 1;
|
40
|
+
}
|
37
41
|
}
|
38
42
|
apply(compiler) {
|
39
43
|
compiler.hooks.thisCompilation.tap(
|
@@ -82,8 +86,9 @@ class AggressiveSplittingPlugin {
|
|
82
86
|
|
83
87
|
const applySplit = splitData => {
|
84
88
|
// Cannot split if id is already taken
|
85
|
-
if (splitData.id !== undefined && usedIds.has(splitData.id))
|
89
|
+
if (splitData.id !== undefined && usedIds.has(splitData.id)) {
|
86
90
|
return false;
|
91
|
+
}
|
87
92
|
|
88
93
|
// Get module objects from names
|
89
94
|
const selectedModules = splitData.modules.map(name =>
|
@@ -188,8 +193,9 @@ class AggressiveSplittingPlugin {
|
|
188
193
|
for (let k = 0; k < modules.length; k++) {
|
189
194
|
const module = modules[k];
|
190
195
|
const newSize = selectedModulesSize + module.size();
|
191
|
-
if (newSize > maxSize && selectedModulesSize >= minSize)
|
196
|
+
if (newSize > maxSize && selectedModulesSize >= minSize) {
|
192
197
|
break;
|
198
|
+
}
|
193
199
|
selectedModulesSize = newSize;
|
194
200
|
selectedModules.push(module);
|
195
201
|
}
|
@@ -114,20 +114,22 @@ const getFinalName = (
|
|
114
114
|
case "concatenated": {
|
115
115
|
const directExport = info.exportMap.get(exportName);
|
116
116
|
if (directExport) {
|
117
|
-
if (exportName === true)
|
117
|
+
if (exportName === true) {
|
118
118
|
ensureNsObjSource(
|
119
119
|
info,
|
120
120
|
moduleToInfoMap,
|
121
121
|
requestShortener,
|
122
122
|
strictHarmonyModule
|
123
123
|
);
|
124
|
+
}
|
124
125
|
const name = info.internalNames.get(directExport);
|
125
|
-
if (!name)
|
126
|
+
if (!name) {
|
126
127
|
throw new Error(
|
127
128
|
`The export "${directExport}" in "${info.module.readableIdentifier(
|
128
129
|
requestShortener
|
129
130
|
)}" has no internal name`
|
130
131
|
);
|
132
|
+
}
|
131
133
|
return name;
|
132
134
|
}
|
133
135
|
const reexport = info.reexportMap.get(exportName);
|
@@ -325,13 +327,18 @@ class ConcatenatedModule extends Module {
|
|
325
327
|
}
|
326
328
|
}
|
327
329
|
// populate warnings
|
328
|
-
for (const warning of m.warnings)
|
330
|
+
for (const warning of m.warnings) {
|
331
|
+
this.warnings.push(warning);
|
332
|
+
}
|
329
333
|
// populate errors
|
330
|
-
for (const error of m.errors)
|
334
|
+
for (const error of m.errors) {
|
335
|
+
this.errors.push(error);
|
336
|
+
}
|
331
337
|
|
332
338
|
if (m.buildInfo.assets) {
|
333
|
-
if (this.buildInfo.assets === undefined)
|
339
|
+
if (this.buildInfo.assets === undefined) {
|
334
340
|
this.buildInfo.assets = Object.create(null);
|
341
|
+
}
|
335
342
|
Object.assign(this.buildInfo.assets, m.buildInfo.assets);
|
336
343
|
}
|
337
344
|
}
|
@@ -450,10 +457,13 @@ class ConcatenatedModule extends Module {
|
|
450
457
|
const reexportMap = new Map();
|
451
458
|
for (const dep of info.module.dependencies) {
|
452
459
|
if (dep instanceof HarmonyExportSpecifierDependency) {
|
453
|
-
if (!exportMap.has(dep.name))
|
460
|
+
if (!exportMap.has(dep.name)) {
|
461
|
+
exportMap.set(dep.name, dep.id);
|
462
|
+
}
|
454
463
|
} else if (dep instanceof HarmonyExportExpressionDependency) {
|
455
|
-
if (!exportMap.has("default"))
|
464
|
+
if (!exportMap.has("default")) {
|
456
465
|
exportMap.set("default", "__WEBPACK_MODULE_DEFAULT_EXPORT__");
|
466
|
+
}
|
457
467
|
} else if (
|
458
468
|
dep instanceof HarmonyExportImportedSpecifierDependency
|
459
469
|
) {
|
@@ -478,8 +488,9 @@ class ConcatenatedModule extends Module {
|
|
478
488
|
}
|
479
489
|
} else if (importedModule) {
|
480
490
|
for (const name of importedModule.buildMeta.providedExports) {
|
481
|
-
if (dep.activeExports.has(name) || name === "default")
|
491
|
+
if (dep.activeExports.has(name) || name === "default") {
|
482
492
|
continue;
|
493
|
+
}
|
483
494
|
if (!reexportMap.has(name)) {
|
484
495
|
reexportMap.set(name, {
|
485
496
|
module: importedModule,
|
@@ -31,8 +31,9 @@ class MergeDuplicateChunksPlugin {
|
|
31
31
|
!notDuplicates.has(dup)
|
32
32
|
) {
|
33
33
|
// delay allocating the new Set until here, reduce memory pressure
|
34
|
-
if (possibleDuplicates === undefined)
|
34
|
+
if (possibleDuplicates === undefined) {
|
35
35
|
possibleDuplicates = new Set();
|
36
|
+
}
|
36
37
|
possibleDuplicates.add(dup);
|
37
38
|
}
|
38
39
|
}
|
@@ -42,8 +43,9 @@ class MergeDuplicateChunksPlugin {
|
|
42
43
|
// validate existing possible duplicates
|
43
44
|
for (const dup of possibleDuplicates) {
|
44
45
|
// remove possible duplicate when module is not contained
|
45
|
-
if (!dup.containsModule(module))
|
46
|
+
if (!dup.containsModule(module)) {
|
46
47
|
possibleDuplicates.delete(dup);
|
48
|
+
}
|
47
49
|
}
|
48
50
|
// when all chunks has been removed we can break here
|
49
51
|
if (possibleDuplicates.size === 0) break;
|
@@ -58,8 +60,9 @@ class MergeDuplicateChunksPlugin {
|
|
58
60
|
for (const otherChunk of possibleDuplicates) {
|
59
61
|
if (otherChunk.hasRuntime() !== chunk.hasRuntime()) continue;
|
60
62
|
// merge them
|
61
|
-
if (chunk.integrate(otherChunk, "duplicate"))
|
63
|
+
if (chunk.integrate(otherChunk, "duplicate")) {
|
62
64
|
chunks.splice(chunks.indexOf(otherChunk), 1);
|
65
|
+
}
|
63
66
|
}
|
64
67
|
}
|
65
68
|
|
@@ -172,19 +172,21 @@ class ModuleConcatenationPlugin {
|
|
172
172
|
)
|
173
173
|
.sort();
|
174
174
|
const explanations = Array.from(importingExplanations).sort();
|
175
|
-
if (names.length > 0 && explanations.length === 0)
|
175
|
+
if (names.length > 0 && explanations.length === 0) {
|
176
176
|
return `Module is referenced from these modules with unsupported syntax: ${names.join(
|
177
177
|
", "
|
178
178
|
)}`;
|
179
|
-
else if (names.length === 0 && explanations.length > 0)
|
179
|
+
} else if (names.length === 0 && explanations.length > 0) {
|
180
180
|
return `Module is referenced by: ${explanations.join(
|
181
181
|
", "
|
182
182
|
)}`;
|
183
|
-
else if (names.length > 0 && explanations.length > 0)
|
183
|
+
} else if (names.length > 0 && explanations.length > 0) {
|
184
184
|
return `Module is referenced from these modules with unsupported syntax: ${names.join(
|
185
185
|
", "
|
186
186
|
)} and by: ${explanations.join(", ")}`;
|
187
|
-
else
|
187
|
+
} else {
|
188
|
+
return "Module is referenced in a unsupported way";
|
189
|
+
}
|
188
190
|
});
|
189
191
|
continue;
|
190
192
|
}
|
@@ -226,8 +228,9 @@ class ModuleConcatenationPlugin {
|
|
226
228
|
if (!currentConfiguration.isEmpty()) {
|
227
229
|
concatConfigurations.push(currentConfiguration);
|
228
230
|
for (const module of currentConfiguration.getModules()) {
|
229
|
-
if (module !== currentConfiguration.rootModule)
|
231
|
+
if (module !== currentConfiguration.rootModule) {
|
230
232
|
usedAsInner.add(module);
|
233
|
+
}
|
231
234
|
}
|
232
235
|
}
|
233
236
|
}
|
@@ -250,13 +253,13 @@ class ModuleConcatenationPlugin {
|
|
250
253
|
newModule.optimizationBailout.push(requestShortener => {
|
251
254
|
const reason = getBailoutReason(warning[0], requestShortener);
|
252
255
|
const reasonWithPrefix = reason ? ` (<- ${reason})` : "";
|
253
|
-
if (warning[0] === warning[1])
|
256
|
+
if (warning[0] === warning[1]) {
|
254
257
|
return formatBailoutReason(
|
255
258
|
`Cannot concat with ${warning[0].readableIdentifier(
|
256
259
|
requestShortener
|
257
260
|
)}${reasonWithPrefix}`
|
258
261
|
);
|
259
|
-
else
|
262
|
+
} else {
|
260
263
|
return formatBailoutReason(
|
261
264
|
`Cannot concat with ${warning[0].readableIdentifier(
|
262
265
|
requestShortener
|
@@ -264,6 +267,7 @@ class ModuleConcatenationPlugin {
|
|
264
267
|
requestShortener
|
265
268
|
)}${reasonWithPrefix}`
|
266
269
|
);
|
270
|
+
}
|
267
271
|
});
|
268
272
|
}
|
269
273
|
const chunks = concatConfiguration.rootModule.getChunks();
|
@@ -276,12 +280,19 @@ class ModuleConcatenationPlugin {
|
|
276
280
|
for (const chunk of chunks) {
|
277
281
|
chunk.addModule(newModule);
|
278
282
|
newModule.addChunk(chunk);
|
279
|
-
if (chunk.entryModule === concatConfiguration.rootModule)
|
283
|
+
if (chunk.entryModule === concatConfiguration.rootModule) {
|
280
284
|
chunk.entryModule = newModule;
|
285
|
+
}
|
281
286
|
}
|
282
287
|
compilation.modules.push(newModule);
|
283
288
|
for (const reason of newModule.reasons) {
|
284
|
-
reason.dependency.module
|
289
|
+
if (reason.dependency.module === concatConfiguration.rootModule)
|
290
|
+
reason.dependency.module = newModule;
|
291
|
+
if (
|
292
|
+
reason.dependency.redirectedModule ===
|
293
|
+
concatConfiguration.rootModule
|
294
|
+
)
|
295
|
+
reason.dependency.redirectedModule = newModule;
|
285
296
|
}
|
286
297
|
// TODO: remove when LTS node version contains fixed v8 version
|
287
298
|
// @see https://github.com/webpack/webpack/pull/6613
|
@@ -293,7 +304,9 @@ class ModuleConcatenationPlugin {
|
|
293
304
|
let reasons = dep.module.reasons;
|
294
305
|
for (let j = 0; j < reasons.length; j++) {
|
295
306
|
let reason = reasons[j];
|
296
|
-
if (reason.dependency === dep)
|
307
|
+
if (reason.dependency === dep) {
|
308
|
+
reason.module = newModule;
|
309
|
+
}
|
297
310
|
}
|
298
311
|
}
|
299
312
|
}
|
@@ -36,15 +36,22 @@ class OccurrenceOrderPlugin {
|
|
36
36
|
}
|
37
37
|
|
38
38
|
const countOccursInEntry = (sum, r) => {
|
39
|
-
if (!r.module)
|
39
|
+
if (!r.module) {
|
40
|
+
return sum;
|
41
|
+
}
|
40
42
|
return sum + initialChunkChunkMap.get(r.module);
|
41
43
|
};
|
42
44
|
const countOccurs = (sum, r) => {
|
43
|
-
if (!r.module)
|
45
|
+
if (!r.module) {
|
46
|
+
return sum;
|
47
|
+
}
|
44
48
|
let factor = 1;
|
45
|
-
if (typeof r.dependency.getNumberOfIdOccurrences === "function")
|
49
|
+
if (typeof r.dependency.getNumberOfIdOccurrences === "function") {
|
46
50
|
factor = r.dependency.getNumberOfIdOccurrences();
|
47
|
-
|
51
|
+
}
|
52
|
+
if (factor === 0) {
|
53
|
+
return sum;
|
54
|
+
}
|
48
55
|
return sum + factor * r.module.getNumberOfChunks();
|
49
56
|
};
|
50
57
|
|
@@ -34,7 +34,9 @@ class RemoveParentModulesPlugin {
|
|
34
34
|
for (const chunkGroup of compilation.entrypoints.values()) {
|
35
35
|
// initialize available modules for chunks without parents
|
36
36
|
availableModulesMap.set(chunkGroup, new Set());
|
37
|
-
for (const child of chunkGroup.childrenIterable)
|
37
|
+
for (const child of chunkGroup.childrenIterable) {
|
38
|
+
queue.enqueue(child);
|
39
|
+
}
|
38
40
|
}
|
39
41
|
|
40
42
|
while (queue.length > 0) {
|
@@ -49,8 +51,9 @@ class RemoveParentModulesPlugin {
|
|
49
51
|
// if we have not own info yet: create new entry
|
50
52
|
availableModules = new Set(availableModulesInParent);
|
51
53
|
for (const chunk of parent.chunks) {
|
52
|
-
for (const m of chunk.modulesIterable)
|
54
|
+
for (const m of chunk.modulesIterable) {
|
53
55
|
availableModules.add(m);
|
56
|
+
}
|
54
57
|
}
|
55
58
|
availableModulesMap.set(chunkGroup, availableModules);
|
56
59
|
changed = true;
|
@@ -69,8 +72,9 @@ class RemoveParentModulesPlugin {
|
|
69
72
|
}
|
70
73
|
if (changed) {
|
71
74
|
// if something changed: enqueue our children
|
72
|
-
for (const child of chunkGroup.childrenIterable)
|
75
|
+
for (const child of chunkGroup.childrenIterable) {
|
73
76
|
queue.enqueue(child);
|
77
|
+
}
|
74
78
|
}
|
75
79
|
}
|
76
80
|
|
@@ -88,11 +92,17 @@ class RemoveParentModulesPlugin {
|
|
88
92
|
const numberOfModules = chunk.getNumberOfModules();
|
89
93
|
const toRemove = new Set();
|
90
94
|
if (numberOfModules < availableModules.size) {
|
91
|
-
for (const m of chunk.modulesIterable)
|
92
|
-
if (availableModules.has(m))
|
95
|
+
for (const m of chunk.modulesIterable) {
|
96
|
+
if (availableModules.has(m)) {
|
97
|
+
toRemove.add(m);
|
98
|
+
}
|
99
|
+
}
|
93
100
|
} else {
|
94
|
-
for (const m of availableModules)
|
95
|
-
if (chunk.containsModule(m))
|
101
|
+
for (const m of availableModules) {
|
102
|
+
if (chunk.containsModule(m)) {
|
103
|
+
toRemove.add(m);
|
104
|
+
}
|
105
|
+
}
|
96
106
|
}
|
97
107
|
for (const module of toRemove) {
|
98
108
|
module.rewriteChunkInReasons(
|
@@ -41,10 +41,11 @@ class SideEffectsFlagPlugin {
|
|
41
41
|
return module;
|
42
42
|
});
|
43
43
|
nmf.hooks.module.tap("SideEffectsFlagPlugin", (module, data) => {
|
44
|
-
if (data.settings.sideEffects === false)
|
44
|
+
if (data.settings.sideEffects === false) {
|
45
45
|
module.factoryMeta.sideEffectFree = true;
|
46
|
-
else if (data.settings.sideEffects === true)
|
46
|
+
} else if (data.settings.sideEffects === true) {
|
47
47
|
module.factoryMeta.sideEffectFree = false;
|
48
|
+
}
|
48
49
|
});
|
49
50
|
});
|
50
51
|
compiler.hooks.compilation.tap("SideEffectsFlagPlugin", compilation => {
|
@@ -36,7 +36,9 @@ const getRequests = chunk => {
|
|
36
36
|
|
37
37
|
const getModulesSize = modules => {
|
38
38
|
let sum = 0;
|
39
|
-
for (const m of modules)
|
39
|
+
for (const m of modules) {
|
40
|
+
sum += m.size();
|
41
|
+
}
|
40
42
|
return sum;
|
41
43
|
};
|
42
44
|
|
@@ -172,8 +174,9 @@ module.exports = class SplitChunksPlugin {
|
|
172
174
|
static normalizeCacheGroups({ cacheGroups, automaticNameDelimiter }) {
|
173
175
|
if (typeof cacheGroups === "function") {
|
174
176
|
// TODO webpack 5 remove this
|
175
|
-
if (cacheGroups.length !== 1)
|
177
|
+
if (cacheGroups.length !== 1) {
|
176
178
|
return module => cacheGroups(module, module.getChunks());
|
179
|
+
}
|
177
180
|
return cacheGroups;
|
178
181
|
}
|
179
182
|
if (cacheGroups && typeof cacheGroups === "object") {
|
@@ -192,12 +195,7 @@ module.exports = class SplitChunksPlugin {
|
|
192
195
|
if (result) {
|
193
196
|
if (results === undefined) results = [];
|
194
197
|
for (const r of Array.isArray(result) ? result : [result]) {
|
195
|
-
const result = Object.assign(
|
196
|
-
{
|
197
|
-
key
|
198
|
-
},
|
199
|
-
r
|
200
|
-
);
|
198
|
+
const result = Object.assign({ key }, r);
|
201
199
|
if (result.name) result.getName = () => result.name;
|
202
200
|
if (result.chunks) {
|
203
201
|
result.chunksFilter = SplitChunksPlugin.normalizeChunksFilter(
|
@@ -240,23 +238,34 @@ module.exports = class SplitChunksPlugin {
|
|
240
238
|
static checkTest(test, module) {
|
241
239
|
if (test === undefined) return true;
|
242
240
|
if (typeof test === "function") {
|
243
|
-
if (test.length !== 1)
|
241
|
+
if (test.length !== 1) {
|
242
|
+
return test(module, module.getChunks());
|
243
|
+
}
|
244
244
|
return test(module);
|
245
245
|
}
|
246
246
|
if (typeof test === "boolean") return test;
|
247
247
|
if (typeof test === "string") {
|
248
|
-
if (
|
248
|
+
if (
|
249
|
+
module.nameForCondition &&
|
250
|
+
module.nameForCondition().startsWith(test)
|
251
|
+
) {
|
249
252
|
return true;
|
253
|
+
}
|
250
254
|
for (const chunk of module.chunksIterable) {
|
251
|
-
if (chunk.name && chunk.name.startsWith(test))
|
255
|
+
if (chunk.name && chunk.name.startsWith(test)) {
|
256
|
+
return true;
|
257
|
+
}
|
252
258
|
}
|
253
259
|
return false;
|
254
260
|
}
|
255
261
|
if (test instanceof RegExp) {
|
256
|
-
if (module.nameForCondition && test.test(module.nameForCondition()))
|
262
|
+
if (module.nameForCondition && test.test(module.nameForCondition())) {
|
257
263
|
return true;
|
264
|
+
}
|
258
265
|
for (const chunk of module.chunksIterable) {
|
259
|
-
if (chunk.name && test.test(chunk.name))
|
266
|
+
if (chunk.name && test.test(chunk.name)) {
|
267
|
+
return true;
|
268
|
+
}
|
260
269
|
}
|
261
270
|
return false;
|
262
271
|
}
|
@@ -447,8 +456,9 @@ module.exports = class SplitChunksPlugin {
|
|
447
456
|
for (const module of compilation.modules) {
|
448
457
|
// Get cache group
|
449
458
|
let cacheGroups = this.options.getCacheGroups(module);
|
450
|
-
if (!Array.isArray(cacheGroups) || cacheGroups.length === 0)
|
459
|
+
if (!Array.isArray(cacheGroups) || cacheGroups.length === 0) {
|
451
460
|
continue;
|
461
|
+
}
|
452
462
|
|
453
463
|
// Prepare some values
|
454
464
|
const chunksKey = getKey(module.chunksIterable);
|
@@ -555,18 +565,20 @@ module.exports = class SplitChunksPlugin {
|
|
555
565
|
if (pair[1] === item.modules.size) {
|
556
566
|
const chunk = pair[0];
|
557
567
|
if (chunk.hasEntryModule()) continue;
|
558
|
-
if (!newChunk || !newChunk.name)
|
559
|
-
|
568
|
+
if (!newChunk || !newChunk.name) {
|
569
|
+
newChunk = chunk;
|
570
|
+
} else if (
|
560
571
|
chunk.name &&
|
561
572
|
chunk.name.length < newChunk.name.length
|
562
|
-
)
|
573
|
+
) {
|
563
574
|
newChunk = chunk;
|
564
|
-
else if (
|
575
|
+
} else if (
|
565
576
|
chunk.name &&
|
566
577
|
chunk.name.length === newChunk.name.length &&
|
567
578
|
chunk.name < newChunk.name
|
568
|
-
)
|
579
|
+
) {
|
569
580
|
newChunk = chunk;
|
581
|
+
}
|
570
582
|
chunkName = undefined;
|
571
583
|
isReused = true;
|
572
584
|
}
|
@@ -683,8 +695,9 @@ module.exports = class SplitChunksPlugin {
|
|
683
695
|
}
|
684
696
|
if (info.modules.size !== oldSize) {
|
685
697
|
info.size = getModulesSize(info.modules);
|
686
|
-
if (info.size < info.cacheGroup.minSize)
|
698
|
+
if (info.size < info.cacheGroup.minSize) {
|
687
699
|
chunksInfoMap.delete(key);
|
700
|
+
}
|
688
701
|
}
|
689
702
|
}
|
690
703
|
}
|
package/lib/util/SortableSet.js
CHANGED
@@ -94,12 +94,15 @@ class SortableSet extends Set {
|
|
94
94
|
}
|
95
95
|
|
96
96
|
_invalidateCache() {
|
97
|
-
if (this._cache !== undefined)
|
97
|
+
if (this._cache !== undefined) {
|
98
|
+
this._cache.clear();
|
99
|
+
}
|
98
100
|
}
|
99
101
|
|
100
102
|
_invalidateOrderedCache() {
|
101
|
-
if (this._cacheOrderIndependent !== undefined)
|
103
|
+
if (this._cacheOrderIndependent !== undefined) {
|
102
104
|
this._cacheOrderIndependent.clear();
|
105
|
+
}
|
103
106
|
}
|
104
107
|
}
|
105
108
|
|
@@ -25,8 +25,11 @@ class StackedSetMap {
|
|
25
25
|
}
|
26
26
|
|
27
27
|
delete(item) {
|
28
|
-
if (this.stack.length > 1)
|
29
|
-
|
28
|
+
if (this.stack.length > 1) {
|
29
|
+
this.map.set(item, TOMBSTONE);
|
30
|
+
} else {
|
31
|
+
this.map.delete(item);
|
32
|
+
}
|
30
33
|
}
|
31
34
|
|
32
35
|
has(item) {
|
@@ -47,10 +50,11 @@ class StackedSetMap {
|
|
47
50
|
|
48
51
|
get(item) {
|
49
52
|
const topValue = this.map.get(item);
|
50
|
-
if (topValue !== undefined)
|
53
|
+
if (topValue !== undefined) {
|
51
54
|
return topValue === TOMBSTONE || topValue === UNDEFINED_MARKER
|
52
55
|
? undefined
|
53
56
|
: topValue;
|
57
|
+
}
|
54
58
|
if (this.stack.length > 1) {
|
55
59
|
for (var i = this.stack.length - 2; i >= 0; i--) {
|
56
60
|
const value = this.stack[i].get(item);
|
@@ -71,8 +75,11 @@ class StackedSetMap {
|
|
71
75
|
this.map = new Map();
|
72
76
|
for (const data of this.stack) {
|
73
77
|
for (const pair of data) {
|
74
|
-
if (pair[1] === TOMBSTONE)
|
75
|
-
|
78
|
+
if (pair[1] === TOMBSTONE) {
|
79
|
+
this.map.delete(pair[0]);
|
80
|
+
} else {
|
81
|
+
this.map.set(pair[0], pair[1]);
|
82
|
+
}
|
76
83
|
}
|
77
84
|
}
|
78
85
|
this.stack = [this.map];
|
@@ -179,10 +179,11 @@ class WasmMainTemplatePlugin {
|
|
179
179
|
hashWithLength(length) {
|
180
180
|
const shortChunkHashMap = Object.create(null);
|
181
181
|
for (const wasmModuleId of Object.keys(chunkModuleMaps.hash)) {
|
182
|
-
if (typeof chunkModuleMaps.hash[wasmModuleId] === "string")
|
182
|
+
if (typeof chunkModuleMaps.hash[wasmModuleId] === "string") {
|
183
183
|
shortChunkHashMap[wasmModuleId] = chunkModuleMaps.hash[
|
184
184
|
wasmModuleId
|
185
185
|
].substr(0, length);
|
186
|
+
}
|
186
187
|
}
|
187
188
|
return `" + ${JSON.stringify(
|
188
189
|
shortChunkHashMap
|
@@ -274,8 +275,9 @@ class WasmMainTemplatePlugin {
|
|
274
275
|
mainTemplate.hooks.requireExtensions.tap(
|
275
276
|
"WasmMainTemplatePlugin",
|
276
277
|
(source, chunk) => {
|
277
|
-
if (!chunk.hasModuleInGraph(m => m.type.startsWith("webassembly")))
|
278
|
+
if (!chunk.hasModuleInGraph(m => m.type.startsWith("webassembly"))) {
|
278
279
|
return source;
|
280
|
+
}
|
279
281
|
return Template.asString([
|
280
282
|
source,
|
281
283
|
"",
|
@@ -207,6 +207,13 @@ const rewriteImportedGlobals = state => bin => {
|
|
207
207
|
|
208
208
|
path.remove();
|
209
209
|
}
|
210
|
+
},
|
211
|
+
|
212
|
+
// in order to preserve non-imported global's order we need to re-inject
|
213
|
+
// those as well
|
214
|
+
Global(path) {
|
215
|
+
newGlobals.push(path.node);
|
216
|
+
path.remove();
|
210
217
|
}
|
211
218
|
});
|
212
219
|
|
@@ -24,8 +24,9 @@ module.exports = function() {
|
|
24
24
|
function hotDownloadManifest(requestTimeout) {
|
25
25
|
requestTimeout = requestTimeout || 10000;
|
26
26
|
return new Promise(function(resolve, reject) {
|
27
|
-
if (typeof XMLHttpRequest === "undefined")
|
27
|
+
if (typeof XMLHttpRequest === "undefined") {
|
28
28
|
return reject(new Error("No browser support"));
|
29
|
+
}
|
29
30
|
try {
|
30
31
|
var request = new XMLHttpRequest();
|
31
32
|
var requestPath = $require$.p + $hotMainFilename$;
|
@@ -66,11 +66,12 @@ class JsonpMainTemplatePlugin {
|
|
66
66
|
hashWithLength(length) {
|
67
67
|
const shortChunkHashMap = Object.create(null);
|
68
68
|
for (const chunkId of Object.keys(chunkMaps.hash)) {
|
69
|
-
if (typeof chunkMaps.hash[chunkId] === "string")
|
69
|
+
if (typeof chunkMaps.hash[chunkId] === "string") {
|
70
70
|
shortChunkHashMap[chunkId] = chunkMaps.hash[chunkId].substr(
|
71
71
|
0,
|
72
72
|
length
|
73
73
|
);
|
74
|
+
}
|
74
75
|
}
|
75
76
|
return `" + ${JSON.stringify(
|
76
77
|
shortChunkHashMap
|
package/lib/webpack.js
CHANGED
@@ -44,8 +44,9 @@ const webpack = (options, callback) => {
|
|
44
44
|
throw new Error("Invalid argument: options");
|
45
45
|
}
|
46
46
|
if (callback) {
|
47
|
-
if (typeof callback !== "function")
|
47
|
+
if (typeof callback !== "function") {
|
48
48
|
throw new Error("Invalid argument: callback");
|
49
|
+
}
|
49
50
|
if (
|
50
51
|
options.watch === true ||
|
51
52
|
(Array.isArray(options) && options.some(o => o.watch))
|