webpack 5.89.0 → 5.90.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 +3 -0
- package/bin/webpack.js +1 -3
- package/hot/log.js +0 -2
- package/lib/APIPlugin.js +17 -13
- package/lib/ChunkGraph.js +1 -1
- package/lib/CleanPlugin.js +12 -12
- package/lib/Compilation.js +26 -17
- package/lib/Compiler.js +13 -0
- package/lib/ConcatenationScope.js +2 -2
- package/lib/ConditionalInitFragment.js +3 -3
- package/lib/ContextModule.js +4 -4
- package/lib/ContextModuleFactory.js +1 -1
- package/lib/DefinePlugin.js +47 -26
- package/lib/DependencyTemplate.js +3 -1
- package/lib/EnvironmentNotSupportAsyncWarning.js +52 -0
- package/lib/EvalDevToolModulePlugin.js +1 -1
- package/lib/EvalSourceMapDevToolPlugin.js +2 -2
- package/lib/ExportsInfoApiPlugin.js +2 -2
- package/lib/ExternalModule.js +47 -12
- package/lib/ExternalModuleFactoryPlugin.js +1 -1
- package/lib/FileSystemInfo.js +20 -3
- package/lib/FlagDependencyExportsPlugin.js +1 -1
- package/lib/Generator.js +1 -0
- package/lib/HotModuleReplacementPlugin.js +3 -3
- package/lib/InitFragment.js +7 -7
- package/lib/LibManifestPlugin.js +4 -1
- package/lib/Module.js +2 -1
- package/lib/ModuleFilenameHelpers.js +1 -1
- package/lib/ModuleInfoHeaderPlugin.js +1 -1
- package/lib/MultiStats.js +2 -2
- package/lib/NodeStuffPlugin.js +48 -0
- package/lib/NormalModule.js +13 -11
- package/lib/NormalModuleFactory.js +7 -7
- package/lib/RuntimeTemplate.js +15 -11
- package/lib/SourceMapDevToolPlugin.js +2 -2
- package/lib/Stats.js +4 -0
- package/lib/WebpackOptionsApply.js +4 -3
- package/lib/asset/AssetModulesPlugin.js +2 -3
- package/lib/async-modules/AwaitDependenciesInitFragment.js +2 -2
- package/lib/buildChunkGraph.js +53 -0
- package/lib/cache/AddManagedPathsPlugin.js +6 -1
- package/lib/cache/IdleFileCachePlugin.js +12 -5
- package/lib/cache/PackFileCacheStrategy.js +3 -3
- package/lib/cache/ResolverCachePlugin.js +2 -2
- package/lib/config/browserslistTargetHandler.js +35 -14
- package/lib/config/defaults.js +88 -52
- package/lib/config/normalization.js +17 -18
- package/lib/config/target.js +5 -0
- package/lib/container/ContainerReferencePlugin.js +1 -1
- package/lib/css/CssExportsGenerator.js +14 -1
- package/lib/css/CssGenerator.js +14 -1
- package/lib/css/CssLoadingRuntimeModule.js +23 -23
- package/lib/css/CssModulesPlugin.js +68 -32
- package/lib/css/CssParser.js +8 -3
- package/lib/debug/ProfilingPlugin.js +2 -2
- package/lib/dependencies/AMDDefineDependency.js +4 -4
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +126 -34
- package/lib/dependencies/AMDPlugin.js +11 -4
- package/lib/dependencies/AMDRequireArrayDependency.js +13 -1
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +159 -43
- package/lib/dependencies/AMDRequireDependency.js +2 -2
- package/lib/dependencies/AMDRequireItemDependency.js +1 -1
- package/lib/dependencies/CachedConstDependency.js +8 -1
- package/lib/dependencies/CommonJsImportsParserPlugin.js +1 -1
- package/lib/dependencies/ContextElementDependency.js +1 -1
- package/lib/dependencies/ExternalModuleDependency.js +107 -0
- package/lib/dependencies/ExternalModuleInitFragment.js +131 -0
- package/lib/dependencies/HarmonyAcceptDependency.js +1 -1
- package/lib/dependencies/HarmonyDetectionParserPlugin.js +7 -1
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +18 -18
- package/lib/dependencies/HarmonyExportInitFragment.js +6 -6
- package/lib/dependencies/HarmonyImportDependency.js +4 -4
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +6 -6
- package/lib/dependencies/ImportDependency.js +26 -6
- package/lib/dependencies/JsonExportsDependency.js +1 -1
- package/lib/dependencies/LoaderPlugin.js +2 -1
- package/lib/dependencies/LocalModuleDependency.js +1 -1
- package/lib/dependencies/PureExpressionDependency.js +12 -4
- package/lib/dependencies/RequireIncludeDependency.js +1 -1
- package/lib/dependencies/WebpackIsIncludedDependency.js +1 -1
- package/lib/dependencies/WorkerPlugin.js +10 -3
- package/lib/dependencies/getFunctionExpression.js +2 -2
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +6 -6
- package/lib/hmr/HotModuleReplacement.runtime.js +3 -5
- package/lib/hmr/lazyCompilationBackend.js +4 -4
- package/lib/ids/DeterministicModuleIdsPlugin.js +1 -1
- package/lib/index.js +4 -0
- package/lib/javascript/JavascriptGenerator.js +16 -1
- package/lib/javascript/JavascriptModulesPlugin.js +33 -33
- package/lib/javascript/JavascriptParser.js +220 -74
- package/lib/json/JsonGenerator.js +1 -1
- package/lib/library/AmdLibraryPlugin.js +5 -1
- package/lib/library/AssignLibraryPlugin.js +1 -1
- package/lib/library/SystemLibraryPlugin.js +1 -1
- package/lib/library/UmdLibraryPlugin.js +39 -39
- package/lib/logging/createConsoleLogger.js +1 -19
- package/lib/node/ReadFileChunkLoadingRuntimeModule.js +8 -8
- package/lib/node/RequireChunkLoadingRuntimeModule.js +8 -8
- package/lib/node/nodeConsole.js +1 -5
- package/lib/optimize/ConcatenatedModule.js +7 -7
- package/lib/optimize/InnerGraphPlugin.js +9 -1
- package/lib/optimize/MangleExportsPlugin.js +5 -1
- package/lib/optimize/ModuleConcatenationPlugin.js +2 -2
- package/lib/optimize/RemoveParentModulesPlugin.js +123 -47
- package/lib/optimize/SideEffectsFlagPlugin.js +15 -3
- package/lib/optimize/SplitChunksPlugin.js +16 -16
- package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +2 -2
- package/lib/rules/RuleSetCompiler.js +1 -1
- package/lib/runtime/AutoPublicPathRuntimeModule.js +2 -2
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +4 -4
- package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +4 -4
- package/lib/runtime/LoadScriptRuntimeModule.js +2 -2
- package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +23 -22
- package/lib/runtime/StartupEntrypointRuntimeModule.js +2 -2
- package/lib/schemes/HttpUriPlugin.js +1 -1
- package/lib/serialization/FileMiddleware.js +4 -4
- package/lib/serialization/ObjectMiddleware.js +4 -4
- package/lib/sharing/ConsumeSharedPlugin.js +5 -5
- package/lib/sharing/ConsumeSharedRuntimeModule.js +8 -4
- package/lib/sharing/ProvideSharedModule.js +2 -2
- package/lib/sharing/SharePlugin.js +2 -2
- package/lib/sharing/ShareRuntimeModule.js +1 -1
- package/lib/sharing/utils.js +24 -28
- package/lib/stats/DefaultStatsFactoryPlugin.js +10 -10
- package/lib/stats/DefaultStatsPresetPlugin.js +3 -7
- package/lib/stats/DefaultStatsPrinterPlugin.js +34 -31
- package/lib/util/chainedImports.js +7 -6
- package/lib/util/cleverMerge.js +4 -4
- package/lib/util/comparators.js +59 -23
- package/lib/util/hash/xxhash64.js +2 -2
- package/lib/util/identifier.js +2 -2
- package/lib/util/internalSerializables.js +6 -0
- package/lib/util/numberHash.js +64 -52
- package/lib/util/runtime.js +18 -1
- package/lib/util/semver.js +19 -24
- package/lib/util/smartGrouping.js +1 -1
- package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +53 -28
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +2 -2
- package/lib/wasm-async/AsyncWebAssemblyParser.js +6 -0
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +2 -2
- package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +2 -2
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +13 -13
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +6 -6
- package/package.json +25 -80
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +140 -32
- package/schemas/plugins/css/CssAutoGeneratorOptions.check.d.ts +7 -0
- package/schemas/plugins/css/CssAutoGeneratorOptions.check.js +6 -0
- package/schemas/plugins/css/CssAutoGeneratorOptions.json +3 -0
- package/schemas/plugins/css/CssAutoParserOptions.check.d.ts +7 -0
- package/schemas/plugins/css/CssAutoParserOptions.check.js +6 -0
- package/schemas/plugins/css/CssAutoParserOptions.json +3 -0
- package/schemas/plugins/css/CssGeneratorOptions.check.js +1 -1
- package/schemas/plugins/css/CssGlobalGeneratorOptions.check.d.ts +7 -0
- package/schemas/plugins/css/CssGlobalGeneratorOptions.check.js +6 -0
- package/schemas/plugins/css/CssGlobalGeneratorOptions.json +3 -0
- package/schemas/plugins/css/CssGlobalParserOptions.check.d.ts +7 -0
- package/schemas/plugins/css/CssGlobalParserOptions.check.js +6 -0
- package/schemas/plugins/css/CssGlobalParserOptions.json +3 -0
- package/schemas/plugins/css/CssModuleGeneratorOptions.check.d.ts +7 -0
- package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +6 -0
- package/schemas/plugins/css/CssModuleGeneratorOptions.json +3 -0
- package/schemas/plugins/css/CssModuleParserOptions.check.d.ts +7 -0
- package/schemas/plugins/css/CssModuleParserOptions.check.js +6 -0
- package/schemas/plugins/css/CssModuleParserOptions.json +3 -0
- package/schemas/plugins/css/CssParserOptions.check.js +1 -1
- package/types.d.ts +273 -94
package/lib/config/defaults.js
CHANGED
@@ -29,7 +29,8 @@ const {
|
|
29
29
|
|
30
30
|
/** @typedef {import("../../declarations/WebpackOptions").CacheOptionsNormalized} CacheOptions */
|
31
31
|
/** @typedef {import("../../declarations/WebpackOptions").Context} Context */
|
32
|
-
/** @typedef {import("../../declarations/WebpackOptions").
|
32
|
+
/** @typedef {import("../../declarations/WebpackOptions").CssGeneratorOptions} CssGeneratorOptions */
|
33
|
+
/** @typedef {import("../../declarations/WebpackOptions").CssParserOptions} CssParserOptions */
|
33
34
|
/** @typedef {import("../../declarations/WebpackOptions").EntryDescription} EntryDescription */
|
34
35
|
/** @typedef {import("../../declarations/WebpackOptions").EntryNormalized} Entry */
|
35
36
|
/** @typedef {import("../../declarations/WebpackOptions").EntryStaticNormalized} EntryStaticNormalized */
|
@@ -39,6 +40,7 @@ const {
|
|
39
40
|
/** @typedef {import("../../declarations/WebpackOptions").ExternalsPresets} ExternalsPresets */
|
40
41
|
/** @typedef {import("../../declarations/WebpackOptions").ExternalsType} ExternalsType */
|
41
42
|
/** @typedef {import("../../declarations/WebpackOptions").FileCacheOptions} FileCacheOptions */
|
43
|
+
/** @typedef {import("../../declarations/WebpackOptions").GeneratorOptionsByModuleTypeKnown} GeneratorOptionsByModuleTypeKnown */
|
42
44
|
/** @typedef {import("../../declarations/WebpackOptions").InfrastructureLogging} InfrastructureLogging */
|
43
45
|
/** @typedef {import("../../declarations/WebpackOptions").JavascriptParserOptions} JavascriptParserOptions */
|
44
46
|
/** @typedef {import("../../declarations/WebpackOptions").Library} Library */
|
@@ -159,11 +161,11 @@ const applyWebpackOptionsDefaults = options => {
|
|
159
161
|
target === false
|
160
162
|
? /** @type {false} */ (false)
|
161
163
|
: typeof target === "string"
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
164
|
+
? getTargetProperties(target, /** @type {Context} */ (options.context))
|
165
|
+
: getTargetsProperties(
|
166
|
+
/** @type {string[]} */ (target),
|
167
|
+
/** @type {Context} */ (options.context)
|
168
|
+
);
|
167
169
|
|
168
170
|
const development = mode === "development";
|
169
171
|
const production = mode === "production" || !mode;
|
@@ -223,7 +225,8 @@ const applyWebpackOptionsDefaults = options => {
|
|
223
225
|
/** @type {NonNullable<ExperimentsNormalized["css"]>} */
|
224
226
|
(options.experiments.css),
|
225
227
|
futureDefaults,
|
226
|
-
isNode: targetProperties && targetProperties.node === true
|
228
|
+
isNode: targetProperties && targetProperties.node === true,
|
229
|
+
targetProperties
|
227
230
|
});
|
228
231
|
|
229
232
|
applyOutputDefaults(options.output, {
|
@@ -260,14 +263,15 @@ const applyWebpackOptionsDefaults = options => {
|
|
260
263
|
validExternalTypes.includes(options.output.library.type)
|
261
264
|
? /** @type {ExternalsType} */ (options.output.library.type)
|
262
265
|
: options.output.module
|
263
|
-
|
264
|
-
|
266
|
+
? "module"
|
267
|
+
: "var";
|
265
268
|
});
|
266
269
|
|
267
270
|
applyNodeDefaults(options.node, {
|
268
271
|
futureDefaults:
|
269
272
|
/** @type {NonNullable<WebpackOptions["experiments"]["futureDefaults"]>} */
|
270
273
|
(options.experiments.futureDefaults),
|
274
|
+
outputModule: options.output.module,
|
271
275
|
targetProperties
|
272
276
|
});
|
273
277
|
|
@@ -335,7 +339,7 @@ const applyExperimentsDefaults = (
|
|
335
339
|
D(experiments, "lazyCompilation", undefined);
|
336
340
|
D(experiments, "buildHttp", undefined);
|
337
341
|
D(experiments, "cacheUnaffected", experiments.futureDefaults);
|
338
|
-
F(experiments, "css", () => (experiments.futureDefaults ?
|
342
|
+
F(experiments, "css", () => (experiments.futureDefaults ? true : undefined));
|
339
343
|
|
340
344
|
// TODO webpack 6: remove this. topLevelAwait should be enabled by default
|
341
345
|
let shouldEnableTopLevelAwait = true;
|
@@ -348,14 +352,6 @@ const applyExperimentsDefaults = (
|
|
348
352
|
D(experiments.buildHttp, "frozen", production);
|
349
353
|
D(experiments.buildHttp, "upgrade", false);
|
350
354
|
}
|
351
|
-
|
352
|
-
if (typeof experiments.css === "object") {
|
353
|
-
D(
|
354
|
-
experiments.css,
|
355
|
-
"exportsOnly",
|
356
|
-
!targetProperties || !targetProperties.document
|
357
|
-
);
|
358
|
-
}
|
359
355
|
};
|
360
356
|
|
361
357
|
/**
|
@@ -448,7 +444,7 @@ const applySnapshotDefaults = (snapshot, { production, futureDefaults }) => {
|
|
448
444
|
process.versions.pnp === "3"
|
449
445
|
? [
|
450
446
|
/^(.+?(?:[\\/]\.yarn[\\/]unplugged[\\/][^\\/]+)?[\\/]node_modules[\\/])/
|
451
|
-
|
447
|
+
]
|
452
448
|
: [/^(.+?[\\/]node_modules[\\/])/]
|
453
449
|
);
|
454
450
|
F(snapshot, "immutablePaths", () =>
|
@@ -468,7 +464,6 @@ const applySnapshotDefaults = (snapshot, { production, futureDefaults }) => {
|
|
468
464
|
}
|
469
465
|
} else {
|
470
466
|
const match = /^(.+?[\\/]node_modules[\\/])/.exec(
|
471
|
-
// eslint-disable-next-line node/no-extraneous-require
|
472
467
|
require.resolve("watchpack")
|
473
468
|
);
|
474
469
|
if (match) {
|
@@ -477,6 +472,7 @@ const applySnapshotDefaults = (snapshot, { production, futureDefaults }) => {
|
|
477
472
|
}
|
478
473
|
return [];
|
479
474
|
});
|
475
|
+
F(snapshot, "unmanagedPaths", () => []);
|
480
476
|
A(snapshot, "immutablePaths", () => {
|
481
477
|
if (process.versions.pnp === "1") {
|
482
478
|
const match =
|
@@ -543,20 +539,46 @@ const applyJavascriptParserOptionsDefaults = (
|
|
543
539
|
if (futureDefaults) D(parserOptions, "exportsPresence", "error");
|
544
540
|
};
|
545
541
|
|
542
|
+
/**
|
543
|
+
* @param {CssGeneratorOptions} generatorOptions generator options
|
544
|
+
* @param {Object} options options
|
545
|
+
* @param {TargetProperties | false} options.targetProperties target properties
|
546
|
+
* @returns {void}
|
547
|
+
*/
|
548
|
+
const applyCssGeneratorOptionsDefaults = (
|
549
|
+
generatorOptions,
|
550
|
+
{ targetProperties }
|
551
|
+
) => {
|
552
|
+
D(
|
553
|
+
generatorOptions,
|
554
|
+
"exportsOnly",
|
555
|
+
!targetProperties || !targetProperties.document
|
556
|
+
);
|
557
|
+
};
|
558
|
+
|
546
559
|
/**
|
547
560
|
* @param {ModuleOptions} module options
|
548
561
|
* @param {Object} options options
|
549
562
|
* @param {boolean} options.cache is caching enabled
|
550
563
|
* @param {boolean} options.syncWebAssembly is syncWebAssembly enabled
|
551
564
|
* @param {boolean} options.asyncWebAssembly is asyncWebAssembly enabled
|
552
|
-
* @param {
|
565
|
+
* @param {boolean} options.css is css enabled
|
553
566
|
* @param {boolean} options.futureDefaults is future defaults enabled
|
554
567
|
* @param {boolean} options.isNode is node target platform
|
568
|
+
* @param {TargetProperties | false} options.targetProperties target properties
|
555
569
|
* @returns {void}
|
556
570
|
*/
|
557
571
|
const applyModuleDefaults = (
|
558
572
|
module,
|
559
|
-
{
|
573
|
+
{
|
574
|
+
cache,
|
575
|
+
syncWebAssembly,
|
576
|
+
asyncWebAssembly,
|
577
|
+
css,
|
578
|
+
futureDefaults,
|
579
|
+
isNode,
|
580
|
+
targetProperties
|
581
|
+
}
|
560
582
|
) => {
|
561
583
|
if (cache) {
|
562
584
|
D(
|
@@ -607,6 +629,20 @@ const applyModuleDefaults = (
|
|
607
629
|
}
|
608
630
|
);
|
609
631
|
|
632
|
+
if (css) {
|
633
|
+
F(module.parser, "css", () => ({}));
|
634
|
+
|
635
|
+
D(module.parser.css, "namedExports", true);
|
636
|
+
|
637
|
+
F(module.generator, "css", () => ({}));
|
638
|
+
|
639
|
+
applyCssGeneratorOptionsDefaults(
|
640
|
+
/** @type {NonNullable<GeneratorOptionsByModuleTypeKnown["css"]>} */
|
641
|
+
(module.generator.css),
|
642
|
+
{ targetProperties }
|
643
|
+
);
|
644
|
+
}
|
645
|
+
|
610
646
|
A(module, "defaultRules", () => {
|
611
647
|
const esm = {
|
612
648
|
type: JAVASCRIPT_MODULE_TYPE_ESM,
|
@@ -818,9 +854,8 @@ const applyOutputDefaults = (
|
|
818
854
|
} catch (e) {
|
819
855
|
if (/** @type {Error & { code: string }} */ (e).code !== "ENOENT") {
|
820
856
|
/** @type {Error & { code: string }} */
|
821
|
-
(
|
822
|
-
|
823
|
-
).message += `\nwhile determining default 'output.uniqueName' from 'name' in ${pkgPath}`;
|
857
|
+
(e).message +=
|
858
|
+
`\nwhile determining default 'output.uniqueName' from 'name' in ${pkgPath}`;
|
824
859
|
throw e;
|
825
860
|
}
|
826
861
|
return "";
|
@@ -870,22 +905,11 @@ const applyOutputDefaults = (
|
|
870
905
|
D(output, "webassemblyModuleFilename", "[hash].module.wasm");
|
871
906
|
D(output, "compareBeforeEmit", true);
|
872
907
|
D(output, "charset", true);
|
873
|
-
|
874
|
-
|
875
|
-
"webpackHotUpdate" +
|
876
|
-
Template.toIdentifier(
|
877
|
-
/** @type {NonNullable<Output["uniqueName"]>} */ (output.uniqueName)
|
878
|
-
)
|
879
|
-
)
|
880
|
-
);
|
881
|
-
F(output, "chunkLoadingGlobal", () =>
|
882
|
-
Template.toIdentifier(
|
883
|
-
"webpackChunk" +
|
884
|
-
Template.toIdentifier(
|
885
|
-
/** @type {NonNullable<Output["uniqueName"]>} */ (output.uniqueName)
|
886
|
-
)
|
887
|
-
)
|
908
|
+
const uniqueNameId = Template.toIdentifier(
|
909
|
+
/** @type {NonNullable<Output["uniqueName"]>} */ (output.uniqueName)
|
888
910
|
);
|
911
|
+
F(output, "hotUpdateGlobal", () => "webpackHotUpdate" + uniqueNameId);
|
912
|
+
F(output, "chunkLoadingGlobal", () => "webpackChunk" + uniqueNameId);
|
889
913
|
F(output, "globalObject", () => {
|
890
914
|
if (tp) {
|
891
915
|
if (tp.global) return "global";
|
@@ -1014,6 +1038,7 @@ const applyOutputDefaults = (
|
|
1014
1038
|
D(output, "hashFunction", futureDefaults ? "xxhash64" : "md4");
|
1015
1039
|
D(output, "hashDigest", "hex");
|
1016
1040
|
D(output, "hashDigestLength", futureDefaults ? 16 : 20);
|
1041
|
+
D(output, "strictModuleErrorHandling", false);
|
1017
1042
|
D(output, "strictModuleExceptionHandling", false);
|
1018
1043
|
|
1019
1044
|
const environment = /** @type {Environment} */ (output.environment);
|
@@ -1050,6 +1075,12 @@ const applyOutputDefaults = (
|
|
1050
1075
|
() =>
|
1051
1076
|
tp && optimistic(/** @type {boolean | undefined} */ (tp.arrowFunction))
|
1052
1077
|
);
|
1078
|
+
F(
|
1079
|
+
environment,
|
1080
|
+
"asyncFunction",
|
1081
|
+
() =>
|
1082
|
+
tp && optimistic(/** @type {boolean | undefined} */ (tp.asyncFunction))
|
1083
|
+
);
|
1053
1084
|
F(
|
1054
1085
|
environment,
|
1055
1086
|
"forOf",
|
@@ -1256,9 +1287,13 @@ const applyLoaderDefaults = (loader, { targetProperties, environment }) => {
|
|
1256
1287
|
* @param {Object} options options
|
1257
1288
|
* @param {TargetProperties | false} options.targetProperties target properties
|
1258
1289
|
* @param {boolean} options.futureDefaults is future defaults enabled
|
1290
|
+
* @param {boolean} options.outputModule is output type is module
|
1259
1291
|
* @returns {void}
|
1260
1292
|
*/
|
1261
|
-
const applyNodeDefaults = (
|
1293
|
+
const applyNodeDefaults = (
|
1294
|
+
node,
|
1295
|
+
{ futureDefaults, outputModule, targetProperties }
|
1296
|
+
) => {
|
1262
1297
|
if (node === false) return;
|
1263
1298
|
|
1264
1299
|
F(node, "global", () => {
|
@@ -1266,16 +1301,16 @@ const applyNodeDefaults = (node, { futureDefaults, targetProperties }) => {
|
|
1266
1301
|
// TODO webpack 6 should always default to false
|
1267
1302
|
return futureDefaults ? "warn" : true;
|
1268
1303
|
});
|
1269
|
-
|
1270
|
-
|
1271
|
-
|
1272
|
-
|
1273
|
-
});
|
1274
|
-
F(node, "__dirname", () => {
|
1275
|
-
if (targetProperties && targetProperties.node) return "eval-only";
|
1304
|
+
|
1305
|
+
const handlerForNames = () => {
|
1306
|
+
if (targetProperties && targetProperties.node)
|
1307
|
+
return outputModule ? "node-module" : "eval-only";
|
1276
1308
|
// TODO webpack 6 should always default to false
|
1277
1309
|
return futureDefaults ? "warn-mock" : "mock";
|
1278
|
-
}
|
1310
|
+
};
|
1311
|
+
|
1312
|
+
F(node, "__filename", handlerForNames);
|
1313
|
+
F(node, "__dirname", handlerForNames);
|
1279
1314
|
};
|
1280
1315
|
|
1281
1316
|
/**
|
@@ -1296,7 +1331,7 @@ const applyPerformanceDefaults = (performance, { production }) => {
|
|
1296
1331
|
* @param {Object} options options
|
1297
1332
|
* @param {boolean} options.production is production
|
1298
1333
|
* @param {boolean} options.development is development
|
1299
|
-
* @param {
|
1334
|
+
* @param {boolean} options.css is css enabled
|
1300
1335
|
* @param {boolean} options.records using records
|
1301
1336
|
* @returns {void}
|
1302
1337
|
*/
|
@@ -1390,7 +1425,7 @@ const applyOptimizationDefaults = (
|
|
1390
1425
|
* @param {string} options.context build context
|
1391
1426
|
* @param {TargetProperties | false} options.targetProperties target properties
|
1392
1427
|
* @param {Mode} options.mode mode
|
1393
|
-
* @param {
|
1428
|
+
* @param {boolean} options.css is css enabled
|
1394
1429
|
* @returns {ResolveOptions} resolve options
|
1395
1430
|
*/
|
1396
1431
|
const getResolveDefaults = ({
|
@@ -1481,7 +1516,8 @@ const getResolveDefaults = ({
|
|
1481
1516
|
mainFiles: [],
|
1482
1517
|
mainFields: ["style", "..."],
|
1483
1518
|
conditionNames: styleConditions,
|
1484
|
-
extensions: [".css"]
|
1519
|
+
extensions: [".css"],
|
1520
|
+
preferRelative: true
|
1485
1521
|
};
|
1486
1522
|
}
|
1487
1523
|
|
@@ -109,7 +109,7 @@ const keyedNestedConfig = (value, fn, customKeys) => {
|
|
109
109
|
obj
|
110
110
|
),
|
111
111
|
/** @type {Record<string, R>} */ ({})
|
112
|
-
|
112
|
+
);
|
113
113
|
if (customKeys) {
|
114
114
|
for (const key of Object.keys(customKeys)) {
|
115
115
|
if (!(key in result)) {
|
@@ -175,19 +175,20 @@ const getNormalizedWebpackOptions = config => {
|
|
175
175
|
),
|
176
176
|
context: config.context,
|
177
177
|
dependencies: config.dependencies,
|
178
|
-
devServer: optionalNestedConfig(config.devServer, devServer =>
|
179
|
-
|
180
|
-
|
178
|
+
devServer: optionalNestedConfig(config.devServer, devServer => {
|
179
|
+
if (devServer === false) return false;
|
180
|
+
return { ...devServer };
|
181
|
+
}),
|
181
182
|
devtool: config.devtool,
|
182
183
|
entry:
|
183
184
|
config.entry === undefined
|
184
185
|
? { main: {} }
|
185
186
|
: typeof config.entry === "function"
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
187
|
+
? (
|
188
|
+
fn => () =>
|
189
|
+
Promise.resolve().then(fn).then(getNormalizedEntryStatic)
|
190
|
+
)(config.entry)
|
191
|
+
: getNormalizedEntryStatic(config.entry),
|
191
192
|
experiments: nestedConfig(config.experiments, experiments => ({
|
192
193
|
...experiments,
|
193
194
|
buildHttp: optionalNestedConfig(experiments.buildHttp, options =>
|
@@ -196,9 +197,6 @@ const getNormalizedWebpackOptions = config => {
|
|
196
197
|
lazyCompilation: optionalNestedConfig(
|
197
198
|
experiments.lazyCompilation,
|
198
199
|
options => (options === true ? {} : options)
|
199
|
-
),
|
200
|
-
css: optionalNestedConfig(experiments.css, options =>
|
201
|
-
options === true ? {} : options
|
202
200
|
)
|
203
201
|
})),
|
204
202
|
externals: /** @type {NonNullable<Externals>} */ (config.externals),
|
@@ -227,7 +225,7 @@ const getNormalizedWebpackOptions = config => {
|
|
227
225
|
}
|
228
226
|
return true;
|
229
227
|
};
|
230
|
-
|
228
|
+
})
|
231
229
|
: undefined,
|
232
230
|
infrastructureLogging: cloneObject(config.infrastructureLogging),
|
233
231
|
loader: cloneObject(config.loader),
|
@@ -292,7 +290,7 @@ const getNormalizedWebpackOptions = config => {
|
|
292
290
|
? handledDeprecatedNoEmitOnErrors(
|
293
291
|
optimization.noEmitOnErrors,
|
294
292
|
optimization.emitOnErrors
|
295
|
-
|
293
|
+
)
|
296
294
|
: optimization.emitOnErrors
|
297
295
|
};
|
298
296
|
}),
|
@@ -306,10 +304,10 @@ const getNormalizedWebpackOptions = config => {
|
|
306
304
|
"type" in library
|
307
305
|
? library
|
308
306
|
: libraryAsName || output.libraryTarget
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
307
|
+
? /** @type {LibraryOptions} */ ({
|
308
|
+
name: libraryAsName
|
309
|
+
})
|
310
|
+
: undefined;
|
313
311
|
/** @type {OutputNormalized} */
|
314
312
|
const result = {
|
315
313
|
assetModuleFilename: output.assetModuleFilename,
|
@@ -382,6 +380,7 @@ const getNormalizedWebpackOptions = config => {
|
|
382
380
|
publicPath: output.publicPath,
|
383
381
|
sourceMapFilename: output.sourceMapFilename,
|
384
382
|
sourcePrefix: output.sourcePrefix,
|
383
|
+
strictModuleErrorHandling: output.strictModuleErrorHandling,
|
385
384
|
strictModuleExceptionHandling: output.strictModuleExceptionHandling,
|
386
385
|
trustedTypes: optionalNestedConfig(
|
387
386
|
output.trustedTypes,
|
package/lib/config/target.js
CHANGED
@@ -61,6 +61,7 @@ const getDefaultTarget = context => {
|
|
61
61
|
* @property {boolean | null} module ESM syntax is available (when in module)
|
62
62
|
* @property {boolean | null} optionalChaining optional chaining is available
|
63
63
|
* @property {boolean | null} templateLiteral template literal is available
|
64
|
+
* @property {boolean | null} asyncFunction async functions and await are available
|
64
65
|
*/
|
65
66
|
|
66
67
|
///** @typedef {PlatformTargetProperties | ApiTargetProperties | EcmaTargetProperties | PlatformTargetProperties & ApiTargetProperties | PlatformTargetProperties & EcmaTargetProperties | ApiTargetProperties & EcmaTargetProperties} TargetProperties */
|
@@ -192,6 +193,7 @@ You can also more options via the 'target' option: 'browserslist' / 'browserslis
|
|
192
193
|
templateLiteral: v(4),
|
193
194
|
optionalChaining: v(14),
|
194
195
|
arrowFunction: v(6),
|
196
|
+
asyncFunction: v(7, 6),
|
195
197
|
forOf: v(5),
|
196
198
|
destructuring: v(6),
|
197
199
|
bigIntLiteral: v(10, 4),
|
@@ -233,6 +235,7 @@ You can also more options via the 'target' option: 'browserslist' / 'browserslis
|
|
233
235
|
templateLiteral: v(1, 1),
|
234
236
|
optionalChaining: v(8),
|
235
237
|
arrowFunction: v(1, 1),
|
238
|
+
asyncFunction: v(1, 7),
|
236
239
|
forOf: v(0, 36),
|
237
240
|
destructuring: v(1, 1),
|
238
241
|
bigIntLiteral: v(4),
|
@@ -270,6 +273,7 @@ You can also more options via the 'target' option: 'browserslist' / 'browserslis
|
|
270
273
|
templateLiteral: v(0, 13),
|
271
274
|
optionalChaining: v(0, 44),
|
272
275
|
arrowFunction: v(0, 15),
|
276
|
+
asyncFunction: v(0, 21),
|
273
277
|
forOf: v(0, 13),
|
274
278
|
destructuring: v(0, 15),
|
275
279
|
bigIntLiteral: v(0, 32),
|
@@ -294,6 +298,7 @@ You can also more options via the 'target' option: 'browserslist' / 'browserslis
|
|
294
298
|
forOf: v >= 2015,
|
295
299
|
destructuring: v >= 2015,
|
296
300
|
module: v >= 2015,
|
301
|
+
asyncFunction: v >= 2017,
|
297
302
|
globalThis: v >= 2020,
|
298
303
|
bigIntLiteral: v >= 2020,
|
299
304
|
dynamicImport: v >= 2020,
|
@@ -47,6 +47,7 @@ class CssExportsGenerator extends Generator {
|
|
47
47
|
|
48
48
|
generateContext.runtimeRequirements.add(RuntimeGlobals.module);
|
49
49
|
|
50
|
+
let chunkInitFragments;
|
50
51
|
const runtimeRequirements = new Set();
|
51
52
|
|
52
53
|
const templateContext = {
|
@@ -60,7 +61,19 @@ class CssExportsGenerator extends Generator {
|
|
60
61
|
concatenationScope: generateContext.concatenationScope,
|
61
62
|
codeGenerationResults: generateContext.codeGenerationResults,
|
62
63
|
initFragments,
|
63
|
-
cssExports
|
64
|
+
cssExports,
|
65
|
+
get chunkInitFragments() {
|
66
|
+
if (!chunkInitFragments) {
|
67
|
+
const data = generateContext.getData();
|
68
|
+
chunkInitFragments = data.get("chunkInitFragments");
|
69
|
+
if (!chunkInitFragments) {
|
70
|
+
chunkInitFragments = [];
|
71
|
+
data.set("chunkInitFragments", chunkInitFragments);
|
72
|
+
}
|
73
|
+
}
|
74
|
+
|
75
|
+
return chunkInitFragments;
|
76
|
+
}
|
64
77
|
};
|
65
78
|
|
66
79
|
/**
|
package/lib/css/CssGenerator.js
CHANGED
@@ -38,6 +38,7 @@ class CssGenerator extends Generator {
|
|
38
38
|
|
39
39
|
generateContext.runtimeRequirements.add(RuntimeGlobals.hasCssModules);
|
40
40
|
|
41
|
+
let chunkInitFragments;
|
41
42
|
const templateContext = {
|
42
43
|
runtimeTemplate: generateContext.runtimeTemplate,
|
43
44
|
dependencyTemplates: generateContext.dependencyTemplates,
|
@@ -49,7 +50,19 @@ class CssGenerator extends Generator {
|
|
49
50
|
concatenationScope: generateContext.concatenationScope,
|
50
51
|
codeGenerationResults: generateContext.codeGenerationResults,
|
51
52
|
initFragments,
|
52
|
-
cssExports
|
53
|
+
cssExports,
|
54
|
+
get chunkInitFragments() {
|
55
|
+
if (!chunkInitFragments) {
|
56
|
+
const data = generateContext.getData();
|
57
|
+
chunkInitFragments = data.get("chunkInitFragments");
|
58
|
+
if (!chunkInitFragments) {
|
59
|
+
chunkInitFragments = [];
|
60
|
+
data.set("chunkInitFragments", chunkInitFragments);
|
61
|
+
}
|
62
|
+
}
|
63
|
+
|
64
|
+
return chunkInitFragments;
|
65
|
+
}
|
53
66
|
};
|
54
67
|
|
55
68
|
/**
|
@@ -129,7 +129,7 @@ class CssLoadingRuntimeModule extends RuntimeModule {
|
|
129
129
|
`link.crossOrigin = ${JSON.stringify(crossOriginLoading)};`
|
130
130
|
),
|
131
131
|
"}"
|
132
|
-
|
132
|
+
])
|
133
133
|
: ""
|
134
134
|
]);
|
135
135
|
|
@@ -141,7 +141,7 @@ class CssLoadingRuntimeModule extends RuntimeModule {
|
|
141
141
|
{ expr: "uniqueName" },
|
142
142
|
"-",
|
143
143
|
{ expr: "chunkId" }
|
144
|
-
|
144
|
+
)
|
145
145
|
: runtimeTemplate.concatenation("--webpack-", { expr: "chunkId" });
|
146
146
|
|
147
147
|
return Template.asString([
|
@@ -158,7 +158,7 @@ class CssLoadingRuntimeModule extends RuntimeModule {
|
|
158
158
|
uniqueName
|
159
159
|
? `var uniqueName = ${JSON.stringify(
|
160
160
|
runtimeTemplate.outputOptions.uniqueName
|
161
|
-
|
161
|
+
)};`
|
162
162
|
: "// data-webpack is not used as build has no uniqueName",
|
163
163
|
`var loadCssChunkData = ${runtimeTemplate.basicFunction(
|
164
164
|
"target, link, chunkId",
|
@@ -210,10 +210,10 @@ class CssLoadingRuntimeModule extends RuntimeModule {
|
|
210
210
|
{ expr: "token" },
|
211
211
|
"-",
|
212
212
|
{ expr: "exports[x]" }
|
213
|
-
|
213
|
+
)
|
214
214
|
: runtimeTemplate.concatenation({ expr: "token" }, "-", {
|
215
215
|
expr: "exports[x]"
|
216
|
-
|
216
|
+
})
|
217
217
|
}`,
|
218
218
|
"x"
|
219
219
|
)}); exportsWithDashes.forEach(${runtimeTemplate.expressionFunction(
|
@@ -292,18 +292,18 @@ class CssLoadingRuntimeModule extends RuntimeModule {
|
|
292
292
|
initialChunkIdsWithCss.size > 2
|
293
293
|
? `${JSON.stringify(
|
294
294
|
Array.from(initialChunkIdsWithCss)
|
295
|
-
|
295
|
+
)}.forEach(loadCssChunkData.bind(null, ${
|
296
296
|
RuntimeGlobals.moduleFactories
|
297
|
-
|
297
|
+
}, 0));`
|
298
298
|
: initialChunkIdsWithCss.size > 0
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
299
|
+
? `${Array.from(
|
300
|
+
initialChunkIdsWithCss,
|
301
|
+
id =>
|
302
|
+
`loadCssChunkData(${
|
303
|
+
RuntimeGlobals.moduleFactories
|
304
|
+
}, 0, ${JSON.stringify(id)});`
|
305
|
+
).join("")}`
|
306
|
+
: "// no initial css",
|
307
307
|
"",
|
308
308
|
withLoading
|
309
309
|
? Template.asString([
|
@@ -345,11 +345,11 @@ class CssLoadingRuntimeModule extends RuntimeModule {
|
|
345
345
|
'if(event.type !== "load") {',
|
346
346
|
Template.indent([
|
347
347
|
"var errorType = event && event.type;",
|
348
|
-
"var
|
349
|
-
"error.message = 'Loading css chunk ' + chunkId + ' failed.\\n(' + errorType + ': ' +
|
348
|
+
"var realHref = event && event.target && event.target.href;",
|
349
|
+
"error.message = 'Loading css chunk ' + chunkId + ' failed.\\n(' + errorType + ': ' + realHref + ')';",
|
350
350
|
"error.name = 'ChunkLoadError';",
|
351
351
|
"error.type = errorType;",
|
352
|
-
"error.request =
|
352
|
+
"error.request = realHref;",
|
353
353
|
"installedChunkData[1](error);"
|
354
354
|
]),
|
355
355
|
"} else {",
|
@@ -372,7 +372,7 @@ class CssLoadingRuntimeModule extends RuntimeModule {
|
|
372
372
|
]),
|
373
373
|
"}"
|
374
374
|
])};`
|
375
|
-
|
375
|
+
])
|
376
376
|
: "// no chunk loading",
|
377
377
|
"",
|
378
378
|
withHmr
|
@@ -435,11 +435,11 @@ class CssLoadingRuntimeModule extends RuntimeModule {
|
|
435
435
|
'if(event.type !== "load") {',
|
436
436
|
Template.indent([
|
437
437
|
"var errorType = event && event.type;",
|
438
|
-
"var
|
439
|
-
"error.message = 'Loading css hot update chunk ' + chunkId + ' failed.\\n(' + errorType + ': ' +
|
438
|
+
"var realHref = event && event.target && event.target.href;",
|
439
|
+
"error.message = 'Loading css hot update chunk ' + chunkId + ' failed.\\n(' + errorType + ': ' + realHref + ')';",
|
440
440
|
"error.name = 'ChunkLoadError';",
|
441
441
|
"error.type = errorType;",
|
442
|
-
"error.request =
|
442
|
+
"error.request = realHref;",
|
443
443
|
"reject(error);"
|
444
444
|
]),
|
445
445
|
"} else {",
|
@@ -464,7 +464,7 @@ class CssLoadingRuntimeModule extends RuntimeModule {
|
|
464
464
|
])});`
|
465
465
|
]
|
466
466
|
)}`
|
467
|
-
|
467
|
+
])
|
468
468
|
: "// no hmr"
|
469
469
|
]);
|
470
470
|
}
|