webpack 5.83.1 → 5.84.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.
Potentially problematic release.
This version of webpack might be problematic. Click here for more details.
- package/README.md +2 -2
- package/lib/CompatibilityPlugin.js +3 -2
- package/lib/Compilation.js +2 -2
- package/lib/ContextModule.js +3 -3
- package/lib/DefinePlugin.js +11 -2
- package/lib/DllEntryPlugin.js +5 -0
- package/lib/DllModule.js +1 -1
- package/lib/EvalSourceMapDevToolPlugin.js +3 -1
- package/lib/MainTemplate.js +2 -2
- package/lib/PrefetchPlugin.js +4 -0
- package/lib/RuntimeTemplate.js +5 -5
- package/lib/SelfModuleFactory.js +12 -0
- package/lib/SourceMapDevToolPlugin.js +9 -2
- package/lib/Template.js +2 -1
- package/lib/config/browserslistTargetHandler.js +3 -3
- package/lib/config/defaults.js +209 -70
- package/lib/config/normalization.js +103 -71
- package/lib/config/target.js +37 -10
- package/lib/container/FallbackModule.js +1 -1
- package/lib/container/RemoteRuntimeModule.js +1 -1
- package/lib/css/CssParser.js +168 -73
- package/lib/debug/ProfilingPlugin.js +11 -0
- package/lib/dependencies/AMDDefineDependency.js +12 -6
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +8 -2
- package/lib/dependencies/AMDPlugin.js +7 -0
- package/lib/dependencies/AMDRequireArrayDependency.js +5 -0
- package/lib/dependencies/AMDRequireContextDependency.js +6 -0
- package/lib/dependencies/AMDRequireDependenciesBlock.js +6 -0
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +8 -2
- package/lib/dependencies/AMDRequireDependency.js +8 -1
- package/lib/dependencies/AMDRequireItemDependency.js +6 -0
- package/lib/dependencies/CachedConstDependency.js +6 -0
- package/lib/dependencies/CommonJsExportRequireDependency.js +11 -0
- package/lib/dependencies/CommonJsExportsDependency.js +8 -0
- package/lib/dependencies/CommonJsExportsParserPlugin.js +2 -2
- package/lib/dependencies/CommonJsFullRequireDependency.js +2 -1
- package/lib/dependencies/CommonJsPlugin.js +14 -0
- package/lib/dependencies/CommonJsRequireContextDependency.js +8 -0
- package/lib/dependencies/CommonJsRequireDependency.js +7 -0
- package/lib/dependencies/CommonJsSelfReferenceDependency.js +8 -0
- package/lib/dependencies/ConstDependency.js +2 -1
- package/lib/dependencies/ContextDependencyHelpers.js +3 -3
- package/lib/dependencies/CreateScriptUrlDependency.js +2 -1
- package/lib/dependencies/CriticalDependencyWarning.js +3 -0
- package/lib/dependencies/CssImportDependency.js +2 -1
- package/lib/dependencies/CssLocalIdentifierDependency.js +2 -1
- package/lib/dependencies/CssSelfLocalIdentifierDependency.js +2 -1
- package/lib/dependencies/CssUrlDependency.js +12 -2
- package/lib/dependencies/DelegatedSourceDependency.js +3 -0
- package/lib/dependencies/ExportsInfoDependency.js +6 -0
- package/lib/dependencies/HarmonyAcceptDependency.js +2 -1
- package/lib/dependencies/HarmonyAcceptImportDependency.js +3 -0
- package/lib/dependencies/HarmonyDetectionParserPlugin.js +16 -0
- package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +11 -0
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +3 -0
- package/lib/dependencies/HarmonyExportExpressionDependency.js +8 -0
- package/lib/dependencies/HarmonyExportHeaderDependency.js +5 -0
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +2 -1
- package/lib/dependencies/HarmonyExportSpecifierDependency.js +4 -0
- package/lib/dependencies/HarmonyImportDependency.js +2 -1
- package/lib/dependencies/HarmonyImportSideEffectDependency.js +6 -0
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +11 -0
- package/lib/dependencies/HarmonyModulesPlugin.js +12 -0
- package/lib/dependencies/ImportContextDependency.js +6 -0
- package/lib/dependencies/ImportDependency.js +2 -1
- package/lib/dependencies/ImportEagerDependency.js +2 -1
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +32 -13
- package/lib/dependencies/ImportMetaContextPlugin.js +7 -0
- package/lib/dependencies/ImportMetaHotAcceptDependency.js +6 -0
- package/lib/dependencies/ImportMetaHotDeclineDependency.js +6 -0
- package/lib/dependencies/ImportParserPlugin.js +5 -0
- package/lib/dependencies/ImportPlugin.js +7 -0
- package/lib/dependencies/ImportWeakDependency.js +2 -1
- package/lib/dependencies/LocalModule.js +16 -0
- package/lib/dependencies/LocalModuleDependency.js +7 -0
- package/lib/dependencies/LocalModulesHelpers.js +18 -0
- package/lib/dependencies/ModuleHotAcceptDependency.js +6 -0
- package/lib/dependencies/ModuleHotDeclineDependency.js +6 -0
- package/lib/dependencies/PrefetchDependency.js +3 -0
- package/lib/dependencies/ProvidedDependency.js +2 -1
- package/lib/dependencies/PureExpressionDependency.js +2 -1
- package/lib/dependencies/RequireContextDependency.js +6 -0
- package/lib/dependencies/RequireContextPlugin.js +7 -0
- package/lib/dependencies/RequireEnsureDependenciesBlock.js +4 -0
- package/lib/dependencies/RequireEnsureDependency.js +8 -2
- package/lib/dependencies/RequireEnsureItemDependency.js +3 -0
- package/lib/dependencies/RequireEnsurePlugin.js +14 -0
- package/lib/dependencies/RequireHeaderDependency.js +5 -1
- package/lib/dependencies/RequireIncludeDependency.js +5 -0
- package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +3 -0
- package/lib/dependencies/RequireIncludePlugin.js +14 -0
- package/lib/dependencies/RequireResolveContextDependency.js +8 -0
- package/lib/dependencies/RequireResolveDependency.js +6 -0
- package/lib/dependencies/RequireResolveHeaderDependency.js +4 -0
- package/lib/dependencies/SystemPlugin.js +10 -1
- package/lib/dependencies/URLDependency.js +3 -2
- package/lib/dependencies/URLPlugin.js +7 -5
- package/lib/dependencies/UnsupportedDependency.js +5 -0
- package/lib/dependencies/WebAssemblyExportImportedDependency.js +6 -0
- package/lib/dependencies/WebpackIsIncludedDependency.js +5 -0
- package/lib/dependencies/WorkerDependency.js +2 -1
- package/lib/dependencies/WorkerPlugin.js +5 -2
- package/lib/dependencies/getFunctionExpression.js +7 -0
- package/lib/esm/ExportWebpackRequireRuntimeModule.js +2 -1
- package/lib/esm/ModuleChunkFormatPlugin.js +2 -2
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +5 -2
- package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +2 -2
- package/lib/javascript/CommonJsChunkFormatPlugin.js +1 -1
- package/lib/javascript/JavascriptModulesPlugin.js +13 -13
- package/lib/javascript/JavascriptParser.js +540 -180
- package/lib/javascript/StartupHelpers.js +1 -1
- package/lib/node/ReadFileChunkLoadingRuntimeModule.js +2 -2
- package/lib/node/RequireChunkLoadingRuntimeModule.js +2 -2
- package/lib/optimize/ConcatenatedModule.js +1 -1
- package/lib/optimize/InnerGraphPlugin.js +11 -4
- package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +1 -1
- package/lib/runtime/StartupEntrypointRuntimeModule.js +5 -5
- package/lib/serialization/ArraySerializer.js +22 -6
- package/lib/serialization/BinaryMiddleware.js +21 -0
- package/lib/serialization/DateObjectSerializer.js +15 -4
- package/lib/serialization/ErrorObjectSerializer.js +20 -8
- package/lib/serialization/FileMiddleware.js +17 -0
- package/lib/serialization/MapObjectSerializer.js +24 -8
- package/lib/serialization/NullPrototypeObjectSerializer.js +25 -8
- package/lib/serialization/ObjectMiddleware.js +23 -0
- package/lib/serialization/PlainObjectSerializer.js +23 -12
- package/lib/serialization/RegExpObjectSerializer.js +16 -5
- package/lib/serialization/SetObjectSerializer.js +21 -6
- package/lib/sharing/ShareRuntimeModule.js +1 -1
- package/lib/util/makeSerializable.js +7 -0
- package/lib/util/serialization.js +10 -0
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +4 -1
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +5 -1
- package/package.json +3 -3
- package/schemas/plugins/SourceMapDevToolPlugin.check.js +1 -1
- package/schemas/plugins/SourceMapDevToolPlugin.json +4 -0
- package/types.d.ts +469 -149
package/lib/config/defaults.js
CHANGED
@@ -25,30 +25,39 @@ const {
|
|
25
25
|
} = require("./target");
|
26
26
|
|
27
27
|
/** @typedef {import("../../declarations/WebpackOptions").CacheOptionsNormalized} CacheOptions */
|
28
|
+
/** @typedef {import("../../declarations/WebpackOptions").Context} Context */
|
28
29
|
/** @typedef {import("../../declarations/WebpackOptions").CssExperimentOptions} CssExperimentOptions */
|
29
30
|
/** @typedef {import("../../declarations/WebpackOptions").EntryDescription} EntryDescription */
|
30
31
|
/** @typedef {import("../../declarations/WebpackOptions").EntryNormalized} Entry */
|
32
|
+
/** @typedef {import("../../declarations/WebpackOptions").EntryStaticNormalized} EntryStaticNormalized */
|
33
|
+
/** @typedef {import("../../declarations/WebpackOptions").Environment} Environment */
|
31
34
|
/** @typedef {import("../../declarations/WebpackOptions").Experiments} Experiments */
|
32
35
|
/** @typedef {import("../../declarations/WebpackOptions").ExperimentsNormalized} ExperimentsNormalized */
|
33
36
|
/** @typedef {import("../../declarations/WebpackOptions").ExternalsPresets} ExternalsPresets */
|
34
37
|
/** @typedef {import("../../declarations/WebpackOptions").ExternalsType} ExternalsType */
|
38
|
+
/** @typedef {import("../../declarations/WebpackOptions").FileCacheOptions} FileCacheOptions */
|
35
39
|
/** @typedef {import("../../declarations/WebpackOptions").InfrastructureLogging} InfrastructureLogging */
|
36
40
|
/** @typedef {import("../../declarations/WebpackOptions").JavascriptParserOptions} JavascriptParserOptions */
|
37
41
|
/** @typedef {import("../../declarations/WebpackOptions").Library} Library */
|
38
42
|
/** @typedef {import("../../declarations/WebpackOptions").LibraryName} LibraryName */
|
39
43
|
/** @typedef {import("../../declarations/WebpackOptions").LibraryOptions} LibraryOptions */
|
44
|
+
/** @typedef {import("../../declarations/WebpackOptions").LibraryType} LibraryType */
|
40
45
|
/** @typedef {import("../../declarations/WebpackOptions").Loader} Loader */
|
41
46
|
/** @typedef {import("../../declarations/WebpackOptions").Mode} Mode */
|
42
47
|
/** @typedef {import("../../declarations/WebpackOptions").ModuleOptionsNormalized} ModuleOptions */
|
43
48
|
/** @typedef {import("../../declarations/WebpackOptions").Node} WebpackNode */
|
44
49
|
/** @typedef {import("../../declarations/WebpackOptions").Optimization} Optimization */
|
50
|
+
/** @typedef {import("../../declarations/WebpackOptions").OptimizationSplitChunksOptions} OptimizationSplitChunksOptions */
|
45
51
|
/** @typedef {import("../../declarations/WebpackOptions").OutputNormalized} Output */
|
52
|
+
/** @typedef {import("../../declarations/WebpackOptions").ParserOptionsByModuleTypeKnown} ParserOptionsByModuleTypeKnown */
|
46
53
|
/** @typedef {import("../../declarations/WebpackOptions").Performance} Performance */
|
47
54
|
/** @typedef {import("../../declarations/WebpackOptions").ResolveOptions} ResolveOptions */
|
48
55
|
/** @typedef {import("../../declarations/WebpackOptions").RuleSetRules} RuleSetRules */
|
49
56
|
/** @typedef {import("../../declarations/WebpackOptions").SnapshotOptions} SnapshotOptions */
|
50
57
|
/** @typedef {import("../../declarations/WebpackOptions").Target} Target */
|
51
58
|
/** @typedef {import("../../declarations/WebpackOptions").WebpackOptionsNormalized} WebpackOptions */
|
59
|
+
/** @typedef {import("../Compiler")} Compiler */
|
60
|
+
/** @typedef {import("../Module")} Module */
|
52
61
|
/** @typedef {import("./target").TargetProperties} TargetProperties */
|
53
62
|
|
54
63
|
const NODE_MODULES_REGEXP = /[\\/]node_modules[\\/]/i;
|
@@ -100,7 +109,7 @@ const A = (obj, prop, factory) => {
|
|
100
109
|
if (value === undefined) {
|
101
110
|
obj[prop] = factory();
|
102
111
|
} else if (Array.isArray(value)) {
|
103
|
-
/** @type {any[]} */
|
112
|
+
/** @type {any[] | undefined} */
|
104
113
|
let newArray = undefined;
|
105
114
|
for (let i = 0; i < value.length; i++) {
|
106
115
|
const item = value[i];
|
@@ -138,7 +147,7 @@ const applyWebpackOptionsBaseDefaults = options => {
|
|
138
147
|
const applyWebpackOptionsDefaults = options => {
|
139
148
|
F(options, "context", () => process.cwd());
|
140
149
|
F(options, "target", () => {
|
141
|
-
return getDefaultTarget(options.context);
|
150
|
+
return getDefaultTarget(/** @type {string} */ (options.context));
|
142
151
|
});
|
143
152
|
|
144
153
|
const { mode, name, target } = options;
|
@@ -147,8 +156,11 @@ const applyWebpackOptionsDefaults = options => {
|
|
147
156
|
target === false
|
148
157
|
? /** @type {false} */ (false)
|
149
158
|
: typeof target === "string"
|
150
|
-
? getTargetProperties(target, options.context)
|
151
|
-
: getTargetsProperties(
|
159
|
+
? getTargetProperties(target, /** @type {Context} */ (options.context))
|
160
|
+
: getTargetsProperties(
|
161
|
+
/** @type {string[]} */ (target),
|
162
|
+
/** @type {Context} */ (options.context)
|
163
|
+
);
|
152
164
|
|
153
165
|
const development = mode === "development";
|
154
166
|
const production = mode === "production" || !mode;
|
@@ -176,7 +188,9 @@ const applyWebpackOptionsDefaults = options => {
|
|
176
188
|
targetProperties
|
177
189
|
});
|
178
190
|
|
179
|
-
const futureDefaults =
|
191
|
+
const futureDefaults =
|
192
|
+
/** @type {NonNullable<ExperimentsNormalized["futureDefaults"]>} */
|
193
|
+
(options.experiments.futureDefaults);
|
180
194
|
|
181
195
|
F(options, "cache", () =>
|
182
196
|
development ? { type: /** @type {"memory"} */ ("memory") } : false
|
@@ -196,22 +210,30 @@ const applyWebpackOptionsDefaults = options => {
|
|
196
210
|
|
197
211
|
applyModuleDefaults(options.module, {
|
198
212
|
cache,
|
199
|
-
syncWebAssembly:
|
200
|
-
|
201
|
-
|
213
|
+
syncWebAssembly:
|
214
|
+
/** @type {NonNullable<ExperimentsNormalized["syncWebAssembly"]>} */
|
215
|
+
(options.experiments.syncWebAssembly),
|
216
|
+
asyncWebAssembly:
|
217
|
+
/** @type {NonNullable<ExperimentsNormalized["asyncWebAssembly"]>} */
|
218
|
+
(options.experiments.asyncWebAssembly),
|
219
|
+
css:
|
220
|
+
/** @type {NonNullable<ExperimentsNormalized["css"]>} */
|
221
|
+
(options.experiments.css),
|
202
222
|
futureDefaults,
|
203
223
|
isNode: targetProperties && targetProperties.node === true
|
204
224
|
});
|
205
225
|
|
206
226
|
applyOutputDefaults(options.output, {
|
207
|
-
context: options.context,
|
227
|
+
context: /** @type {Context} */ (options.context),
|
208
228
|
targetProperties,
|
209
229
|
isAffectedByBrowserslist:
|
210
230
|
target === undefined ||
|
211
231
|
(typeof target === "string" && target.startsWith("browserslist")) ||
|
212
232
|
(Array.isArray(target) &&
|
213
233
|
target.some(target => target.startsWith("browserslist"))),
|
214
|
-
outputModule:
|
234
|
+
outputModule:
|
235
|
+
/** @type {NonNullable<ExperimentsNormalized["outputModule"]>} */
|
236
|
+
(options.experiments.outputModule),
|
215
237
|
development,
|
216
238
|
entry: options.entry,
|
217
239
|
module: options.module,
|
@@ -223,7 +245,10 @@ const applyWebpackOptionsDefaults = options => {
|
|
223
245
|
buildHttp: !!options.experiments.buildHttp
|
224
246
|
});
|
225
247
|
|
226
|
-
applyLoaderDefaults(
|
248
|
+
applyLoaderDefaults(
|
249
|
+
/** @type {NonNullable<WebpackOptions["loader"]>} */ (options.loader),
|
250
|
+
{ targetProperties }
|
251
|
+
);
|
227
252
|
|
228
253
|
F(options, "externalsType", () => {
|
229
254
|
const validExternalTypes = require("../../schemas/WebpackOptions.json")
|
@@ -237,7 +262,9 @@ const applyWebpackOptionsDefaults = options => {
|
|
237
262
|
});
|
238
263
|
|
239
264
|
applyNodeDefaults(options.node, {
|
240
|
-
futureDefaults:
|
265
|
+
futureDefaults:
|
266
|
+
/** @type {NonNullable<WebpackOptions["experiments"]["futureDefaults"]>} */
|
267
|
+
(options.experiments.futureDefaults),
|
241
268
|
targetProperties
|
242
269
|
});
|
243
270
|
|
@@ -248,23 +275,29 @@ const applyWebpackOptionsDefaults = options => {
|
|
248
275
|
? {}
|
249
276
|
: false
|
250
277
|
);
|
251
|
-
applyPerformanceDefaults(
|
252
|
-
|
253
|
-
|
278
|
+
applyPerformanceDefaults(
|
279
|
+
/** @type {NonNullable<WebpackOptions["performance"]>} */
|
280
|
+
(options.performance),
|
281
|
+
{
|
282
|
+
production
|
283
|
+
}
|
284
|
+
);
|
254
285
|
|
255
286
|
applyOptimizationDefaults(options.optimization, {
|
256
287
|
development,
|
257
288
|
production,
|
258
|
-
css:
|
289
|
+
css:
|
290
|
+
/** @type {NonNullable<ExperimentsNormalized["css"]>} */
|
291
|
+
(options.experiments.css),
|
259
292
|
records: !!(options.recordsInputPath || options.recordsOutputPath)
|
260
293
|
});
|
261
294
|
|
262
295
|
options.resolve = cleverMerge(
|
263
296
|
getResolveDefaults({
|
264
297
|
cache,
|
265
|
-
context: options.context,
|
298
|
+
context: /** @type {Context} */ (options.context),
|
266
299
|
targetProperties,
|
267
|
-
mode: options.mode
|
300
|
+
mode: /** @type {Mode} */ (options.mode)
|
268
301
|
}),
|
269
302
|
options.resolve
|
270
303
|
);
|
@@ -323,9 +356,9 @@ const applyExperimentsDefaults = (
|
|
323
356
|
* @param {CacheOptions} cache options
|
324
357
|
* @param {Object} options options
|
325
358
|
* @param {string} options.name name
|
326
|
-
* @param {
|
359
|
+
* @param {Mode} options.mode mode
|
327
360
|
* @param {boolean} options.development is development mode
|
328
|
-
* @param {
|
361
|
+
* @param {Experiments["cacheUnaffected"]} options.cacheUnaffected the cacheUnaffected experiment is enabled
|
329
362
|
* @returns {void}
|
330
363
|
*/
|
331
364
|
const applyCacheDefaults = (
|
@@ -339,6 +372,7 @@ const applyCacheDefaults = (
|
|
339
372
|
D(cache, "version", "");
|
340
373
|
F(cache, "cacheDirectory", () => {
|
341
374
|
const cwd = process.cwd();
|
375
|
+
/** @type {string | undefined} */
|
342
376
|
let dir = cwd;
|
343
377
|
for (;;) {
|
344
378
|
try {
|
@@ -363,7 +397,11 @@ const applyCacheDefaults = (
|
|
363
397
|
}
|
364
398
|
});
|
365
399
|
F(cache, "cacheLocation", () =>
|
366
|
-
path.resolve(
|
400
|
+
path.resolve(
|
401
|
+
/** @type {NonNullable<FileCacheOptions["cacheDirectory"]>} */
|
402
|
+
(cache.cacheDirectory),
|
403
|
+
/** @type {NonNullable<FileCacheOptions["name"]>} */ (cache.name)
|
404
|
+
)
|
367
405
|
);
|
368
406
|
D(cache, "hashAlgorithm", "md4");
|
369
407
|
D(cache, "store", "pack");
|
@@ -376,9 +414,12 @@ const applyCacheDefaults = (
|
|
376
414
|
D(cache, "maxAge", 1000 * 60 * 60 * 24 * 60); // 1 month
|
377
415
|
D(cache, "allowCollectingMemory", development);
|
378
416
|
D(cache, "memoryCacheUnaffected", development && cacheUnaffected);
|
379
|
-
D(
|
380
|
-
|
381
|
-
|
417
|
+
D(
|
418
|
+
/** @type {NonNullable<FileCacheOptions["buildDependencies"]>} */
|
419
|
+
(cache.buildDependencies),
|
420
|
+
"defaultWebpack",
|
421
|
+
[path.resolve(__dirname, "..") + path.sep]
|
422
|
+
);
|
382
423
|
break;
|
383
424
|
case "memory":
|
384
425
|
D(cache, "maxGenerations", Infinity);
|
@@ -510,25 +551,53 @@ const applyModuleDefaults = (
|
|
510
551
|
{ cache, syncWebAssembly, asyncWebAssembly, css, futureDefaults, isNode }
|
511
552
|
) => {
|
512
553
|
if (cache) {
|
513
|
-
D(
|
514
|
-
|
515
|
-
|
516
|
-
|
554
|
+
D(
|
555
|
+
module,
|
556
|
+
"unsafeCache",
|
557
|
+
/**
|
558
|
+
* @param {Module} module module
|
559
|
+
* @returns {boolean | null | string} true, if we want to cache the module
|
560
|
+
*/
|
561
|
+
module => {
|
562
|
+
const name = module.nameForCondition();
|
563
|
+
return name && NODE_MODULES_REGEXP.test(name);
|
564
|
+
}
|
565
|
+
);
|
517
566
|
} else {
|
518
567
|
D(module, "unsafeCache", false);
|
519
568
|
}
|
520
569
|
|
521
570
|
F(module.parser, ASSET_MODULE_TYPE, () => ({}));
|
522
|
-
F(
|
523
|
-
|
524
|
-
|
571
|
+
F(
|
572
|
+
/** @type {NonNullable<ParserOptionsByModuleTypeKnown["asset"]>} */
|
573
|
+
(module.parser.asset),
|
574
|
+
"dataUrlCondition",
|
575
|
+
() => ({})
|
576
|
+
);
|
577
|
+
if (
|
578
|
+
typeof (
|
579
|
+
/** @type {NonNullable<ParserOptionsByModuleTypeKnown["asset"]>} */
|
580
|
+
(module.parser.asset).dataUrlCondition
|
581
|
+
) === "object"
|
582
|
+
) {
|
583
|
+
D(
|
584
|
+
/** @type {NonNullable<ParserOptionsByModuleTypeKnown["asset"]>} */
|
585
|
+
(module.parser.asset).dataUrlCondition,
|
586
|
+
"maxSize",
|
587
|
+
8096
|
588
|
+
);
|
525
589
|
}
|
526
590
|
|
527
591
|
F(module.parser, "javascript", () => ({}));
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
592
|
+
|
593
|
+
applyJavascriptParserOptionsDefaults(
|
594
|
+
/** @type {NonNullable<ParserOptionsByModuleTypeKnown["javascript"]>} */
|
595
|
+
(module.parser.javascript),
|
596
|
+
{
|
597
|
+
futureDefaults,
|
598
|
+
isNode
|
599
|
+
}
|
600
|
+
);
|
532
601
|
|
533
602
|
A(module, "defaultRules", () => {
|
534
603
|
const esm = {
|
@@ -726,7 +795,7 @@ const applyOutputDefaults = (
|
|
726
795
|
!Array.isArray(library) &&
|
727
796
|
"type" in library
|
728
797
|
? library.name
|
729
|
-
: /** @type {LibraryName
|
798
|
+
: /** @type {LibraryName} */ (library);
|
730
799
|
if (Array.isArray(libraryName)) {
|
731
800
|
return libraryName.join(".");
|
732
801
|
} else if (typeof libraryName === "object") {
|
@@ -753,8 +822,11 @@ const applyOutputDefaults = (
|
|
753
822
|
const packageInfo = JSON.parse(fs.readFileSync(pkgPath, "utf-8"));
|
754
823
|
return packageInfo.name || "";
|
755
824
|
} catch (e) {
|
756
|
-
if (e.code !== "ENOENT") {
|
757
|
-
|
825
|
+
if (/** @type {Error & { code: string }} */ (e).code !== "ENOENT") {
|
826
|
+
/** @type {Error & { code: string }} */
|
827
|
+
(
|
828
|
+
e
|
829
|
+
).message += `\nwhile determining default 'output.uniqueName' from 'name' in ${pkgPath}`;
|
758
830
|
throw e;
|
759
831
|
}
|
760
832
|
return "";
|
@@ -767,7 +839,9 @@ const applyOutputDefaults = (
|
|
767
839
|
D(output, "importFunctionName", "import");
|
768
840
|
D(output, "importMetaName", "import.meta");
|
769
841
|
F(output, "chunkFilename", () => {
|
770
|
-
const filename =
|
842
|
+
const filename =
|
843
|
+
/** @type {NonNullable<Output["chunkFilename"]>} */
|
844
|
+
(output.filename);
|
771
845
|
if (typeof filename !== "function") {
|
772
846
|
const hasName = filename.includes("[name]");
|
773
847
|
const hasId = filename.includes("[id]");
|
@@ -781,14 +855,18 @@ const applyOutputDefaults = (
|
|
781
855
|
return output.module ? "[id].mjs" : "[id].js";
|
782
856
|
});
|
783
857
|
F(output, "cssFilename", () => {
|
784
|
-
const filename =
|
858
|
+
const filename =
|
859
|
+
/** @type {NonNullable<Output["cssFilename"]>} */
|
860
|
+
(output.filename);
|
785
861
|
if (typeof filename !== "function") {
|
786
862
|
return filename.replace(/\.[mc]?js(\?|$)/, ".css$1");
|
787
863
|
}
|
788
864
|
return "[id].css";
|
789
865
|
});
|
790
866
|
F(output, "cssChunkFilename", () => {
|
791
|
-
const chunkFilename =
|
867
|
+
const chunkFilename =
|
868
|
+
/** @type {NonNullable<Output["cssChunkFilename"]>} */
|
869
|
+
(output.chunkFilename);
|
792
870
|
if (typeof chunkFilename !== "function") {
|
793
871
|
return chunkFilename.replace(/\.[mc]?js(\?|$)/, ".css$1");
|
794
872
|
}
|
@@ -800,12 +878,18 @@ const applyOutputDefaults = (
|
|
800
878
|
D(output, "charset", true);
|
801
879
|
F(output, "hotUpdateGlobal", () =>
|
802
880
|
Template.toIdentifier(
|
803
|
-
"webpackHotUpdate" +
|
881
|
+
"webpackHotUpdate" +
|
882
|
+
Template.toIdentifier(
|
883
|
+
/** @type {NonNullable<Output["uniqueName"]>} */ (output.uniqueName)
|
884
|
+
)
|
804
885
|
)
|
805
886
|
);
|
806
887
|
F(output, "chunkLoadingGlobal", () =>
|
807
888
|
Template.toIdentifier(
|
808
|
-
"webpackChunk" +
|
889
|
+
"webpackChunk" +
|
890
|
+
Template.toIdentifier(
|
891
|
+
/** @type {NonNullable<Output["uniqueName"]>} */ (output.uniqueName)
|
892
|
+
)
|
809
893
|
)
|
810
894
|
);
|
811
895
|
F(output, "globalObject", () => {
|
@@ -938,26 +1022,56 @@ const applyOutputDefaults = (
|
|
938
1022
|
D(output, "hashDigestLength", futureDefaults ? 16 : 20);
|
939
1023
|
D(output, "strictModuleExceptionHandling", false);
|
940
1024
|
|
1025
|
+
const environment = /** @type {Environment} */ (output.environment);
|
1026
|
+
/**
|
1027
|
+
* @param {boolean | undefined} v value
|
1028
|
+
* @returns {boolean} true, when v is truthy or undefined
|
1029
|
+
*/
|
941
1030
|
const optimistic = v => v || v === undefined;
|
1031
|
+
/**
|
1032
|
+
* @param {boolean | undefined} v value
|
1033
|
+
* @param {boolean | undefined} c condition
|
1034
|
+
* @returns {boolean | undefined} true, when v is truthy or undefined, or c is truthy
|
1035
|
+
*/
|
942
1036
|
const conditionallyOptimistic = (v, c) => (v === undefined && c) || v;
|
943
1037
|
F(
|
944
|
-
|
1038
|
+
environment,
|
945
1039
|
"arrowFunction",
|
946
|
-
() =>
|
1040
|
+
() =>
|
1041
|
+
tp && optimistic(/** @type {boolean | undefined} */ (tp.arrowFunction))
|
1042
|
+
);
|
1043
|
+
F(
|
1044
|
+
environment,
|
1045
|
+
"const",
|
1046
|
+
() => tp && optimistic(/** @type {boolean | undefined} */ (tp.const))
|
947
1047
|
);
|
948
|
-
F(output.environment, "const", () => tp && optimistic(tp.const));
|
949
1048
|
F(
|
950
|
-
|
1049
|
+
environment,
|
951
1050
|
"destructuring",
|
952
|
-
() =>
|
1051
|
+
() =>
|
1052
|
+
tp && optimistic(/** @type {boolean | undefined} */ (tp.destructuring))
|
953
1053
|
);
|
954
|
-
F(
|
955
|
-
|
956
|
-
|
957
|
-
|
1054
|
+
F(
|
1055
|
+
environment,
|
1056
|
+
"forOf",
|
1057
|
+
() => tp && optimistic(/** @type {boolean | undefined} */ (tp.forOf))
|
958
1058
|
);
|
959
|
-
F(
|
960
|
-
|
1059
|
+
F(
|
1060
|
+
environment,
|
1061
|
+
"bigIntLiteral",
|
1062
|
+
() => /** @type {boolean | undefined} */ (tp && tp.bigIntLiteral)
|
1063
|
+
);
|
1064
|
+
F(environment, "dynamicImport", () =>
|
1065
|
+
conditionallyOptimistic(
|
1066
|
+
/** @type {boolean | undefined} */ (tp && tp.dynamicImport),
|
1067
|
+
output.module
|
1068
|
+
)
|
1069
|
+
);
|
1070
|
+
F(environment, "module", () =>
|
1071
|
+
conditionallyOptimistic(
|
1072
|
+
/** @type {boolean | undefined} */ (tp && tp.module),
|
1073
|
+
output.module
|
1074
|
+
)
|
961
1075
|
);
|
962
1076
|
|
963
1077
|
const { trustedTypes } = output;
|
@@ -966,7 +1080,8 @@ const applyOutputDefaults = (
|
|
966
1080
|
trustedTypes,
|
967
1081
|
"policyName",
|
968
1082
|
() =>
|
969
|
-
|
1083
|
+
/** @type {NonNullable<Output["uniqueName"]>} */
|
1084
|
+
(output.uniqueName).replace(/[^a-zA-Z0-9\-#=_/@.%]+/g, "_") || "webpack"
|
970
1085
|
);
|
971
1086
|
D(trustedTypes, "onPolicyCreationFailure", "stop");
|
972
1087
|
}
|
@@ -977,10 +1092,11 @@ const applyOutputDefaults = (
|
|
977
1092
|
*/
|
978
1093
|
const forEachEntry = fn => {
|
979
1094
|
for (const name of Object.keys(entry)) {
|
980
|
-
fn(entry[name]);
|
1095
|
+
fn(/** @type {{[k: string] : EntryDescription}} */ (entry)[name]);
|
981
1096
|
}
|
982
1097
|
};
|
983
1098
|
A(output, "enabledLibraryTypes", () => {
|
1099
|
+
/** @type {LibraryType[]} */
|
984
1100
|
const enabledLibraryTypes = [];
|
985
1101
|
if (output.library) {
|
986
1102
|
enabledLibraryTypes.push(output.library.type);
|
@@ -1040,35 +1156,56 @@ const applyExternalsPresetsDefaults = (
|
|
1040
1156
|
D(
|
1041
1157
|
externalsPresets,
|
1042
1158
|
"web",
|
1043
|
-
|
1159
|
+
/** @type {boolean | undefined} */
|
1160
|
+
(!buildHttp && targetProperties && targetProperties.web)
|
1161
|
+
);
|
1162
|
+
D(
|
1163
|
+
externalsPresets,
|
1164
|
+
"node",
|
1165
|
+
/** @type {boolean | undefined} */
|
1166
|
+
(targetProperties && targetProperties.node)
|
1167
|
+
);
|
1168
|
+
D(
|
1169
|
+
externalsPresets,
|
1170
|
+
"nwjs",
|
1171
|
+
/** @type {boolean | undefined} */
|
1172
|
+
(targetProperties && targetProperties.nwjs)
|
1044
1173
|
);
|
1045
|
-
D(externalsPresets, "node", targetProperties && targetProperties.node);
|
1046
|
-
D(externalsPresets, "nwjs", targetProperties && targetProperties.nwjs);
|
1047
1174
|
D(
|
1048
1175
|
externalsPresets,
|
1049
1176
|
"electron",
|
1050
|
-
|
1177
|
+
/** @type {boolean | undefined} */
|
1178
|
+
(targetProperties && targetProperties.electron)
|
1051
1179
|
);
|
1052
1180
|
D(
|
1053
1181
|
externalsPresets,
|
1054
1182
|
"electronMain",
|
1055
|
-
|
1056
|
-
|
1057
|
-
targetProperties
|
1183
|
+
/** @type {boolean | undefined} */
|
1184
|
+
(
|
1185
|
+
targetProperties &&
|
1186
|
+
targetProperties.electron &&
|
1187
|
+
targetProperties.electronMain
|
1188
|
+
)
|
1058
1189
|
);
|
1059
1190
|
D(
|
1060
1191
|
externalsPresets,
|
1061
1192
|
"electronPreload",
|
1062
|
-
|
1063
|
-
|
1064
|
-
targetProperties
|
1193
|
+
/** @type {boolean | undefined} */
|
1194
|
+
(
|
1195
|
+
targetProperties &&
|
1196
|
+
targetProperties.electron &&
|
1197
|
+
targetProperties.electronPreload
|
1198
|
+
)
|
1065
1199
|
);
|
1066
1200
|
D(
|
1067
1201
|
externalsPresets,
|
1068
1202
|
"electronRenderer",
|
1069
|
-
|
1070
|
-
|
1071
|
-
targetProperties
|
1203
|
+
/** @type {boolean | undefined} */
|
1204
|
+
(
|
1205
|
+
targetProperties &&
|
1206
|
+
targetProperties.electron &&
|
1207
|
+
targetProperties.electronRenderer
|
1208
|
+
)
|
1072
1209
|
);
|
1073
1210
|
};
|
1074
1211
|
|
@@ -1209,7 +1346,9 @@ const applyOptimizationDefaults = (
|
|
1209
1346
|
F(splitChunks, "maxAsyncRequests", () => (production ? 30 : Infinity));
|
1210
1347
|
F(splitChunks, "maxInitialRequests", () => (production ? 30 : Infinity));
|
1211
1348
|
D(splitChunks, "automaticNameDelimiter", "-");
|
1212
|
-
const
|
1349
|
+
const cacheGroups =
|
1350
|
+
/** @type {NonNullable<OptimizationSplitChunksOptions["cacheGroups"]>} */
|
1351
|
+
(splitChunks.cacheGroups);
|
1213
1352
|
F(cacheGroups, "default", () => ({
|
1214
1353
|
idHint: "",
|
1215
1354
|
reuseExistingChunk: true,
|