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.
- package/README.md +719 -721
- package/bin/webpack.js +69 -10
- package/lib/APIPlugin.js +84 -84
- package/lib/AmdMainTemplatePlugin.js +75 -77
- package/lib/AsyncDependencyToInitialChunkError.js +21 -23
- package/lib/BannerPlugin.js +101 -101
- package/lib/Chunk.js +477 -469
- package/lib/ChunkTemplate.js +51 -53
- package/lib/Compilation.js +1858 -1851
- package/lib/Compiler.js +493 -478
- package/lib/ConcurrentCompilationError.js +19 -0
- package/lib/ContextModule.js +696 -685
- package/lib/ContextModuleFactory.js +245 -243
- package/lib/DefinePlugin.js +197 -197
- package/lib/DelegatedModule.js +101 -101
- package/lib/DependenciesBlockVariable.js +51 -52
- package/lib/Dependency.js +53 -52
- package/lib/DllModule.js +54 -54
- package/lib/DllModuleFactory.js +29 -29
- package/lib/EnvironmentPlugin.js +65 -67
- package/lib/EvalDevToolModuleTemplatePlugin.js +60 -60
- package/lib/EvalSourceMapDevToolModuleTemplatePlugin.js +105 -105
- package/lib/ExportPropertyMainTemplatePlugin.js +40 -40
- package/lib/ExternalModule.js +159 -159
- package/lib/FunctionModuleTemplatePlugin.js +98 -98
- package/lib/HotModuleReplacement.runtime.js +631 -631
- package/lib/HotModuleReplacementPlugin.js +407 -406
- package/lib/HotUpdateChunkTemplate.js +78 -80
- package/lib/JavascriptGenerator.js +228 -229
- package/lib/JavascriptModulesPlugin.js +184 -158
- package/lib/JsonGenerator.js +42 -42
- package/lib/MainTemplate.js +406 -402
- package/lib/Module.js +343 -340
- package/lib/ModuleBuildError.js +42 -42
- package/lib/ModuleError.js +28 -28
- package/lib/ModuleFilenameHelpers.js +166 -166
- package/lib/ModuleTemplate.js +77 -79
- package/lib/ModuleWarning.js +30 -30
- package/lib/MultiCompiler.js +271 -259
- package/lib/MultiModule.js +78 -75
- package/lib/MultiModuleFactory.js +23 -23
- package/lib/MultiWatching.js +38 -37
- package/lib/NoModeWarning.js +23 -21
- package/lib/NormalModule.js +478 -470
- package/lib/NormalModuleFactory.js +483 -481
- package/lib/OptionsDefaulter.js +80 -86
- package/lib/Parser.js +2074 -2071
- package/lib/ProgressPlugin.js +231 -231
- package/lib/RawModule.js +54 -55
- package/lib/RecordIdsPlugin.js +160 -160
- package/lib/RemovedPluginError.js +13 -13
- package/lib/ResolverFactory.js +64 -67
- package/lib/RuntimeTemplate.js +267 -297
- package/lib/SetVarMainTemplatePlugin.js +57 -57
- package/lib/SourceMapDevToolPlugin.js +302 -308
- package/lib/Stats.js +1234 -1212
- package/lib/Template.js +205 -205
- package/lib/TemplatedPathPlugin.js +170 -143
- package/lib/UmdMainTemplatePlugin.js +264 -269
- package/lib/Watching.js +193 -193
- package/lib/WebAssemblyParser.js +50 -54
- package/lib/WebpackOptionsApply.js +401 -401
- package/lib/WebpackOptionsDefaulter.js +337 -317
- package/lib/WebpackOptionsValidationError.js +316 -319
- package/lib/debug/ProfilingPlugin.js +409 -405
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +328 -311
- package/lib/dependencies/AMDRequireContextDependency.js +20 -20
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +270 -241
- package/lib/dependencies/HarmonyAcceptImportDependency.js +23 -23
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +620 -606
- package/lib/dependencies/HarmonyExportSpecifierDependency.js +53 -53
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +214 -214
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +154 -156
- package/lib/dependencies/ImportDependenciesBlock.js +17 -17
- package/lib/dependencies/ImportDependency.js +34 -34
- package/lib/dependencies/ImportEagerDependency.js +32 -32
- package/lib/dependencies/ImportParserPlugin.js +175 -179
- package/lib/dependencies/ImportWeakDependency.js +34 -34
- package/lib/dependencies/JsonExportsDependency.js +25 -25
- package/lib/dependencies/ModuleDependency.js +20 -20
- package/lib/dependencies/NullDependency.js +20 -20
- package/lib/dependencies/RequireContextDependency.js +22 -22
- package/lib/dependencies/RequireIncludeDependency.js +40 -40
- package/lib/dependencies/WebpackMissingModule.js +20 -22
- package/lib/node/NodeChunkTemplatePlugin.js +31 -31
- package/lib/node/NodeHotUpdateChunkTemplatePlugin.js +36 -36
- package/lib/node/NodeMainTemplatePlugin.js +320 -273
- package/lib/node/ReadFileCompileWasmMainTemplatePlugin.js +113 -115
- package/lib/optimize/AggressiveSplittingPlugin.js +281 -281
- package/lib/optimize/ConcatenatedModule.js +1364 -1366
- package/lib/optimize/RemoveParentModulesPlugin.js +114 -114
- package/lib/optimize/SplitChunksPlugin.js +519 -491
- package/lib/performance/SizeLimitsPlugin.js +105 -105
- package/lib/util/TrackingSet.js +35 -35
- package/lib/util/objectToMap.js +10 -10
- package/lib/wasm/WasmModuleTemplatePlugin.js +106 -106
- package/lib/web/JsonpChunkTemplatePlugin.js +47 -47
- package/lib/web/JsonpExportMainTemplatePlugin.js +47 -47
- package/lib/web/JsonpHotUpdateChunkTemplatePlugin.js +39 -39
- package/lib/web/JsonpMainTemplatePlugin.js +425 -403
- package/lib/webpack.js +182 -179
- package/lib/webworker/WebWorkerChunkTemplatePlugin.js +35 -35
- package/lib/webworker/WebWorkerHotUpdateChunkTemplatePlugin.js +40 -40
- package/lib/webworker/WebWorkerMainTemplatePlugin.js +177 -154
- package/package.json +9 -8
- package/schemas/WebpackOptions.json +1973 -1951
- package/schemas/ajv.absolutePath.js +55 -29
- package/schemas/plugins/BannerPlugin.json +85 -85
- package/schemas/plugins/DllPlugin.json +28 -28
- package/schemas/plugins/DllReferencePlugin.json +99 -99
- package/schemas/plugins/HashedModuleIdsPlugin.json +24 -24
- package/schemas/plugins/LoaderOptionsPlugin.json +26 -26
- package/schemas/plugins/SourceMapDevToolPlugin.json +187 -187
- package/schemas/plugins/WatchIgnorePlugin.json +16 -16
- package/schemas/plugins/debug/ProfilingPlugin.json +12 -12
- package/schemas/plugins/optimize/AggressiveSplittingPlugin.json +22 -22
- package/schemas/plugins/optimize/LimitChunkCountPlugin.json +15 -15
- package/schemas/plugins/optimize/MinChunkSizePlugin.json +13 -13
package/lib/Chunk.js
CHANGED
@@ -1,469 +1,477 @@
|
|
1
|
-
/*
|
2
|
-
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
-
Author Tobias Koppers @sokra
|
4
|
-
*/
|
5
|
-
"use strict";
|
6
|
-
|
7
|
-
const util = require("util");
|
8
|
-
const SortableSet = require("./util/SortableSet");
|
9
|
-
const GraphHelpers = require("./GraphHelpers");
|
10
|
-
let debugId = 1000;
|
11
|
-
const ERR_CHUNK_ENTRY = "Chunk.entry was removed. Use hasRuntime()";
|
12
|
-
const ERR_CHUNK_INITIAL =
|
13
|
-
"Chunk.initial was removed. Use canBeInitial/isOnlyInitial()";
|
14
|
-
|
15
|
-
const sortById = (a, b) => {
|
16
|
-
if (a.id < b.id) return -1;
|
17
|
-
if (b.id < a.id) return 1;
|
18
|
-
return 0;
|
19
|
-
};
|
20
|
-
|
21
|
-
const sortByIdentifier = (a, b) => {
|
22
|
-
if (a.identifier() > b.identifier()) return 1;
|
23
|
-
if (a.identifier() < b.identifier()) return -1;
|
24
|
-
return 0;
|
25
|
-
};
|
26
|
-
|
27
|
-
const getModulesIdent = set => {
|
28
|
-
set.sort();
|
29
|
-
let str = "";
|
30
|
-
for (const m of set) {
|
31
|
-
str += m.identifier() + "#";
|
32
|
-
}
|
33
|
-
return str;
|
34
|
-
};
|
35
|
-
|
36
|
-
const getArray = set => Array.from(set);
|
37
|
-
|
38
|
-
const getModulesSize = set => {
|
39
|
-
let count = 0;
|
40
|
-
for (const module of set) {
|
41
|
-
count += module.size();
|
42
|
-
}
|
43
|
-
return count;
|
44
|
-
};
|
45
|
-
|
46
|
-
class Chunk {
|
47
|
-
constructor(name) {
|
48
|
-
this.id = null;
|
49
|
-
this.ids = null;
|
50
|
-
this.debugId = debugId++;
|
51
|
-
this.name = name;
|
52
|
-
this.entryModule = undefined;
|
53
|
-
this._modules = new SortableSet(undefined, sortByIdentifier);
|
54
|
-
this._groups = new SortableSet(undefined, sortById);
|
55
|
-
this.files = [];
|
56
|
-
this.rendered = false;
|
57
|
-
this.hash = undefined;
|
58
|
-
this.
|
59
|
-
this.
|
60
|
-
this.
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
this._groups.
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
this._groups.
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
if (this._modules.size
|
163
|
-
|
164
|
-
const
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
const
|
169
|
-
|
170
|
-
|
171
|
-
const
|
172
|
-
|
173
|
-
if (aModuleIdentifier
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
//
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
GraphHelpers.
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
hash.update(this.
|
250
|
-
hash.update(
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
if (
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
return
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
if
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
const
|
325
|
-
const
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
const
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
this._modules.
|
412
|
-
}
|
413
|
-
}
|
414
|
-
|
415
|
-
// TODO remove in webpack 5
|
416
|
-
Object.defineProperty(Chunk.prototype, "
|
417
|
-
configurable: false,
|
418
|
-
value: util.deprecate(function(fn) {
|
419
|
-
|
420
|
-
}, "Chunk.
|
421
|
-
});
|
422
|
-
|
423
|
-
// TODO remove in webpack 5
|
424
|
-
Object.defineProperty(Chunk.prototype, "
|
425
|
-
configurable: false,
|
426
|
-
|
427
|
-
|
428
|
-
},
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
throw new Error("Chunk.
|
439
|
-
}
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
throw new Error("Chunk.
|
450
|
-
}
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
throw new Error(
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
1
|
+
/*
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
+
Author Tobias Koppers @sokra
|
4
|
+
*/
|
5
|
+
"use strict";
|
6
|
+
|
7
|
+
const util = require("util");
|
8
|
+
const SortableSet = require("./util/SortableSet");
|
9
|
+
const GraphHelpers = require("./GraphHelpers");
|
10
|
+
let debugId = 1000;
|
11
|
+
const ERR_CHUNK_ENTRY = "Chunk.entry was removed. Use hasRuntime()";
|
12
|
+
const ERR_CHUNK_INITIAL =
|
13
|
+
"Chunk.initial was removed. Use canBeInitial/isOnlyInitial()";
|
14
|
+
|
15
|
+
const sortById = (a, b) => {
|
16
|
+
if (a.id < b.id) return -1;
|
17
|
+
if (b.id < a.id) return 1;
|
18
|
+
return 0;
|
19
|
+
};
|
20
|
+
|
21
|
+
const sortByIdentifier = (a, b) => {
|
22
|
+
if (a.identifier() > b.identifier()) return 1;
|
23
|
+
if (a.identifier() < b.identifier()) return -1;
|
24
|
+
return 0;
|
25
|
+
};
|
26
|
+
|
27
|
+
const getModulesIdent = set => {
|
28
|
+
set.sort();
|
29
|
+
let str = "";
|
30
|
+
for (const m of set) {
|
31
|
+
str += m.identifier() + "#";
|
32
|
+
}
|
33
|
+
return str;
|
34
|
+
};
|
35
|
+
|
36
|
+
const getArray = set => Array.from(set);
|
37
|
+
|
38
|
+
const getModulesSize = set => {
|
39
|
+
let count = 0;
|
40
|
+
for (const module of set) {
|
41
|
+
count += module.size();
|
42
|
+
}
|
43
|
+
return count;
|
44
|
+
};
|
45
|
+
|
46
|
+
class Chunk {
|
47
|
+
constructor(name) {
|
48
|
+
this.id = null;
|
49
|
+
this.ids = null;
|
50
|
+
this.debugId = debugId++;
|
51
|
+
this.name = name;
|
52
|
+
this.entryModule = undefined;
|
53
|
+
this._modules = new SortableSet(undefined, sortByIdentifier);
|
54
|
+
this._groups = new SortableSet(undefined, sortById);
|
55
|
+
this.files = [];
|
56
|
+
this.rendered = false;
|
57
|
+
this.hash = undefined;
|
58
|
+
this.contentHash = Object.create(null);
|
59
|
+
this.renderedHash = undefined;
|
60
|
+
this.chunkReason = undefined;
|
61
|
+
this.extraAsync = false;
|
62
|
+
}
|
63
|
+
|
64
|
+
get entry() {
|
65
|
+
throw new Error(ERR_CHUNK_ENTRY);
|
66
|
+
}
|
67
|
+
|
68
|
+
set entry(data) {
|
69
|
+
throw new Error(ERR_CHUNK_ENTRY);
|
70
|
+
}
|
71
|
+
|
72
|
+
get initial() {
|
73
|
+
throw new Error(ERR_CHUNK_INITIAL);
|
74
|
+
}
|
75
|
+
|
76
|
+
set initial(data) {
|
77
|
+
throw new Error(ERR_CHUNK_INITIAL);
|
78
|
+
}
|
79
|
+
|
80
|
+
hasRuntime() {
|
81
|
+
for (const chunkGroup of this._groups) {
|
82
|
+
// We only need to check the first one
|
83
|
+
return chunkGroup.isInitial() && chunkGroup.getRuntimeChunk() === this;
|
84
|
+
}
|
85
|
+
return false;
|
86
|
+
}
|
87
|
+
|
88
|
+
canBeInitial() {
|
89
|
+
for (const chunkGroup of this._groups) {
|
90
|
+
if (chunkGroup.isInitial()) return true;
|
91
|
+
}
|
92
|
+
return false;
|
93
|
+
}
|
94
|
+
|
95
|
+
isOnlyInitial() {
|
96
|
+
if (this._groups.size <= 0) return false;
|
97
|
+
for (const chunkGroup of this._groups) {
|
98
|
+
if (!chunkGroup.isInitial()) return false;
|
99
|
+
}
|
100
|
+
return true;
|
101
|
+
}
|
102
|
+
|
103
|
+
hasEntryModule() {
|
104
|
+
return !!this.entryModule;
|
105
|
+
}
|
106
|
+
|
107
|
+
addModule(module) {
|
108
|
+
if (!this._modules.has(module)) {
|
109
|
+
this._modules.add(module);
|
110
|
+
return true;
|
111
|
+
}
|
112
|
+
return false;
|
113
|
+
}
|
114
|
+
|
115
|
+
removeModule(module) {
|
116
|
+
if (this._modules.delete(module)) {
|
117
|
+
module.removeChunk(this);
|
118
|
+
return true;
|
119
|
+
}
|
120
|
+
return false;
|
121
|
+
}
|
122
|
+
|
123
|
+
setModules(modules) {
|
124
|
+
this._modules = new SortableSet(modules, sortByIdentifier);
|
125
|
+
}
|
126
|
+
|
127
|
+
getNumberOfModules() {
|
128
|
+
return this._modules.size;
|
129
|
+
}
|
130
|
+
|
131
|
+
get modulesIterable() {
|
132
|
+
return this._modules;
|
133
|
+
}
|
134
|
+
|
135
|
+
addGroup(chunkGroup) {
|
136
|
+
if (this._groups.has(chunkGroup)) return false;
|
137
|
+
this._groups.add(chunkGroup);
|
138
|
+
return true;
|
139
|
+
}
|
140
|
+
|
141
|
+
removeGroup(chunkGroup) {
|
142
|
+
if (!this._groups.has(chunkGroup)) return false;
|
143
|
+
this._groups.delete(chunkGroup);
|
144
|
+
return true;
|
145
|
+
}
|
146
|
+
|
147
|
+
isInGroup(chunkGroup) {
|
148
|
+
return this._groups.has(chunkGroup);
|
149
|
+
}
|
150
|
+
|
151
|
+
getNumberOfGroups() {
|
152
|
+
return this._groups.size;
|
153
|
+
}
|
154
|
+
|
155
|
+
get groupsIterable() {
|
156
|
+
return this._groups;
|
157
|
+
}
|
158
|
+
|
159
|
+
compareTo(otherChunk) {
|
160
|
+
this._modules.sort();
|
161
|
+
otherChunk._modules.sort();
|
162
|
+
if (this._modules.size > otherChunk._modules.size) return -1;
|
163
|
+
if (this._modules.size < otherChunk._modules.size) return 1;
|
164
|
+
const a = this._modules[Symbol.iterator]();
|
165
|
+
const b = otherChunk._modules[Symbol.iterator]();
|
166
|
+
// eslint-disable-next-line
|
167
|
+
while (true) {
|
168
|
+
const aItem = a.next();
|
169
|
+
const bItem = b.next();
|
170
|
+
if (aItem.done) return 0;
|
171
|
+
const aModuleIdentifier = aItem.value.identifier();
|
172
|
+
const bModuleIdentifier = bItem.value.identifier();
|
173
|
+
if (aModuleIdentifier > bModuleIdentifier) return -1;
|
174
|
+
if (aModuleIdentifier < bModuleIdentifier) return 1;
|
175
|
+
}
|
176
|
+
}
|
177
|
+
|
178
|
+
containsModule(module) {
|
179
|
+
return this._modules.has(module);
|
180
|
+
}
|
181
|
+
|
182
|
+
getModules() {
|
183
|
+
return this._modules.getFromCache(getArray);
|
184
|
+
}
|
185
|
+
|
186
|
+
getModulesIdent() {
|
187
|
+
return this._modules.getFromUnorderedCache(getModulesIdent);
|
188
|
+
}
|
189
|
+
|
190
|
+
remove(reason) {
|
191
|
+
// cleanup modules
|
192
|
+
// Array.from is used here to create a clone, because removeChunk modifies this._modules
|
193
|
+
for (const module of Array.from(this._modules)) {
|
194
|
+
module.removeChunk(this);
|
195
|
+
}
|
196
|
+
for (const chunkGroup of this._groups) {
|
197
|
+
chunkGroup.removeChunk(this);
|
198
|
+
}
|
199
|
+
}
|
200
|
+
|
201
|
+
moveModule(module, otherChunk) {
|
202
|
+
GraphHelpers.disconnectChunkAndModule(this, module);
|
203
|
+
GraphHelpers.connectChunkAndModule(otherChunk, module);
|
204
|
+
module.rewriteChunkInReasons(this, [otherChunk]);
|
205
|
+
}
|
206
|
+
|
207
|
+
integrate(otherChunk, reason) {
|
208
|
+
if (!this.canBeIntegrated(otherChunk)) {
|
209
|
+
return false;
|
210
|
+
}
|
211
|
+
|
212
|
+
// Array.from is used here to create a clone, because moveModule modifies otherChunk._modules
|
213
|
+
for (const module of Array.from(otherChunk._modules)) {
|
214
|
+
otherChunk.moveModule(module, this);
|
215
|
+
}
|
216
|
+
otherChunk._modules.clear();
|
217
|
+
|
218
|
+
for (const chunkGroup of otherChunk._groups) {
|
219
|
+
chunkGroup.replaceChunk(otherChunk, this);
|
220
|
+
this.addGroup(chunkGroup);
|
221
|
+
}
|
222
|
+
otherChunk._groups.clear();
|
223
|
+
|
224
|
+
if (this.name && otherChunk.name) {
|
225
|
+
if (this.name.length !== otherChunk.name.length)
|
226
|
+
this.name =
|
227
|
+
this.name.length < otherChunk.name.length
|
228
|
+
? this.name
|
229
|
+
: otherChunk.name;
|
230
|
+
else
|
231
|
+
this.name = this.name < otherChunk.name ? this.name : otherChunk.name;
|
232
|
+
}
|
233
|
+
|
234
|
+
return true;
|
235
|
+
}
|
236
|
+
|
237
|
+
split(newChunk) {
|
238
|
+
for (const chunkGroup of this._groups) {
|
239
|
+
chunkGroup.insertChunk(newChunk, this);
|
240
|
+
newChunk.addGroup(chunkGroup);
|
241
|
+
}
|
242
|
+
}
|
243
|
+
|
244
|
+
isEmpty() {
|
245
|
+
return this._modules.size === 0;
|
246
|
+
}
|
247
|
+
|
248
|
+
updateHash(hash) {
|
249
|
+
hash.update(`${this.id} `);
|
250
|
+
hash.update(this.ids ? this.ids.join(",") : "");
|
251
|
+
hash.update(`${this.name || ""} `);
|
252
|
+
for (const m of this._modules) {
|
253
|
+
hash.update(m.hash);
|
254
|
+
}
|
255
|
+
}
|
256
|
+
|
257
|
+
canBeIntegrated(otherChunk) {
|
258
|
+
const isAvailable = (a, b) => {
|
259
|
+
const queue = new Set(b.groupsIterable);
|
260
|
+
for (const chunkGroup of queue) {
|
261
|
+
if (a.isInGroup(chunkGroup)) continue;
|
262
|
+
if (chunkGroup.isInitial()) return false;
|
263
|
+
for (const parent of chunkGroup.parentsIterable) queue.add(parent);
|
264
|
+
}
|
265
|
+
return true;
|
266
|
+
};
|
267
|
+
if (this.hasRuntime() !== otherChunk.hasRuntime()) {
|
268
|
+
if (this.hasRuntime()) {
|
269
|
+
return isAvailable(this, otherChunk);
|
270
|
+
} else if (otherChunk.hasRuntime()) {
|
271
|
+
return isAvailable(otherChunk, this);
|
272
|
+
} else {
|
273
|
+
return false;
|
274
|
+
}
|
275
|
+
}
|
276
|
+
if (this.hasEntryModule() || otherChunk.hasEntryModule()) return false;
|
277
|
+
return true;
|
278
|
+
}
|
279
|
+
|
280
|
+
addMultiplierAndOverhead(size, options) {
|
281
|
+
const overhead =
|
282
|
+
typeof options.chunkOverhead === "number" ? options.chunkOverhead : 10000;
|
283
|
+
const multiplicator = this.canBeInitial()
|
284
|
+
? options.entryChunkMultiplicator || 10
|
285
|
+
: 1;
|
286
|
+
|
287
|
+
return size * multiplicator + overhead;
|
288
|
+
}
|
289
|
+
|
290
|
+
modulesSize() {
|
291
|
+
return this._modules.getFromUnorderedCache(getModulesSize);
|
292
|
+
}
|
293
|
+
|
294
|
+
size(options) {
|
295
|
+
return this.addMultiplierAndOverhead(this.modulesSize(), options);
|
296
|
+
}
|
297
|
+
|
298
|
+
integratedSize(otherChunk, options) {
|
299
|
+
// Chunk if it's possible to integrate this chunk
|
300
|
+
if (!this.canBeIntegrated(otherChunk)) {
|
301
|
+
return false;
|
302
|
+
}
|
303
|
+
|
304
|
+
let integratedModulesSize = this.modulesSize();
|
305
|
+
// only count modules that do not exist in this chunk!
|
306
|
+
for (const otherModule of otherChunk._modules) {
|
307
|
+
if (!this._modules.has(otherModule)) {
|
308
|
+
integratedModulesSize += otherModule.size();
|
309
|
+
}
|
310
|
+
}
|
311
|
+
|
312
|
+
return this.addMultiplierAndOverhead(integratedModulesSize, options);
|
313
|
+
}
|
314
|
+
|
315
|
+
sortModules(sortByFn) {
|
316
|
+
this._modules.sortWith(sortByFn || sortById);
|
317
|
+
}
|
318
|
+
|
319
|
+
sortItems(sortChunks) {
|
320
|
+
this.sortModules();
|
321
|
+
}
|
322
|
+
|
323
|
+
getAllAsyncChunks() {
|
324
|
+
const initialChunks = new Set();
|
325
|
+
const queue = new Set(this.groupsIterable);
|
326
|
+
const chunks = new Set();
|
327
|
+
|
328
|
+
for (const chunkGroup of queue) {
|
329
|
+
for (const chunk of chunkGroup.chunks) initialChunks.add(chunk);
|
330
|
+
}
|
331
|
+
|
332
|
+
for (const chunkGroup of queue) {
|
333
|
+
for (const chunk of chunkGroup.chunks) {
|
334
|
+
if (!initialChunks.has(chunk)) chunks.add(chunk);
|
335
|
+
}
|
336
|
+
for (const child of chunkGroup.childrenIterable) queue.add(child);
|
337
|
+
}
|
338
|
+
|
339
|
+
return chunks;
|
340
|
+
}
|
341
|
+
|
342
|
+
getChunkMaps(realHash) {
|
343
|
+
const chunkHashMap = Object.create(null);
|
344
|
+
const chunkContentHashMap = Object.create(null);
|
345
|
+
const chunkNameMap = Object.create(null);
|
346
|
+
|
347
|
+
for (const chunk of this.getAllAsyncChunks()) {
|
348
|
+
chunkHashMap[chunk.id] = realHash ? chunk.hash : chunk.renderedHash;
|
349
|
+
for (const key of Object.keys(chunk.contentHash)) {
|
350
|
+
if (!chunkContentHashMap[key])
|
351
|
+
chunkContentHashMap[key] = Object.create(null);
|
352
|
+
chunkContentHashMap[key][chunk.id] = chunk.contentHash[key];
|
353
|
+
}
|
354
|
+
if (chunk.name) chunkNameMap[chunk.id] = chunk.name;
|
355
|
+
}
|
356
|
+
|
357
|
+
return {
|
358
|
+
hash: chunkHashMap,
|
359
|
+
contentHash: chunkContentHashMap,
|
360
|
+
name: chunkNameMap
|
361
|
+
};
|
362
|
+
}
|
363
|
+
|
364
|
+
getChunkModuleMaps(filterFn) {
|
365
|
+
const chunkModuleIdMap = Object.create(null);
|
366
|
+
const chunkModuleHashMap = Object.create(null);
|
367
|
+
|
368
|
+
for (const chunk of this.getAllAsyncChunks()) {
|
369
|
+
let array;
|
370
|
+
for (const module of chunk.modulesIterable) {
|
371
|
+
if (filterFn(module)) {
|
372
|
+
if (array === undefined) {
|
373
|
+
array = [];
|
374
|
+
chunkModuleIdMap[chunk.id] = array;
|
375
|
+
}
|
376
|
+
array.push(module.id);
|
377
|
+
chunkModuleHashMap[module.id] = module.renderedHash;
|
378
|
+
}
|
379
|
+
}
|
380
|
+
if (array !== undefined) {
|
381
|
+
array.sort();
|
382
|
+
}
|
383
|
+
}
|
384
|
+
|
385
|
+
return {
|
386
|
+
id: chunkModuleIdMap,
|
387
|
+
hash: chunkModuleHashMap
|
388
|
+
};
|
389
|
+
}
|
390
|
+
|
391
|
+
hasModuleInGraph(filterFn, filterChunkFn) {
|
392
|
+
const queue = new Set(this.groupsIterable);
|
393
|
+
const chunksProcessed = new Set();
|
394
|
+
|
395
|
+
for (const chunkGroup of queue) {
|
396
|
+
for (const chunk of chunkGroup.chunks) {
|
397
|
+
if (!chunksProcessed.has(chunk)) {
|
398
|
+
chunksProcessed.add(chunk);
|
399
|
+
if (!filterChunkFn || filterChunkFn(chunk)) {
|
400
|
+
for (const module of chunk.modulesIterable)
|
401
|
+
if (filterFn(module)) return true;
|
402
|
+
}
|
403
|
+
}
|
404
|
+
}
|
405
|
+
for (const child of chunkGroup.childrenIterable) queue.add(child);
|
406
|
+
}
|
407
|
+
return false;
|
408
|
+
}
|
409
|
+
|
410
|
+
toString() {
|
411
|
+
return `Chunk[${Array.from(this._modules).join()}]`;
|
412
|
+
}
|
413
|
+
}
|
414
|
+
|
415
|
+
// TODO remove in webpack 5
|
416
|
+
Object.defineProperty(Chunk.prototype, "forEachModule", {
|
417
|
+
configurable: false,
|
418
|
+
value: util.deprecate(function(fn) {
|
419
|
+
this._modules.forEach(fn);
|
420
|
+
}, "Chunk.forEachModule: Use for(const module of chunk.modulesIterable) instead")
|
421
|
+
});
|
422
|
+
|
423
|
+
// TODO remove in webpack 5
|
424
|
+
Object.defineProperty(Chunk.prototype, "mapModules", {
|
425
|
+
configurable: false,
|
426
|
+
value: util.deprecate(function(fn) {
|
427
|
+
return Array.from(this._modules, fn);
|
428
|
+
}, "Chunk.mapModules: Use Array.from(chunk.modulesIterable, fn) instead")
|
429
|
+
});
|
430
|
+
|
431
|
+
// TODO remove in webpack 5
|
432
|
+
Object.defineProperty(Chunk.prototype, "chunks", {
|
433
|
+
configurable: false,
|
434
|
+
get() {
|
435
|
+
throw new Error("Chunk.chunks: Use ChunkGroup.getChildren() instead");
|
436
|
+
},
|
437
|
+
set() {
|
438
|
+
throw new Error("Chunk.chunks: Use ChunkGroup.add/removeChild() instead");
|
439
|
+
}
|
440
|
+
});
|
441
|
+
|
442
|
+
// TODO remove in webpack 5
|
443
|
+
Object.defineProperty(Chunk.prototype, "parents", {
|
444
|
+
configurable: false,
|
445
|
+
get() {
|
446
|
+
throw new Error("Chunk.parents: Use ChunkGroup.getParents() instead");
|
447
|
+
},
|
448
|
+
set() {
|
449
|
+
throw new Error("Chunk.parents: Use ChunkGroup.add/removeParent() instead");
|
450
|
+
}
|
451
|
+
});
|
452
|
+
|
453
|
+
// TODO remove in webpack 5
|
454
|
+
Object.defineProperty(Chunk.prototype, "blocks", {
|
455
|
+
configurable: false,
|
456
|
+
get() {
|
457
|
+
throw new Error("Chunk.blocks: Use ChunkGroup.getBlocks() instead");
|
458
|
+
},
|
459
|
+
set() {
|
460
|
+
throw new Error("Chunk.blocks: Use ChunkGroup.add/removeBlock() instead");
|
461
|
+
}
|
462
|
+
});
|
463
|
+
|
464
|
+
// TODO remove in webpack 5
|
465
|
+
Object.defineProperty(Chunk.prototype, "entrypoints", {
|
466
|
+
configurable: false,
|
467
|
+
get() {
|
468
|
+
throw new Error(
|
469
|
+
"Chunk.entrypoints: Use Chunks.groupsIterable and filter by instanceof Entrypoint instead"
|
470
|
+
);
|
471
|
+
},
|
472
|
+
set() {
|
473
|
+
throw new Error("Chunk.entrypoints: Use Chunks.addGroup instead");
|
474
|
+
}
|
475
|
+
});
|
476
|
+
|
477
|
+
module.exports = Chunk;
|