webpack 5.39.0 → 5.41.1
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.
Potentially problematic release.
This version of webpack might be problematic. Click here for more details.
- package/README.md +13 -13
- package/bin/webpack.js +0 -0
- package/lib/Compilation.js +43 -28
- package/lib/ConditionalInitFragment.js +15 -12
- package/lib/DependencyTemplate.js +3 -2
- package/lib/ExternalModule.js +210 -35
- package/lib/ExternalModuleFactoryPlugin.js +2 -1
- package/lib/InitFragment.js +10 -7
- package/lib/MainTemplate.js +1 -1
- package/lib/ModuleTemplate.js +0 -9
- package/lib/RuntimeTemplate.js +8 -0
- package/lib/Template.js +3 -2
- package/lib/TemplatedPathPlugin.js +24 -26
- package/lib/Watching.js +2 -1
- package/lib/WebpackOptionsApply.js +10 -7
- package/lib/async-modules/AwaitDependenciesInitFragment.js +4 -1
- package/lib/cache/IdleFileCachePlugin.js +60 -13
- package/lib/cache/PackFileCacheStrategy.js +4 -1
- package/lib/cli.js +1 -1
- package/lib/config/defaults.js +53 -12
- package/lib/config/normalization.js +1 -0
- package/lib/dependencies/HarmonyExportInitFragment.js +4 -1
- package/lib/dependencies/WorkerPlugin.js +25 -10
- package/lib/electron/ElectronTargetPlugin.js +3 -3
- package/lib/esm/ModuleChunkFormatPlugin.js +97 -0
- package/lib/esm/ModuleChunkLoadingPlugin.js +63 -0
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +208 -0
- package/lib/hmr/lazyCompilationBackend.js +17 -1
- package/lib/javascript/EnableChunkLoadingPlugin.js +5 -3
- package/lib/javascript/JavascriptModulesPlugin.js +80 -17
- package/lib/javascript/JavascriptParser.js +12 -4
- package/lib/node/NodeTargetPlugin.js +2 -1
- package/lib/node/ReadFileCompileAsyncWasmPlugin.js +44 -22
- package/lib/optimize/InnerGraphPlugin.js +33 -2
- package/lib/optimize/ModuleConcatenationPlugin.js +1 -1
- package/lib/runtime/AsyncModuleRuntimeModule.js +8 -4
- package/lib/serialization/BinaryMiddleware.js +24 -14
- package/lib/serialization/FileMiddleware.js +30 -6
- package/lib/serialization/PlainObjectSerializer.js +17 -8
- package/lib/serialization/Serializer.js +2 -2
- package/lib/serialization/SerializerMiddleware.js +26 -4
- package/lib/util/ArrayQueue.js +8 -0
- package/lib/util/AsyncQueue.js +9 -0
- package/lib/util/LazySet.js +26 -17
- package/lib/wasm/EnableWasmLoadingPlugin.js +10 -1
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +2 -2
- package/lib/wasm-sync/WebAssemblyModulesPlugin.js +1 -1
- package/package.json +17 -17
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +16 -7
- package/types.d.ts +107 -158
package/lib/ExternalModule.js
CHANGED
@@ -7,6 +7,8 @@
|
|
7
7
|
|
8
8
|
const { OriginalSource, RawSource } = require("webpack-sources");
|
9
9
|
const ConcatenationScope = require("./ConcatenationScope");
|
10
|
+
const { UsageState } = require("./ExportsInfo");
|
11
|
+
const InitFragment = require("./InitFragment");
|
10
12
|
const Module = require("./Module");
|
11
13
|
const RuntimeGlobals = require("./RuntimeGlobals");
|
12
14
|
const Template = require("./Template");
|
@@ -22,6 +24,7 @@ const propertyAccess = require("./util/propertyAccess");
|
|
22
24
|
/** @typedef {import("./Compilation")} Compilation */
|
23
25
|
/** @typedef {import("./Dependency").UpdateHashContext} UpdateHashContext */
|
24
26
|
/** @typedef {import("./DependencyTemplates")} DependencyTemplates */
|
27
|
+
/** @typedef {import("./ExportsInfo")} ExportsInfo */
|
25
28
|
/** @typedef {import("./Module").CodeGenerationContext} CodeGenerationContext */
|
26
29
|
/** @typedef {import("./Module").CodeGenerationResult} CodeGenerationResult */
|
27
30
|
/** @typedef {import("./Module").ConcatenationBailoutReasonContext} ConcatenationBailoutReasonContext */
|
@@ -31,16 +34,28 @@ const propertyAccess = require("./util/propertyAccess");
|
|
31
34
|
/** @typedef {import("./ResolverFactory").ResolverWithOptions} ResolverWithOptions */
|
32
35
|
/** @typedef {import("./RuntimeTemplate")} RuntimeTemplate */
|
33
36
|
/** @typedef {import("./WebpackError")} WebpackError */
|
37
|
+
/** @typedef {import("./javascript/JavascriptModulesPlugin").ChunkRenderContext} ChunkRenderContext */
|
34
38
|
/** @typedef {import("./util/Hash")} Hash */
|
35
39
|
/** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */
|
40
|
+
/** @typedef {import("./util/runtime").RuntimeSpec} RuntimeSpec */
|
36
41
|
|
37
42
|
/**
|
38
43
|
* @typedef {Object} SourceData
|
39
44
|
* @property {boolean=} iife
|
40
45
|
* @property {string=} init
|
41
46
|
* @property {string} expression
|
47
|
+
* @property {InitFragment<ChunkRenderContext>[]=} chunkInitFragments
|
48
|
+
* @property {ReadonlySet<string>=} runtimeRequirements
|
42
49
|
*/
|
43
50
|
|
51
|
+
const TYPES = new Set(["javascript"]);
|
52
|
+
const RUNTIME_REQUIREMENTS = new Set([RuntimeGlobals.module]);
|
53
|
+
const RUNTIME_REQUIREMENTS_FOR_SCRIPT = new Set([RuntimeGlobals.loadScript]);
|
54
|
+
const RUNTIME_REQUIREMENTS_FOR_MODULE = new Set([
|
55
|
+
RuntimeGlobals.definePropertyGetters
|
56
|
+
]);
|
57
|
+
const EMPTY_RUNTIME_REQUIREMENTS = new Set([]);
|
58
|
+
|
44
59
|
/**
|
45
60
|
* @param {string|string[]} variableName the variable name or path
|
46
61
|
* @param {string} type the module system
|
@@ -67,7 +82,7 @@ const getSourceForGlobalVariableExternal = (variableName, type) => {
|
|
67
82
|
const getSourceForCommonJsExternal = moduleAndSpecifiers => {
|
68
83
|
if (!Array.isArray(moduleAndSpecifiers)) {
|
69
84
|
return {
|
70
|
-
expression: `require(${JSON.stringify(moduleAndSpecifiers)})
|
85
|
+
expression: `require(${JSON.stringify(moduleAndSpecifiers)})`
|
71
86
|
};
|
72
87
|
}
|
73
88
|
const moduleName = moduleAndSpecifiers[0];
|
@@ -75,7 +90,37 @@ const getSourceForCommonJsExternal = moduleAndSpecifiers => {
|
|
75
90
|
expression: `require(${JSON.stringify(moduleName)})${propertyAccess(
|
76
91
|
moduleAndSpecifiers,
|
77
92
|
1
|
78
|
-
)}
|
93
|
+
)}`
|
94
|
+
};
|
95
|
+
};
|
96
|
+
|
97
|
+
/**
|
98
|
+
* @param {string|string[]} moduleAndSpecifiers the module request
|
99
|
+
* @returns {SourceData} the generated source
|
100
|
+
*/
|
101
|
+
const getSourceForCommonJsExternalInNodeModule = moduleAndSpecifiers => {
|
102
|
+
const chunkInitFragments = [
|
103
|
+
new InitFragment(
|
104
|
+
'import { createRequire as __WEBPACK_EXTERNAL_createRequire } from "module";\n',
|
105
|
+
InitFragment.STAGE_HARMONY_IMPORTS,
|
106
|
+
0,
|
107
|
+
"external module node-commonjs"
|
108
|
+
)
|
109
|
+
];
|
110
|
+
if (!Array.isArray(moduleAndSpecifiers)) {
|
111
|
+
return {
|
112
|
+
expression: `__WEBPACK_EXTERNAL_createRequire(import.meta.url)(${JSON.stringify(
|
113
|
+
moduleAndSpecifiers
|
114
|
+
)})`,
|
115
|
+
chunkInitFragments
|
116
|
+
};
|
117
|
+
}
|
118
|
+
const moduleName = moduleAndSpecifiers[0];
|
119
|
+
return {
|
120
|
+
expression: `__WEBPACK_EXTERNAL_createRequire(import.meta.url)(${JSON.stringify(
|
121
|
+
moduleName
|
122
|
+
)})${propertyAccess(moduleAndSpecifiers, 1)}`,
|
123
|
+
chunkInitFragments
|
79
124
|
};
|
80
125
|
};
|
81
126
|
|
@@ -112,6 +157,91 @@ const getSourceForImportExternal = (moduleAndSpecifiers, runtimeTemplate) => {
|
|
112
157
|
};
|
113
158
|
};
|
114
159
|
|
160
|
+
class ModuleExternalInitFragment extends InitFragment {
|
161
|
+
constructor(id, request) {
|
162
|
+
const identifier = `__WEBPACK_EXTERNAL_MODULE_${Template.toIdentifier(
|
163
|
+
`${id}`
|
164
|
+
)}__`;
|
165
|
+
super(
|
166
|
+
`import * as ${identifier} from ${JSON.stringify(request)};\n`,
|
167
|
+
InitFragment.STAGE_HARMONY_IMPORTS,
|
168
|
+
0,
|
169
|
+
`external module import ${id}`
|
170
|
+
);
|
171
|
+
this._identifier = identifier;
|
172
|
+
}
|
173
|
+
|
174
|
+
getNamespaceIdentifier() {
|
175
|
+
return this._identifier;
|
176
|
+
}
|
177
|
+
}
|
178
|
+
|
179
|
+
const generateModuleRemapping = (input, exportsInfo, runtime) => {
|
180
|
+
if (exportsInfo.otherExportsInfo.getUsed(runtime) === UsageState.Unused) {
|
181
|
+
const properties = [];
|
182
|
+
for (const exportInfo of exportsInfo.orderedExports) {
|
183
|
+
const used = exportInfo.getUsedName(exportInfo.name, runtime);
|
184
|
+
if (!used) continue;
|
185
|
+
const nestedInfo = exportInfo.getNestedExportsInfo();
|
186
|
+
if (nestedInfo) {
|
187
|
+
const nestedExpr = generateModuleRemapping(
|
188
|
+
`${input}${propertyAccess([exportInfo.name])}`,
|
189
|
+
nestedInfo
|
190
|
+
);
|
191
|
+
if (nestedExpr) {
|
192
|
+
properties.push(`[${JSON.stringify(used)}]: y(${nestedExpr})`);
|
193
|
+
continue;
|
194
|
+
}
|
195
|
+
}
|
196
|
+
properties.push(
|
197
|
+
`[${JSON.stringify(used)}]: () => ${input}${propertyAccess([
|
198
|
+
exportInfo.name
|
199
|
+
])}`
|
200
|
+
);
|
201
|
+
}
|
202
|
+
return `x({ ${properties.join(", ")} })`;
|
203
|
+
}
|
204
|
+
};
|
205
|
+
|
206
|
+
/**
|
207
|
+
* @param {string|number} id the module id
|
208
|
+
* @param {string|string[]} moduleAndSpecifiers the module request
|
209
|
+
* @param {ExportsInfo} exportsInfo exports info of this module
|
210
|
+
* @param {RuntimeSpec} runtime the runtime
|
211
|
+
* @returns {SourceData} the generated source
|
212
|
+
*/
|
213
|
+
const getSourceForModuleExternal = (
|
214
|
+
id,
|
215
|
+
moduleAndSpecifiers,
|
216
|
+
exportsInfo,
|
217
|
+
runtime
|
218
|
+
) => {
|
219
|
+
if (!Array.isArray(moduleAndSpecifiers))
|
220
|
+
moduleAndSpecifiers = [moduleAndSpecifiers];
|
221
|
+
const initFragment = new ModuleExternalInitFragment(
|
222
|
+
id,
|
223
|
+
moduleAndSpecifiers[0]
|
224
|
+
);
|
225
|
+
const baseAccess = `${initFragment.getNamespaceIdentifier()}${propertyAccess(
|
226
|
+
moduleAndSpecifiers,
|
227
|
+
1
|
228
|
+
)}`;
|
229
|
+
const moduleRemapping = generateModuleRemapping(
|
230
|
+
baseAccess,
|
231
|
+
exportsInfo,
|
232
|
+
runtime
|
233
|
+
);
|
234
|
+
let expression = moduleRemapping || baseAccess;
|
235
|
+
return {
|
236
|
+
expression,
|
237
|
+
init: `var x = y => { var x = {}; ${RuntimeGlobals.definePropertyGetters}(x, y); return x; }\nvar y = x => () => x`,
|
238
|
+
runtimeRequirements: moduleRemapping
|
239
|
+
? RUNTIME_REQUIREMENTS_FOR_MODULE
|
240
|
+
: undefined,
|
241
|
+
chunkInitFragments: [initFragment]
|
242
|
+
};
|
243
|
+
};
|
244
|
+
|
115
245
|
/**
|
116
246
|
* @param {string|string[]} urlAndGlobal the script request
|
117
247
|
* @param {RuntimeTemplate} runtimeTemplate the runtime template
|
@@ -144,7 +274,8 @@ const getSourceForScriptExternal = (urlAndGlobal, runtimeTemplate) => {
|
|
144
274
|
]
|
145
275
|
)}).then(${runtimeTemplate.returningFunction(
|
146
276
|
`${globalName}${propertyAccess(urlAndGlobal, 2)}`
|
147
|
-
)})
|
277
|
+
)})`,
|
278
|
+
runtimeRequirements: RUNTIME_REQUIREMENTS_FOR_SCRIPT
|
148
279
|
};
|
149
280
|
};
|
150
281
|
|
@@ -210,14 +341,6 @@ const getSourceForDefaultCase = (optional, request, runtimeTemplate) => {
|
|
210
341
|
};
|
211
342
|
};
|
212
343
|
|
213
|
-
const TYPES = new Set(["javascript"]);
|
214
|
-
const RUNTIME_REQUIREMENTS = new Set([RuntimeGlobals.module]);
|
215
|
-
const RUNTIME_REQUIREMENTS_FOR_SCRIPT = new Set([
|
216
|
-
RuntimeGlobals.module,
|
217
|
-
RuntimeGlobals.loadScript
|
218
|
-
]);
|
219
|
-
const RUNTIME_REQUIREMENTS_CONCATENATED = new Set([]);
|
220
|
-
|
221
344
|
class ExternalModule extends Module {
|
222
345
|
constructor(request, type, userRequest) {
|
223
346
|
super("javascript/dynamic", null);
|
@@ -293,32 +416,44 @@ class ExternalModule extends Module {
|
|
293
416
|
exportsType: undefined
|
294
417
|
};
|
295
418
|
this.buildInfo = {
|
296
|
-
strict:
|
297
|
-
topLevelDeclarations: new Set()
|
419
|
+
strict: true,
|
420
|
+
topLevelDeclarations: new Set(),
|
421
|
+
module: compilation.outputOptions.module
|
298
422
|
};
|
423
|
+
const { request, externalType } = this._getRequestAndExternalType();
|
299
424
|
this.buildMeta.exportsType = "dynamic";
|
300
425
|
let canMangle = false;
|
301
426
|
this.clearDependenciesAndBlocks();
|
302
|
-
switch (
|
427
|
+
switch (externalType) {
|
428
|
+
case "this":
|
429
|
+
this.buildInfo.strict = false;
|
430
|
+
break;
|
303
431
|
case "system":
|
304
|
-
|
305
|
-
|
306
|
-
|
432
|
+
case "module":
|
433
|
+
if (this.buildInfo.module) {
|
434
|
+
if (!Array.isArray(request) || request.length === 1) {
|
435
|
+
this.buildMeta.exportsType = "namespace";
|
436
|
+
canMangle = true;
|
437
|
+
}
|
438
|
+
} else {
|
439
|
+
this.buildMeta.async = true;
|
440
|
+
if (!Array.isArray(request) || request.length === 1) {
|
441
|
+
this.buildMeta.exportsType = "namespace";
|
442
|
+
canMangle = false;
|
443
|
+
}
|
307
444
|
}
|
308
445
|
break;
|
446
|
+
case "script":
|
309
447
|
case "promise":
|
310
448
|
this.buildMeta.async = true;
|
311
449
|
break;
|
312
450
|
case "import":
|
313
451
|
this.buildMeta.async = true;
|
314
|
-
if (!Array.isArray(
|
452
|
+
if (!Array.isArray(request) || request.length === 1) {
|
315
453
|
this.buildMeta.exportsType = "namespace";
|
316
454
|
canMangle = false;
|
317
455
|
}
|
318
456
|
break;
|
319
|
-
case "script":
|
320
|
-
this.buildMeta.async = true;
|
321
|
-
break;
|
322
457
|
}
|
323
458
|
this.addDependency(new StaticExportsDependency(true, canMangle));
|
324
459
|
callback();
|
@@ -341,12 +476,16 @@ class ExternalModule extends Module {
|
|
341
476
|
return undefined;
|
342
477
|
}
|
343
478
|
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
479
|
+
_getRequestAndExternalType() {
|
480
|
+
let { request, externalType } = this;
|
481
|
+
if (typeof request === "object" && !Array.isArray(request))
|
482
|
+
request = request[externalType];
|
483
|
+
return { request, externalType };
|
484
|
+
}
|
485
|
+
|
486
|
+
_getSourceData(runtimeTemplate, moduleGraph, chunkGraph, runtime) {
|
487
|
+
const { request, externalType } = this._getRequestAndExternalType();
|
488
|
+
switch (externalType) {
|
350
489
|
case "this":
|
351
490
|
case "window":
|
352
491
|
case "self":
|
@@ -360,6 +499,10 @@ class ExternalModule extends Module {
|
|
360
499
|
case "commonjs2":
|
361
500
|
case "commonjs-module":
|
362
501
|
return getSourceForCommonJsExternal(request);
|
502
|
+
case "node-commonjs":
|
503
|
+
return this.buildInfo.module
|
504
|
+
? getSourceForCommonJsExternalInNodeModule(request)
|
505
|
+
: getSourceForCommonJsExternal(request);
|
363
506
|
case "amd":
|
364
507
|
case "amd-require":
|
365
508
|
case "umd":
|
@@ -377,12 +520,28 @@ class ExternalModule extends Module {
|
|
377
520
|
case "script":
|
378
521
|
return getSourceForScriptExternal(request, runtimeTemplate);
|
379
522
|
case "module":
|
523
|
+
if (!this.buildInfo.module) {
|
524
|
+
if (!runtimeTemplate.supportsDynamicImport()) {
|
525
|
+
throw new Error(
|
526
|
+
"The target environment doesn't support dynamic import() syntax so it's not possible to use external type 'module' within a script" +
|
527
|
+
(runtimeTemplate.supportsEcmaScriptModuleSyntax()
|
528
|
+
? "\nDid you mean to build a EcmaScript Module ('output.module: true')?"
|
529
|
+
: "")
|
530
|
+
);
|
531
|
+
}
|
532
|
+
return getSourceForImportExternal(request, runtimeTemplate);
|
533
|
+
}
|
380
534
|
if (!runtimeTemplate.supportsEcmaScriptModuleSyntax()) {
|
381
535
|
throw new Error(
|
382
536
|
"The target environment doesn't support EcmaScriptModule syntax so it's not possible to use external type 'module'"
|
383
537
|
);
|
384
538
|
}
|
385
|
-
|
539
|
+
return getSourceForModuleExternal(
|
540
|
+
chunkGraph.getModuleId(this),
|
541
|
+
request,
|
542
|
+
moduleGraph.getExportsInfo(this),
|
543
|
+
runtime
|
544
|
+
);
|
386
545
|
case "var":
|
387
546
|
case "promise":
|
388
547
|
case "const":
|
@@ -405,12 +564,14 @@ class ExternalModule extends Module {
|
|
405
564
|
runtimeTemplate,
|
406
565
|
moduleGraph,
|
407
566
|
chunkGraph,
|
567
|
+
runtime,
|
408
568
|
concatenationScope
|
409
569
|
}) {
|
410
|
-
const sourceData = this.
|
570
|
+
const sourceData = this._getSourceData(
|
411
571
|
runtimeTemplate,
|
412
572
|
moduleGraph,
|
413
|
-
chunkGraph
|
573
|
+
chunkGraph,
|
574
|
+
runtime
|
414
575
|
);
|
415
576
|
|
416
577
|
let sourceString = sourceData.expression;
|
@@ -428,6 +589,12 @@ class ExternalModule extends Module {
|
|
428
589
|
}
|
429
590
|
if (sourceData.init) sourceString = `${sourceData.init}\n${sourceString}`;
|
430
591
|
|
592
|
+
let data = undefined;
|
593
|
+
if (sourceData.chunkInitFragments) {
|
594
|
+
data = new Map();
|
595
|
+
data.set("chunkInitFragments", sourceData.chunkInitFragments);
|
596
|
+
}
|
597
|
+
|
431
598
|
const sources = new Map();
|
432
599
|
if (this.useSourceMap || this.useSimpleSourceMap) {
|
433
600
|
sources.set(
|
@@ -438,13 +605,21 @@ class ExternalModule extends Module {
|
|
438
605
|
sources.set("javascript", new RawSource(sourceString));
|
439
606
|
}
|
440
607
|
|
608
|
+
let runtimeRequirements = sourceData.runtimeRequirements;
|
609
|
+
if (!concatenationScope) {
|
610
|
+
if (!runtimeRequirements) {
|
611
|
+
runtimeRequirements = RUNTIME_REQUIREMENTS;
|
612
|
+
} else {
|
613
|
+
const set = new Set(runtimeRequirements);
|
614
|
+
set.add(RuntimeGlobals.module);
|
615
|
+
runtimeRequirements = set;
|
616
|
+
}
|
617
|
+
}
|
618
|
+
|
441
619
|
return {
|
442
620
|
sources,
|
443
|
-
runtimeRequirements:
|
444
|
-
|
445
|
-
: this.externalType === "script"
|
446
|
-
? RUNTIME_REQUIREMENTS_FOR_SCRIPT
|
447
|
-
: RUNTIME_REQUIREMENTS
|
621
|
+
runtimeRequirements: runtimeRequirements || EMPTY_RUNTIME_REQUIREMENTS,
|
622
|
+
data
|
448
623
|
};
|
449
624
|
}
|
450
625
|
|
@@ -172,13 +172,14 @@ class ExternalModuleFactoryPlugin {
|
|
172
172
|
cb
|
173
173
|
);
|
174
174
|
} else {
|
175
|
+
const dependencyType = dependency.category || "";
|
175
176
|
const promise = externals(
|
176
177
|
{
|
177
178
|
context,
|
178
179
|
request: dependency.request,
|
180
|
+
dependencyType,
|
179
181
|
contextInfo,
|
180
182
|
getResolve: options => (context, request, callback) => {
|
181
|
-
const dependencyType = dependency.category || "";
|
182
183
|
const resolveContext = {
|
183
184
|
fileDependencies: data.fileDependencies,
|
184
185
|
missingDependencies: data.missingDependencies,
|
package/lib/InitFragment.js
CHANGED
@@ -30,6 +30,9 @@ const sortFragmentWithIndex = ([a, i], [b, j]) => {
|
|
30
30
|
return i - j;
|
31
31
|
};
|
32
32
|
|
33
|
+
/**
|
34
|
+
* @template Context
|
35
|
+
*/
|
33
36
|
class InitFragment {
|
34
37
|
/**
|
35
38
|
* @param {string|Source} content the source code that will be included as initialization code
|
@@ -47,22 +50,22 @@ class InitFragment {
|
|
47
50
|
}
|
48
51
|
|
49
52
|
/**
|
50
|
-
* @param {
|
53
|
+
* @param {Context} context context
|
51
54
|
* @returns {string|Source} the source code that will be included as initialization code
|
52
55
|
*/
|
53
|
-
getContent(
|
56
|
+
getContent(context) {
|
54
57
|
return this.content;
|
55
58
|
}
|
56
59
|
|
57
60
|
/**
|
58
|
-
* @param {
|
61
|
+
* @param {Context} context context
|
59
62
|
* @returns {string|Source=} the source code that will be included at the end of the module
|
60
63
|
*/
|
61
|
-
getEndContent(
|
64
|
+
getEndContent(context) {
|
62
65
|
return this.endContent;
|
63
66
|
}
|
64
67
|
|
65
|
-
static addToSource(source, initFragments,
|
68
|
+
static addToSource(source, initFragments, context) {
|
66
69
|
if (initFragments.length > 0) {
|
67
70
|
// Sort fragments by position. If 2 fragments have the same position,
|
68
71
|
// use their index.
|
@@ -104,8 +107,8 @@ class InitFragment {
|
|
104
107
|
if (Array.isArray(fragment)) {
|
105
108
|
fragment = fragment[0].mergeAll(fragment);
|
106
109
|
}
|
107
|
-
concatSource.add(fragment.getContent(
|
108
|
-
const endContent = fragment.getEndContent(
|
110
|
+
concatSource.add(fragment.getContent(context));
|
111
|
+
const endContent = fragment.getEndContent(context);
|
109
112
|
if (endContent) {
|
110
113
|
endContents.push(endContent);
|
111
114
|
}
|
package/lib/MainTemplate.js
CHANGED
@@ -20,7 +20,7 @@ const memoize = require("./util/memoize");
|
|
20
20
|
/** @typedef {import("./Module")} Module} */
|
21
21
|
/** @typedef {import("./util/Hash")} Hash} */
|
22
22
|
/** @typedef {import("./DependencyTemplates")} DependencyTemplates} */
|
23
|
-
/** @typedef {import("./
|
23
|
+
/** @typedef {import("./javascript/JavascriptModulesPlugin").RenderContext} RenderContext} */
|
24
24
|
/** @typedef {import("./RuntimeTemplate")} RuntimeTemplate} */
|
25
25
|
/** @typedef {import("./ModuleGraph")} ModuleGraph} */
|
26
26
|
/** @typedef {import("./ChunkGraph")} ChunkGraph} */
|
package/lib/ModuleTemplate.js
CHANGED
@@ -22,15 +22,6 @@ const getJavascriptModulesPlugin = memoize(() =>
|
|
22
22
|
require("./javascript/JavascriptModulesPlugin")
|
23
23
|
);
|
24
24
|
|
25
|
-
/**
|
26
|
-
* @typedef {Object} RenderContext
|
27
|
-
* @property {Chunk} chunk the chunk
|
28
|
-
* @property {DependencyTemplates} dependencyTemplates the dependency templates
|
29
|
-
* @property {RuntimeTemplate} runtimeTemplate the runtime template
|
30
|
-
* @property {ModuleGraph} moduleGraph the module graph
|
31
|
-
* @property {ChunkGraph} chunkGraph the chunk graph
|
32
|
-
*/
|
33
|
-
|
34
25
|
// TODO webpack 6: remove this class
|
35
26
|
class ModuleTemplate {
|
36
27
|
/**
|
package/lib/RuntimeTemplate.js
CHANGED
@@ -133,6 +133,14 @@ class RuntimeTemplate {
|
|
133
133
|
);
|
134
134
|
}
|
135
135
|
|
136
|
+
destructureObject(items, value) {
|
137
|
+
return this.supportsDestructuring()
|
138
|
+
? `var {${items.join(", ")}} = ${value};`
|
139
|
+
: Template.asString(
|
140
|
+
items.map(item => `var ${item} = ${value}${propertyAccess([item])};`)
|
141
|
+
);
|
142
|
+
}
|
143
|
+
|
136
144
|
iife(args, body) {
|
137
145
|
return `(${this.basicFunction(args, body)})()`;
|
138
146
|
}
|
package/lib/Template.js
CHANGED
@@ -18,9 +18,10 @@ const { ConcatSource, PrefixSource } = require("webpack-sources");
|
|
18
18
|
/** @typedef {import("./Module")} Module */
|
19
19
|
/** @typedef {import("./ModuleGraph")} ModuleGraph */
|
20
20
|
/** @typedef {import("./ModuleTemplate")} ModuleTemplate */
|
21
|
-
/** @typedef {import("./ModuleTemplate").RenderContext} RenderContext */
|
22
21
|
/** @typedef {import("./RuntimeModule")} RuntimeModule */
|
23
22
|
/** @typedef {import("./RuntimeTemplate")} RuntimeTemplate */
|
23
|
+
/** @typedef {import("./javascript/JavascriptModulesPlugin").ChunkRenderContext} ChunkRenderContext */
|
24
|
+
/** @typedef {import("./javascript/JavascriptModulesPlugin").RenderContext} RenderContext */
|
24
25
|
|
25
26
|
const START_LOWERCASE_ALPHABET_CODE = "a".charCodeAt(0);
|
26
27
|
const START_UPPERCASE_ALPHABET_CODE = "A".charCodeAt(0);
|
@@ -283,7 +284,7 @@ class Template {
|
|
283
284
|
}
|
284
285
|
|
285
286
|
/**
|
286
|
-
* @param {
|
287
|
+
* @param {ChunkRenderContext} renderContext render context
|
287
288
|
* @param {Module[]} modules modules to render (should be ordered by identifier)
|
288
289
|
* @param {function(Module): Source} renderModule function to render a module
|
289
290
|
* @param {string=} prefix applying prefix strings
|
@@ -116,32 +116,30 @@ const replacePathVariables = (path, data, assetInfo) => {
|
|
116
116
|
// [path] - /some/path/
|
117
117
|
// [name] - file
|
118
118
|
// [ext] - .js
|
119
|
-
if (data.filename) {
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
);
|
144
|
-
}
|
119
|
+
if (typeof data.filename === "string") {
|
120
|
+
const { path: file, query, fragment } = parseResource(data.filename);
|
121
|
+
|
122
|
+
const ext = extname(file);
|
123
|
+
const base = basename(file);
|
124
|
+
const name = base.slice(0, base.length - ext.length);
|
125
|
+
const path = file.slice(0, file.length - base.length);
|
126
|
+
|
127
|
+
replacements.set("file", replacer(file));
|
128
|
+
replacements.set("query", replacer(query, true));
|
129
|
+
replacements.set("fragment", replacer(fragment, true));
|
130
|
+
replacements.set("path", replacer(path, true));
|
131
|
+
replacements.set("base", replacer(base));
|
132
|
+
replacements.set("name", replacer(name));
|
133
|
+
replacements.set("ext", replacer(ext, true));
|
134
|
+
// Legacy
|
135
|
+
replacements.set(
|
136
|
+
"filebase",
|
137
|
+
deprecated(
|
138
|
+
replacer(base),
|
139
|
+
"[filebase] is now [base]",
|
140
|
+
"DEP_WEBPACK_TEMPLATE_PATH_PLUGIN_REPLACE_PATH_VARIABLES_FILENAME"
|
141
|
+
)
|
142
|
+
);
|
145
143
|
}
|
146
144
|
|
147
145
|
// Compilation context
|
package/lib/Watching.js
CHANGED
@@ -86,7 +86,7 @@ class Watching {
|
|
86
86
|
|
87
87
|
_go(fileTimeInfoEntries, contextTimeInfoEntries, changedFiles, removedFiles) {
|
88
88
|
this._initial = false;
|
89
|
-
this.startTime = Date.now();
|
89
|
+
if (this.startTime === null) this.startTime = Date.now();
|
90
90
|
this.running = true;
|
91
91
|
if (this.watcher) {
|
92
92
|
this.pausedWatcher = this.watcher;
|
@@ -252,6 +252,7 @@ class Watching {
|
|
252
252
|
compilation.endTime = Date.now();
|
253
253
|
stats = new Stats(compilation);
|
254
254
|
}
|
255
|
+
this.startTime = null;
|
255
256
|
if (err) return handleError(err);
|
256
257
|
|
257
258
|
const cbs = this.callbacks;
|
@@ -113,7 +113,7 @@ class WebpackOptionsApply extends OptionsApply {
|
|
113
113
|
if (options.externalsPresets.nwjs) {
|
114
114
|
//@ts-expect-error https://github.com/microsoft/TypeScript/issues/41697
|
115
115
|
const ExternalsPlugin = require("./ExternalsPlugin");
|
116
|
-
new ExternalsPlugin("commonjs", "nw.gui").apply(compiler);
|
116
|
+
new ExternalsPlugin("node-commonjs", "nw.gui").apply(compiler);
|
117
117
|
}
|
118
118
|
if (options.externalsPresets.webAsync) {
|
119
119
|
//@ts-expect-error https://github.com/microsoft/TypeScript/issues/41697
|
@@ -139,10 +139,11 @@ class WebpackOptionsApply extends OptionsApply {
|
|
139
139
|
new CommonJsChunkFormatPlugin().apply(compiler);
|
140
140
|
break;
|
141
141
|
}
|
142
|
-
case "module":
|
143
|
-
|
144
|
-
|
145
|
-
|
142
|
+
case "module": {
|
143
|
+
const ModuleChunkFormatPlugin = require("./esm/ModuleChunkFormatPlugin");
|
144
|
+
new ModuleChunkFormatPlugin().apply(compiler);
|
145
|
+
break;
|
146
|
+
}
|
146
147
|
default:
|
147
148
|
throw new Error(
|
148
149
|
"Unsupported chunk format '" + options.output.chunkFormat + "'."
|
@@ -317,7 +318,8 @@ class WebpackOptionsApply extends OptionsApply {
|
|
317
318
|
new URLPlugin().apply(compiler);
|
318
319
|
new WorkerPlugin(
|
319
320
|
options.output.workerChunkLoading,
|
320
|
-
options.output.workerWasmLoading
|
321
|
+
options.output.workerWasmLoading,
|
322
|
+
options.output.module
|
321
323
|
).apply(compiler);
|
322
324
|
|
323
325
|
new DefaultStatsFactoryPlugin().apply(compiler);
|
@@ -573,7 +575,8 @@ class WebpackOptionsApply extends OptionsApply {
|
|
573
575
|
allowCollectingMemory: cacheOptions.allowCollectingMemory
|
574
576
|
}),
|
575
577
|
cacheOptions.idleTimeout,
|
576
|
-
cacheOptions.idleTimeoutForInitialStore
|
578
|
+
cacheOptions.idleTimeoutForInitialStore,
|
579
|
+
cacheOptions.idleTimeoutAfterLargeChanges
|
577
580
|
).apply(compiler);
|
578
581
|
break;
|
579
582
|
}
|
@@ -12,6 +12,9 @@ const Template = require("../Template");
|
|
12
12
|
/** @typedef {import("webpack-sources").Source} Source */
|
13
13
|
/** @typedef {import("../Generator").GenerateContext} GenerateContext */
|
14
14
|
|
15
|
+
/**
|
16
|
+
* @typedef {GenerateContext} Context
|
17
|
+
*/
|
15
18
|
class AwaitDependenciesInitFragment extends InitFragment {
|
16
19
|
/**
|
17
20
|
* @param {Set<string>} promises the promises that should be awaited
|
@@ -35,7 +38,7 @@ class AwaitDependenciesInitFragment extends InitFragment {
|
|
35
38
|
}
|
36
39
|
|
37
40
|
/**
|
38
|
-
* @param {
|
41
|
+
* @param {Context} context context
|
39
42
|
* @returns {string|Source} the source code that will be included as initialization code
|
40
43
|
*/
|
41
44
|
getContent({ runtimeRequirements }) {
|