webpack 5.108.4 → 5.109.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.
- package/bin/webpack.js +12 -0
- package/lib/APIPlugin.js +48 -29
- package/lib/CacheFacade.js +8 -0
- package/lib/ChunkGraph.js +17 -15
- package/lib/ChunkGroup.js +1 -0
- package/lib/CompatibilityPlugin.js +62 -29
- package/lib/Compilation.js +58 -6
- package/lib/ConstPlugin.js +11 -11
- package/lib/ContextModule.js +239 -6
- package/lib/ContextModuleFactory.js +139 -14
- package/lib/DefinePlugin.js +433 -112
- package/lib/Entrypoint.js +1 -1
- package/lib/ExportsInfo.js +22 -5
- package/lib/ExportsInfoApiPlugin.js +2 -2
- package/lib/ExternalModule.js +107 -5
- package/lib/ExternalModuleFactoryPlugin.js +20 -1
- package/lib/FileSystemInfo.js +256 -100
- package/lib/FlagDependencyUsagePlugin.js +33 -12
- package/lib/HotModuleReplacementPlugin.js +18 -15
- package/lib/InitFragment.js +20 -32
- package/lib/Module.js +3 -0
- package/lib/ModuleFilenameHelpers.js +2 -2
- package/lib/ModuleTypeConstants.js +8 -1
- package/lib/MultiCompiler.js +13 -2
- package/lib/MultiWatching.js +1 -0
- package/lib/NodeStuffPlugin.js +51 -33
- package/lib/NormalModule.js +175 -401
- package/lib/NormalModuleFactory.js +76 -2
- package/lib/ProgressPlugin.js +211 -119
- package/lib/ProvidePlugin.js +2 -2
- package/lib/RuntimeGlobals.js +47 -0
- package/lib/RuntimePlugin.js +67 -107
- package/lib/RuntimeTemplate.js +304 -16
- package/lib/Template.js +23 -3
- package/lib/UseStrictPlugin.js +1 -1
- package/lib/WebpackIsIncludedPlugin.js +1 -1
- package/lib/WebpackOptionsApply.js +24 -19
- package/lib/asset/AssetGenerator.js +110 -28
- package/lib/asset/AssetModulesPlugin.js +92 -2
- package/lib/asset/WebManifestGenerator.js +164 -0
- package/lib/asset/WebManifestParser.js +130 -0
- package/lib/async-modules/AwaitDependenciesInitFragment.js +14 -4
- package/lib/async-modules/isGeneratorLowered.js +26 -0
- package/lib/cache/PackFileCacheStrategy.js +9 -3
- package/lib/config/browserslistTargetHandler.js +40 -0
- package/lib/config/defaults.js +219 -29
- package/lib/config/normalization.js +26 -0
- package/lib/config/target.js +9 -1
- package/lib/container/HoistContainerReferencesPlugin.js +47 -55
- package/lib/css/CssGenerator.js +40 -31
- package/lib/css/CssLoadingRuntimeModule.js +5 -1
- package/lib/css/CssModulesPlugin.js +13 -0
- package/lib/css/CssParser.js +729 -313
- package/lib/css/syntax.js +1371 -861
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +6 -6
- package/lib/dependencies/AMDPlugin.js +2 -2
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +13 -13
- package/lib/dependencies/CommonJsDependencyHelpers.js +39 -0
- package/lib/dependencies/CommonJsExportRequireDependency.js +19 -0
- package/lib/dependencies/CommonJsExportsDependency.js +47 -2
- package/lib/dependencies/CommonJsExportsParserPlugin.js +10 -10
- package/lib/dependencies/CommonJsImportsParserPlugin.js +18 -18
- package/lib/dependencies/CommonJsPlugin.js +2 -2
- package/lib/dependencies/CommonJsRequireDependency.js +26 -1
- package/lib/dependencies/CommonJsSelfReferenceDependency.js +32 -1
- package/lib/dependencies/ContextDependencyHelpers.js +3 -3
- package/lib/dependencies/CreateRequireParserPlugin.js +6 -6
- package/lib/dependencies/CssIcssExportDependency.js +162 -71
- package/lib/dependencies/CssUrlDependency.js +35 -4
- package/lib/dependencies/ExternalModuleInitFragmentDependency.js +2 -2
- package/lib/dependencies/HarmonyCompatibilityDependency.js +32 -14
- package/lib/dependencies/HarmonyDetectionParserPlugin.js +43 -13
- package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +2 -1
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +7 -19
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +17 -9
- package/lib/dependencies/HarmonyImportDependency.js +13 -2
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +11 -11
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +10 -7
- package/lib/dependencies/HarmonyModulesPlugin.js +6 -0
- package/lib/dependencies/HarmonyTopLevelThisParserPlugin.js +1 -1
- package/lib/dependencies/HtmlEntryDependency.js +797 -172
- package/lib/dependencies/HtmlSourceDependency.js +26 -0
- package/lib/dependencies/ImportDependency.js +43 -1
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +31 -18
- package/lib/dependencies/ImportMetaContextPlugin.js +38 -7
- package/lib/dependencies/ImportMetaGlobDependency.js +81 -0
- package/lib/dependencies/ImportMetaGlobDependencyParserPlugin.js +78 -0
- package/lib/dependencies/ImportMetaGlobHelpers.js +660 -0
- package/lib/dependencies/ImportMetaPlugin.js +532 -180
- package/lib/dependencies/ImportMetaResolveDependency.js +90 -0
- package/lib/dependencies/ImportParserPlugin.js +80 -17
- package/lib/dependencies/ImportPhase.js +10 -8
- package/lib/dependencies/LoaderPlugin.js +5 -1
- package/lib/dependencies/RequireContextDependencyParserPlugin.js +1 -1
- package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +3 -6
- package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +4 -11
- package/lib/dependencies/SystemPlugin.js +2 -4
- package/lib/dependencies/TopLevelAwaitDependency.js +93 -0
- package/lib/dependencies/URLDependency.js +141 -21
- package/lib/dependencies/{WorkerPlugin.js → WorkerAndWorkletPlugin.js} +324 -112
- package/lib/dependencies/WorkerDependency.js +86 -18
- package/lib/dependencies/WorkletDependency.js +278 -0
- package/lib/dll/DelegatedModuleFactoryPlugin.js +19 -0
- package/lib/errors/EnvironmentNotSupportAsyncWarning.js +1 -1
- package/lib/errors/LoaderLoadingError.js +20 -0
- package/lib/errors/ModuleParseError.js +39 -22
- package/lib/errors/NodeStuffInWebError.js +1 -1
- package/lib/esm/ModuleChunkFormatPlugin.js +47 -14
- package/lib/esm/ModuleChunkLoadingPlugin.js +8 -1
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +29 -1
- package/lib/hmr/lazyCompilationBackend.js +51 -12
- package/lib/html/HtmlGenerator.js +907 -15
- package/lib/html/HtmlModule.js +2 -2
- package/lib/html/HtmlModulesPlugin.js +610 -166
- package/lib/html/HtmlParser.js +603 -247
- package/lib/html/favicon.svg +1 -0
- package/lib/html/syntax.js +3451 -2762
- package/lib/ids/IdHelpers.js +25 -11
- package/lib/index.js +6 -0
- package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +4 -5
- package/lib/javascript/BasicEvaluatedExpression.js +366 -48
- package/lib/javascript/JavascriptGenerator.js +197 -49
- package/lib/javascript/JavascriptModulesPlugin.js +178 -24
- package/lib/javascript/JavascriptParser.js +704 -355
- package/lib/javascript/JavascriptParserHelpers.js +3 -6
- package/lib/javascript/syntax.js +5037 -0
- package/lib/library/ModuleLibraryPlugin.js +38 -1
- package/lib/loaders/LoaderRunner.js +714 -0
- package/lib/loaders/loadLoader.js +100 -0
- package/lib/node/ReadFileCompileAsyncWasmPlugin.js +29 -2
- package/lib/node/ReadFileCompileWasmPlugin.js +24 -2
- package/lib/optimize/AggressiveMergingPlugin.js +19 -15
- package/lib/optimize/ConcatenatedModule.js +139 -31
- package/lib/optimize/FlagIncludedChunksPlugin.js +13 -3
- package/lib/optimize/InnerGraphPlugin.js +50 -30
- package/lib/optimize/ModuleConcatenationPlugin.js +139 -24
- package/lib/optimize/SideEffectsFlagPlugin.js +86 -43
- package/lib/optimize/SplitChunksPlugin.js +146 -44
- package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +15 -0
- package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +24 -13
- package/lib/prefetch/ResourceHintPlugin.js +687 -0
- package/lib/prefetch/ResourceHintRuntimeModule.js +149 -0
- package/lib/prefetch/StartupAssetHintRuntimeModule.js +210 -0
- package/lib/prefetch/parseResourceHintOptions.js +103 -0
- package/lib/rules/RuleSetCompiler.js +114 -0
- package/lib/runtime/AsyncModuleGeneratorRuntimeModule.js +56 -0
- package/lib/runtime/AsyncModuleRuntimeModule.js +24 -8
- package/lib/runtime/AutoPublicPathRuntimeModule.js +7 -1
- package/lib/runtime/CommonJsWrapRuntimeModule.js +37 -0
- package/lib/runtime/GetWorkletBootstrapRuntimeModule.js +59 -0
- package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +204 -8
- package/lib/runtime/SetAnonymousDefaultNameRuntimeModule.js +4 -1
- package/lib/schemes/HttpUriPlugin.js +40 -1
- package/lib/schemes/VirtualUrlPlugin.js +1 -2
- package/lib/serialization/BinaryMiddleware.js +270 -938
- package/lib/serialization/FileMiddleware.js +29 -3
- package/lib/stats/DefaultStatsFactoryPlugin.js +229 -194
- package/lib/stats/DefaultStatsPresetPlugin.js +2 -0
- package/lib/stats/DefaultStatsPrinterPlugin.js +36 -168
- package/lib/stats/StatsFactory.js +46 -17
- package/lib/url/URLParserPlugin.js +66 -13
- package/lib/util/AsyncQueue.js +122 -72
- package/lib/util/SetHelpers.js +1 -1
- package/lib/util/StackedMap.js +122 -48
- package/lib/util/binarySearchBounds.js +2 -2
- package/lib/util/concatenate.js +40 -14
- package/lib/util/createHooksRegistry.js +13 -5
- package/lib/util/dataURL.js +2 -2
- package/lib/util/deterministicGrouping.js +7 -5
- package/lib/util/formatSize.js +6 -2
- package/lib/util/globUtils.js +710 -0
- package/lib/util/identifier.js +23 -6
- package/lib/util/implicitTypeLoaderFallback.js +62 -0
- package/lib/util/internalSerializables.js +88 -71
- package/lib/util/magicComment.js +121 -25
- package/lib/util/numberHash.js +2 -2
- package/lib/wasm-async/AsyncWasmCompileRuntimeModule.js +24 -18
- package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +33 -22
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +79 -16
- package/lib/web/FetchCompileAsyncWasmPlugin.js +19 -0
- package/lib/web/FetchCompileWasmPlugin.js +14 -0
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +2 -0
- package/lib/webpack.js +65 -0
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +3 -0
- package/module.d.ts +21 -0
- package/package.json +12 -11
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +759 -36
- package/schemas/plugins/HtmlParserOptions.check.js +1 -1
- package/schemas/plugins/ProgressPlugin.check.js +1 -1
- package/schemas/plugins/ProgressPlugin.json +17 -1
- package/schemas/plugins/container/ContainerReferencePlugin.check.js +1 -1
- package/schemas/plugins/container/ContainerReferencePlugin.json +1 -0
- package/schemas/plugins/container/ExternalsType.check.js +1 -1
- package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
- package/schemas/plugins/container/ModuleFederationPlugin.json +1 -0
- package/schemas/plugins/css/CssAutoOrModuleParserOptions.check.js +1 -1
- package/schemas/plugins/css/CssModuleParserOptions.check.js +1 -1
- package/schemas/plugins/css/CssParserOptions.check.js +1 -1
- package/types.d.ts +1212 -99
|
@@ -22,8 +22,9 @@ class AwaitDependenciesInitFragment extends InitFragment {
|
|
|
22
22
|
/**
|
|
23
23
|
* Creates an instance of AwaitDependenciesInitFragment.
|
|
24
24
|
* @param {Dependencies} dependencies maps an import var to an async module that needs to be awaited
|
|
25
|
+
* @param {boolean=} generatorLowered module is emitted as a generator, so use `yield` instead of `await`
|
|
25
26
|
*/
|
|
26
|
-
constructor(dependencies) {
|
|
27
|
+
constructor(dependencies, generatorLowered = false) {
|
|
27
28
|
super(
|
|
28
29
|
undefined,
|
|
29
30
|
InitFragment.STAGE_ASYNC_DEPENDENCIES,
|
|
@@ -32,6 +33,8 @@ class AwaitDependenciesInitFragment extends InitFragment {
|
|
|
32
33
|
);
|
|
33
34
|
/** @type {Dependencies} */
|
|
34
35
|
this.dependencies = dependencies;
|
|
36
|
+
/** @type {boolean} */
|
|
37
|
+
this.generatorLowered = generatorLowered;
|
|
35
38
|
}
|
|
36
39
|
|
|
37
40
|
/**
|
|
@@ -44,7 +47,10 @@ class AwaitDependenciesInitFragment extends InitFragment {
|
|
|
44
47
|
for (const [key, value] of this.dependencies) {
|
|
45
48
|
dependencies.set(key, value);
|
|
46
49
|
}
|
|
47
|
-
return new AwaitDependenciesInitFragment(
|
|
50
|
+
return new AwaitDependenciesInitFragment(
|
|
51
|
+
dependencies,
|
|
52
|
+
this.generatorLowered || other.generatorLowered
|
|
53
|
+
);
|
|
48
54
|
}
|
|
49
55
|
|
|
50
56
|
/**
|
|
@@ -61,6 +67,10 @@ class AwaitDependenciesInitFragment extends InitFragment {
|
|
|
61
67
|
const importVars = [...this.dependencies.keys()];
|
|
62
68
|
const asyncModuleValues = [...this.dependencies.values()].join(", ");
|
|
63
69
|
|
|
70
|
+
// In a generator-lowered module (no `async`/`await`, but generators) the
|
|
71
|
+
// dependency `await` becomes `yield`; the body stays a single scope.
|
|
72
|
+
const suspend = this.generatorLowered ? "yield" : "await";
|
|
73
|
+
|
|
64
74
|
const templateInput = [
|
|
65
75
|
`var __webpack_async_dependencies__ = __webpack_handle_async_dependencies__([${asyncModuleValues}]);`
|
|
66
76
|
];
|
|
@@ -70,7 +80,7 @@ class AwaitDependenciesInitFragment extends InitFragment {
|
|
|
70
80
|
!runtimeTemplate.supportsDestructuring()
|
|
71
81
|
) {
|
|
72
82
|
templateInput.push(
|
|
73
|
-
|
|
83
|
+
`var __webpack_async_dependencies_result__ = (__webpack_async_dependencies__.then ? (${suspend} __webpack_async_dependencies__)() : __webpack_async_dependencies__);`
|
|
74
84
|
);
|
|
75
85
|
for (const [index, importVar] of importVars.entries()) {
|
|
76
86
|
templateInput.push(
|
|
@@ -81,7 +91,7 @@ class AwaitDependenciesInitFragment extends InitFragment {
|
|
|
81
91
|
const importVarsStr = importVars.join(", ");
|
|
82
92
|
|
|
83
93
|
templateInput.push(
|
|
84
|
-
`([${importVarsStr}] = __webpack_async_dependencies__.then ? (
|
|
94
|
+
`([${importVarsStr}] = __webpack_async_dependencies__.then ? (${suspend} __webpack_async_dependencies__)() : __webpack_async_dependencies__);`
|
|
85
95
|
);
|
|
86
96
|
}
|
|
87
97
|
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/*
|
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
"use strict";
|
|
6
|
+
|
|
7
|
+
/** @typedef {import("../Module")} Module */
|
|
8
|
+
/** @typedef {import("../ModuleGraph")} ModuleGraph */
|
|
9
|
+
/** @typedef {import("../RuntimeTemplate")} RuntimeTemplate */
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Whether an async module is lowered to a generator: the target has no
|
|
13
|
+
* `async`/`await` but supports generators, and the module contains no
|
|
14
|
+
* top-level `for await…of` (which generators can't express).
|
|
15
|
+
* @param {Module} module module
|
|
16
|
+
* @param {ModuleGraph} moduleGraph module graph
|
|
17
|
+
* @param {RuntimeTemplate} runtimeTemplate runtime template
|
|
18
|
+
* @returns {boolean} true when the module should be emitted as a generator
|
|
19
|
+
*/
|
|
20
|
+
const isGeneratorLowered = (module, moduleGraph, runtimeTemplate) =>
|
|
21
|
+
moduleGraph.isAsync(module) &&
|
|
22
|
+
!runtimeTemplate.supportsAsyncFunction() &&
|
|
23
|
+
Boolean(runtimeTemplate.supportsGenerator()) &&
|
|
24
|
+
!(module.buildInfo && module.buildInfo.usesTopLevelAwaitForOf);
|
|
25
|
+
|
|
26
|
+
module.exports = isGeneratorLowered;
|
|
@@ -1134,7 +1134,7 @@ class PackFileCacheStrategy {
|
|
|
1134
1134
|
* @param {number} options.maxAge max age of cache items
|
|
1135
1135
|
* @param {boolean=} options.profile track and log detailed timing information for individual cache items
|
|
1136
1136
|
* @param {boolean=} options.allowCollectingMemory allow to collect unused memory created during deserialization
|
|
1137
|
-
* @param {false | "gzip" | "brotli"=} options.compression compression used
|
|
1137
|
+
* @param {false | "gzip" | "brotli" | "zstd"=} options.compression compression used
|
|
1138
1138
|
* @param {boolean=} options.readonly disable storing cache into filesystem
|
|
1139
1139
|
*/
|
|
1140
1140
|
constructor({
|
|
@@ -1182,15 +1182,21 @@ class PackFileCacheStrategy {
|
|
|
1182
1182
|
this.readonly = readonly;
|
|
1183
1183
|
/** @type {boolean | undefined} */
|
|
1184
1184
|
this.allowCollectingMemory = allowCollectingMemory;
|
|
1185
|
-
/** @type {false | "gzip" | "brotli" | undefined} */
|
|
1185
|
+
/** @type {false | "gzip" | "brotli" | "zstd" | undefined} */
|
|
1186
1186
|
this.compression = compression;
|
|
1187
|
+
// eslint-disable-next-line n/no-unsupported-features/node-builtins
|
|
1188
|
+
if (compression === "zstd" && !require("zlib").createZstdCompress) {
|
|
1189
|
+
throw new Error("cache.compression: 'zstd' requires Node.js >= 22.15.0");
|
|
1190
|
+
}
|
|
1187
1191
|
/** @type {string} */
|
|
1188
1192
|
this._extension =
|
|
1189
1193
|
compression === "brotli"
|
|
1190
1194
|
? ".pack.br"
|
|
1191
1195
|
: compression === "gzip"
|
|
1192
1196
|
? ".pack.gz"
|
|
1193
|
-
: "
|
|
1197
|
+
: compression === "zstd"
|
|
1198
|
+
? ".pack.zst"
|
|
1199
|
+
: ".pack";
|
|
1194
1200
|
/** @type {SnapshotOptions} */
|
|
1195
1201
|
this.snapshot = snapshot;
|
|
1196
1202
|
/** @type {BuildDependencies} */
|
|
@@ -449,6 +449,25 @@ const resolve = (browsers) => {
|
|
|
449
449
|
kaios: 3,
|
|
450
450
|
node: [7, 6]
|
|
451
451
|
}),
|
|
452
|
+
generator: rawChecker({
|
|
453
|
+
chrome: 39,
|
|
454
|
+
and_chr: 39,
|
|
455
|
+
edge: 13,
|
|
456
|
+
firefox: 26,
|
|
457
|
+
and_ff: 26,
|
|
458
|
+
// ie: Not supported,
|
|
459
|
+
opera: 26,
|
|
460
|
+
op_mob: 26,
|
|
461
|
+
safari: 10,
|
|
462
|
+
ios_saf: 10,
|
|
463
|
+
samsung: [3, 4],
|
|
464
|
+
android: 39,
|
|
465
|
+
and_qq: [10, 4],
|
|
466
|
+
baidu: [7, 12],
|
|
467
|
+
and_uc: [12, 12],
|
|
468
|
+
kaios: [2, 5],
|
|
469
|
+
node: 4
|
|
470
|
+
}),
|
|
452
471
|
/* eslint-enable camelcase */
|
|
453
472
|
browser: browserProperty,
|
|
454
473
|
electron: false,
|
|
@@ -458,6 +477,27 @@ const resolve = (browsers) => {
|
|
|
458
477
|
webworker: false,
|
|
459
478
|
|
|
460
479
|
document: browserProperty,
|
|
480
|
+
modulePreload:
|
|
481
|
+
browserProperty &&
|
|
482
|
+
/* eslint-disable camelcase */
|
|
483
|
+
rawChecker({
|
|
484
|
+
chrome: 66,
|
|
485
|
+
and_chr: 66,
|
|
486
|
+
edge: 79,
|
|
487
|
+
firefox: 115,
|
|
488
|
+
and_ff: 115,
|
|
489
|
+
opera: 53,
|
|
490
|
+
op_mob: 47,
|
|
491
|
+
safari: 17,
|
|
492
|
+
ios_saf: 17,
|
|
493
|
+
samsung: [9, 0],
|
|
494
|
+
android: 66,
|
|
495
|
+
and_qq: [13, 1],
|
|
496
|
+
baidu: [13, 18],
|
|
497
|
+
and_uc: [15, 5],
|
|
498
|
+
kaios: [3, 1]
|
|
499
|
+
}),
|
|
500
|
+
/* eslint-enable camelcase */
|
|
461
501
|
fetchWasm: browserProperty,
|
|
462
502
|
global: nodeProperty,
|
|
463
503
|
importScripts: false,
|
package/lib/config/defaults.js
CHANGED
|
@@ -31,6 +31,7 @@ const {
|
|
|
31
31
|
WEBASSEMBLY_MODULE_TYPE_SYNC
|
|
32
32
|
} = require("../ModuleTypeConstants");
|
|
33
33
|
const Template = require("../Template");
|
|
34
|
+
const RuleSetCompiler = require("../rules/RuleSetCompiler");
|
|
34
35
|
const { cleverMerge } = require("../util/cleverMerge");
|
|
35
36
|
const {
|
|
36
37
|
getDefaultTarget,
|
|
@@ -71,6 +72,7 @@ const {
|
|
|
71
72
|
/** @typedef {import("../../declarations/WebpackOptions").ParserOptionsByModuleTypeKnown} ParserOptionsByModuleTypeKnown */
|
|
72
73
|
/** @typedef {import("../../declarations/WebpackOptions").Performance} Performance */
|
|
73
74
|
/** @typedef {import("../../declarations/WebpackOptions").ResolveOptions} ResolveOptions */
|
|
75
|
+
/** @typedef {import("../../declarations/WebpackOptions").RuleSetRule} RuleSetRule */
|
|
74
76
|
/** @typedef {import("../../declarations/WebpackOptions").RuleSetRules} RuleSetRules */
|
|
75
77
|
/** @typedef {import("../../declarations/WebpackOptions").SnapshotOptions} SnapshotOptions */
|
|
76
78
|
/** @typedef {import("../../declarations/WebpackOptions").WebpackOptionsNormalized} WebpackOptionsNormalized */
|
|
@@ -341,6 +343,26 @@ const applyWebpackOptionsDefaults = (options, compilerIndex) => {
|
|
|
341
343
|
}
|
|
342
344
|
}
|
|
343
345
|
|
|
346
|
+
D(options, "watch", false);
|
|
347
|
+
D(options, "profile", false);
|
|
348
|
+
D(options, "parallelism", 100);
|
|
349
|
+
D(options, "recordsInputPath", false);
|
|
350
|
+
D(options, "recordsOutputPath", false);
|
|
351
|
+
|
|
352
|
+
// Capture the raw html intent before "auto" is resolved: only an explicit
|
|
353
|
+
// `html: true` (or futureDefaults) keeps `.html` ahead of `.js` when resolving.
|
|
354
|
+
const htmlExplicitlyEnabled = options.experiments.html === true;
|
|
355
|
+
const htmlWasUnset = options.experiments.html === undefined;
|
|
356
|
+
|
|
357
|
+
applyExperimentsDefaults(options.experiments, {
|
|
358
|
+
production,
|
|
359
|
+
development,
|
|
360
|
+
targetProperties,
|
|
361
|
+
rules: options.module.rules
|
|
362
|
+
});
|
|
363
|
+
|
|
364
|
+
// After experiments are resolved: the default dev source map depends on the
|
|
365
|
+
// (possibly "auto"-resolved) `experiments.css` value.
|
|
344
366
|
F(
|
|
345
367
|
options,
|
|
346
368
|
"devtool",
|
|
@@ -363,24 +385,20 @@ const applyWebpackOptionsDefaults = (options, compilerIndex) => {
|
|
|
363
385
|
)
|
|
364
386
|
);
|
|
365
387
|
|
|
366
|
-
D(options, "watch", false);
|
|
367
|
-
D(options, "profile", false);
|
|
368
|
-
D(options, "parallelism", 100);
|
|
369
|
-
D(options, "recordsInputPath", false);
|
|
370
|
-
D(options, "recordsOutputPath", false);
|
|
371
|
-
|
|
372
|
-
applyExperimentsDefaults(options.experiments, {
|
|
373
|
-
production,
|
|
374
|
-
development,
|
|
375
|
-
targetProperties
|
|
376
|
-
});
|
|
377
|
-
|
|
378
388
|
const futureDefaults =
|
|
379
389
|
/** @type {NonNullable<ExperimentsNormalized["futureDefaults"]>} */
|
|
380
390
|
(options.experiments.futureDefaults);
|
|
381
391
|
|
|
392
|
+
// `.html` outranks `.js` only for an explicit opt-in (`html: true`, or the
|
|
393
|
+
// futureDefaults-forced default), never for the auto-enabled default.
|
|
394
|
+
const htmlFirst = htmlExplicitlyEnabled || (htmlWasUnset && futureDefaults);
|
|
395
|
+
|
|
382
396
|
F(options, "validate", () => !(futureDefaults === true && production));
|
|
383
397
|
|
|
398
|
+
// Progress lives on infrastructureLogging; webpack@6 shows the interactive
|
|
399
|
+
// bar by default (`"auto"` = TTY only), webpack@5 stays opt-in.
|
|
400
|
+
D(options.infrastructureLogging, "progress", futureDefaults ? "auto" : false);
|
|
401
|
+
|
|
384
402
|
F(options, "cache", () =>
|
|
385
403
|
development ? { type: /** @type {"memory"} */ ("memory") } : false
|
|
386
404
|
);
|
|
@@ -414,7 +432,7 @@ const applyWebpackOptionsDefaults = (options, compilerIndex) => {
|
|
|
414
432
|
entry: options.entry,
|
|
415
433
|
futureDefaults,
|
|
416
434
|
asyncWebAssembly:
|
|
417
|
-
/** @type {
|
|
435
|
+
/** @type {boolean} */
|
|
418
436
|
(options.experiments.asyncWebAssembly)
|
|
419
437
|
});
|
|
420
438
|
|
|
@@ -430,16 +448,16 @@ const applyWebpackOptionsDefaults = (options, compilerIndex) => {
|
|
|
430
448
|
/** @type {NonNullable<ExperimentsNormalized["syncWebAssembly"]>} */
|
|
431
449
|
(options.experiments.syncWebAssembly),
|
|
432
450
|
asyncWebAssembly:
|
|
433
|
-
/** @type {
|
|
451
|
+
/** @type {boolean} */
|
|
434
452
|
(options.experiments.asyncWebAssembly),
|
|
435
453
|
css:
|
|
436
|
-
/** @type {
|
|
454
|
+
/** @type {boolean} */
|
|
437
455
|
(options.experiments.css),
|
|
438
456
|
html:
|
|
439
|
-
/** @type {
|
|
457
|
+
/** @type {boolean} */
|
|
440
458
|
(options.experiments.html),
|
|
441
459
|
typescript:
|
|
442
|
-
/** @type {
|
|
460
|
+
/** @type {boolean} */
|
|
443
461
|
(options.experiments.typescript),
|
|
444
462
|
deferImport:
|
|
445
463
|
/** @type {NonNullable<ExperimentsNormalized["deferImport"]>} */
|
|
@@ -458,6 +476,29 @@ const applyWebpackOptionsDefaults = (options, compilerIndex) => {
|
|
|
458
476
|
library: options.output.library
|
|
459
477
|
});
|
|
460
478
|
|
|
479
|
+
// `output.resourceHints.urlHints` shorthand: fan the project-wide rules out
|
|
480
|
+
// as the base `urlHints` of every URL-emitting parser (JS `new URL`, CSS
|
|
481
|
+
// `url()`, HTML `<img src>`). They go first so parser-scoped
|
|
482
|
+
// `parser.<type>.urlHints` rules — matched later, last-match-wins — override.
|
|
483
|
+
const outputUrlHints =
|
|
484
|
+
options.output.resourceHints && options.output.resourceHints.urlHints;
|
|
485
|
+
if (outputUrlHints && outputUrlHints.length > 0) {
|
|
486
|
+
for (const type of [
|
|
487
|
+
"javascript",
|
|
488
|
+
CSS_MODULE_TYPE,
|
|
489
|
+
CSS_MODULE_TYPE_AUTO,
|
|
490
|
+
CSS_MODULE_TYPE_MODULE,
|
|
491
|
+
CSS_MODULE_TYPE_GLOBAL,
|
|
492
|
+
HTML_MODULE_TYPE
|
|
493
|
+
]) {
|
|
494
|
+
const parser =
|
|
495
|
+
/** @type {{ urlHints?: import("../../declarations/WebpackOptions").UrlHintRule[] } | undefined} */
|
|
496
|
+
(options.module.parser[type]);
|
|
497
|
+
if (!parser) continue;
|
|
498
|
+
parser.urlHints = [...outputUrlHints, ...(parser.urlHints || [])];
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
|
|
461
502
|
applyExternalsPresetsDefaults(options.externalsPresets, {
|
|
462
503
|
targetProperties,
|
|
463
504
|
buildHttp: Boolean(options.experiments.buildHttp),
|
|
@@ -514,7 +555,7 @@ const applyWebpackOptionsDefaults = (options, compilerIndex) => {
|
|
|
514
555
|
development,
|
|
515
556
|
production,
|
|
516
557
|
css:
|
|
517
|
-
/** @type {
|
|
558
|
+
/** @type {boolean} */
|
|
518
559
|
(options.experiments.css),
|
|
519
560
|
records: Boolean(options.recordsInputPath || options.recordsOutputPath)
|
|
520
561
|
});
|
|
@@ -526,13 +567,14 @@ const applyWebpackOptionsDefaults = (options, compilerIndex) => {
|
|
|
526
567
|
targetProperties,
|
|
527
568
|
mode: /** @type {Mode} */ (options.mode),
|
|
528
569
|
css:
|
|
529
|
-
/** @type {
|
|
570
|
+
/** @type {boolean} */
|
|
530
571
|
(options.experiments.css),
|
|
531
572
|
html:
|
|
532
|
-
/** @type {
|
|
573
|
+
/** @type {boolean} */
|
|
533
574
|
(options.experiments.html),
|
|
575
|
+
htmlFirst,
|
|
534
576
|
typescript:
|
|
535
|
-
/** @type {
|
|
577
|
+
/** @type {boolean} */
|
|
536
578
|
(options.experiments.typescript)
|
|
537
579
|
}),
|
|
538
580
|
options.resolve
|
|
@@ -570,17 +612,22 @@ const applyWebpackOptionsDefaults = (options, compilerIndex) => {
|
|
|
570
612
|
* @param {boolean} options.production is production
|
|
571
613
|
* @param {boolean} options.development is development mode
|
|
572
614
|
* @param {TargetProperties | false} options.targetProperties target properties
|
|
615
|
+
* @param {RuleSetRules} options.rules user `module.rules`, used to resolve the css/html/asyncWebAssembly/typescript "auto" defaults
|
|
573
616
|
* @returns {void}
|
|
574
617
|
*/
|
|
575
618
|
const applyExperimentsDefaults = (
|
|
576
619
|
experiments,
|
|
577
|
-
{ production, development, targetProperties }
|
|
620
|
+
{ production, development, targetProperties, rules }
|
|
578
621
|
) => {
|
|
579
622
|
D(experiments, "futureDefaults", false);
|
|
580
623
|
D(experiments, "backCompat", !experiments.futureDefaults);
|
|
581
624
|
// TODO do we need sync web assembly in webpack@6?
|
|
582
625
|
D(experiments, "syncWebAssembly", false);
|
|
583
|
-
D(
|
|
626
|
+
D(
|
|
627
|
+
experiments,
|
|
628
|
+
"asyncWebAssembly",
|
|
629
|
+
experiments.futureDefaults ? true : "auto"
|
|
630
|
+
);
|
|
584
631
|
// the universal target (web + node, neither specific) only works as ESM
|
|
585
632
|
const universal =
|
|
586
633
|
Boolean(targetProperties) &&
|
|
@@ -599,12 +646,52 @@ const applyExperimentsDefaults = (
|
|
|
599
646
|
D(experiments, "cacheUnaffected", experiments.futureDefaults);
|
|
600
647
|
D(experiments, "deferImport", false);
|
|
601
648
|
D(experiments, "sourceImport", false);
|
|
602
|
-
F(experiments, "css", () => (experiments.futureDefaults ? true :
|
|
603
|
-
F(experiments, "html", () => (experiments.futureDefaults ? true :
|
|
649
|
+
F(experiments, "css", () => (experiments.futureDefaults ? true : "auto"));
|
|
650
|
+
F(experiments, "html", () => (experiments.futureDefaults ? true : "auto"));
|
|
604
651
|
F(experiments, "typescript", () =>
|
|
605
|
-
experiments.futureDefaults ? true :
|
|
652
|
+
experiments.futureDefaults ? true : "auto"
|
|
606
653
|
);
|
|
607
654
|
|
|
655
|
+
// Resolve the "auto" default: enable the built-in css/html module type unless
|
|
656
|
+
// the user already registered a loader (or explicit type) for these files, so
|
|
657
|
+
// enabling them by default does not break existing css-loader/html-loader setups.
|
|
658
|
+
// The built-in `/\.css$/i` rule also covers `.module.css`, so a loader scoped to
|
|
659
|
+
// CSS modules must disable the built-in type too — sample both extensions.
|
|
660
|
+
// When enabled implicitly the value stays `"auto"` (truthy): Css/HtmlModulesPlugin
|
|
661
|
+
// then step aside per-module for requests that loaders were applied to
|
|
662
|
+
// (inline requests or loaders injected via hooks, e.g. html-webpack-plugin).
|
|
663
|
+
// TODO webpack 6: css/html default to `true`, drop the `"auto"` marker.
|
|
664
|
+
if (experiments.css === "auto") {
|
|
665
|
+
experiments.css =
|
|
666
|
+
!(
|
|
667
|
+
RuleSetCompiler.hasRuleForResource(rules, "/file.css") ||
|
|
668
|
+
RuleSetCompiler.hasRuleForResource(rules, "/file.module.css")
|
|
669
|
+
) && "auto";
|
|
670
|
+
}
|
|
671
|
+
if (experiments.html === "auto") {
|
|
672
|
+
experiments.html =
|
|
673
|
+
!RuleSetCompiler.hasRuleForResource(rules, "/file.html") && "auto";
|
|
674
|
+
}
|
|
675
|
+
// Auto-enable only when the built-in TypeScript support can actually run:
|
|
676
|
+
// it needs `module.stripTypeScriptTypes` (Node.js >= 22.6) and must step
|
|
677
|
+
// aside for a loader registered for `.ts`/`.mts`/`.cts` (e.g. ts-loader).
|
|
678
|
+
if (experiments.typescript === "auto") {
|
|
679
|
+
experiments.typescript =
|
|
680
|
+
// eslint-disable-next-line n/no-unsupported-features/node-builtins
|
|
681
|
+
typeof require("module").stripTypeScriptTypes === "function" &&
|
|
682
|
+
!(
|
|
683
|
+
RuleSetCompiler.hasRuleForResource(rules, "/file.ts") ||
|
|
684
|
+
RuleSetCompiler.hasRuleForResource(rules, "/file.mts") ||
|
|
685
|
+
RuleSetCompiler.hasRuleForResource(rules, "/file.cts")
|
|
686
|
+
);
|
|
687
|
+
}
|
|
688
|
+
// `syncWebAssembly` already claims `.wasm`, so don't let "auto" override it.
|
|
689
|
+
if (experiments.asyncWebAssembly === "auto") {
|
|
690
|
+
experiments.asyncWebAssembly =
|
|
691
|
+
!experiments.syncWebAssembly &&
|
|
692
|
+
!RuleSetCompiler.hasRuleForResource(rules, "/file.wasm");
|
|
693
|
+
}
|
|
694
|
+
|
|
608
695
|
if (typeof experiments.buildHttp === "object") {
|
|
609
696
|
D(experiments.buildHttp, "frozen", production);
|
|
610
697
|
D(experiments.buildHttp, "upgrade", false);
|
|
@@ -820,6 +907,7 @@ const applyJavascriptParserOptionsDefaults = (
|
|
|
820
907
|
D(parserOptions, "sourceImport", sourceImport);
|
|
821
908
|
D(parserOptions, "typescript", typescript);
|
|
822
909
|
if (futureDefaults) D(parserOptions, "exportsPresence", "error");
|
|
910
|
+
D(parserOptions, "strictModeViolations", futureDefaults ? "error" : "warn");
|
|
823
911
|
D(parserOptions, "anonymousDefaultExportName", !library);
|
|
824
912
|
};
|
|
825
913
|
|
|
@@ -989,6 +1077,18 @@ const applyModuleDefaults = (
|
|
|
989
1077
|
"namedExports",
|
|
990
1078
|
true
|
|
991
1079
|
);
|
|
1080
|
+
D(
|
|
1081
|
+
/** @type {NonNullable<ParserOptionsByModuleTypeKnown[CSS_MODULE_TYPE]>} */
|
|
1082
|
+
(module.parser[CSS_MODULE_TYPE]),
|
|
1083
|
+
"customMedia",
|
|
1084
|
+
true
|
|
1085
|
+
);
|
|
1086
|
+
D(
|
|
1087
|
+
/** @type {NonNullable<ParserOptionsByModuleTypeKnown[CSS_MODULE_TYPE]>} */
|
|
1088
|
+
(module.parser[CSS_MODULE_TYPE]),
|
|
1089
|
+
"customSelectors",
|
|
1090
|
+
true
|
|
1091
|
+
);
|
|
992
1092
|
|
|
993
1093
|
for (const type of [
|
|
994
1094
|
CSS_MODULE_TYPE_AUTO,
|
|
@@ -1033,6 +1133,18 @@ const applyModuleDefaults = (
|
|
|
1033
1133
|
"grid",
|
|
1034
1134
|
true
|
|
1035
1135
|
);
|
|
1136
|
+
D(
|
|
1137
|
+
/** @type {NonNullable<ParserOptionsByModuleTypeKnown[CSS_MODULE_TYPE_AUTO]> | NonNullable<ParserOptionsByModuleTypeKnown[CSS_MODULE_TYPE_MODULE]> | NonNullable<ParserOptionsByModuleTypeKnown[CSS_MODULE_TYPE_GLOBAL]>} */
|
|
1138
|
+
(module.parser[type]),
|
|
1139
|
+
"customMedia",
|
|
1140
|
+
true
|
|
1141
|
+
);
|
|
1142
|
+
D(
|
|
1143
|
+
/** @type {NonNullable<ParserOptionsByModuleTypeKnown[CSS_MODULE_TYPE_AUTO]> | NonNullable<ParserOptionsByModuleTypeKnown[CSS_MODULE_TYPE_MODULE]> | NonNullable<ParserOptionsByModuleTypeKnown[CSS_MODULE_TYPE_GLOBAL]>} */
|
|
1144
|
+
(module.parser[type]),
|
|
1145
|
+
"customSelectors",
|
|
1146
|
+
true
|
|
1147
|
+
);
|
|
1036
1148
|
}
|
|
1037
1149
|
|
|
1038
1150
|
F(module.generator, CSS_MODULE_TYPE, () => ({}));
|
|
@@ -1407,6 +1519,46 @@ const applyModuleDefaults = (
|
|
|
1407
1519
|
type: ASSET_MODULE_TYPE_BYTES
|
|
1408
1520
|
}
|
|
1409
1521
|
);
|
|
1522
|
+
if (html) {
|
|
1523
|
+
// A `.webmanifest` referenced by `<link rel="manifest">` is a `url`
|
|
1524
|
+
// dependency; route it to the `asset/webmanifest` type so its icon URLs
|
|
1525
|
+
// are parsed. Must come after the generic `url` → asset rule so it wins.
|
|
1526
|
+
rules.push({
|
|
1527
|
+
dependency: "url",
|
|
1528
|
+
test: /\.webmanifest$/i,
|
|
1529
|
+
type: "asset/webmanifest"
|
|
1530
|
+
});
|
|
1531
|
+
// A generated manifest (`output.html.manifest` object) is injected as a
|
|
1532
|
+
// `data:application/manifest+json` URL with no `.webmanifest` extension;
|
|
1533
|
+
// route it by mimetype so its icons are parsed and hashed too.
|
|
1534
|
+
rules.push({
|
|
1535
|
+
dependency: "url",
|
|
1536
|
+
mimetype: "application/manifest+json",
|
|
1537
|
+
type: "asset/webmanifest"
|
|
1538
|
+
});
|
|
1539
|
+
}
|
|
1540
|
+
if (futureDefaults) {
|
|
1541
|
+
rules.push({
|
|
1542
|
+
oneOf: [
|
|
1543
|
+
{
|
|
1544
|
+
resourceQuery: /(\?|&)raw(&|$)/,
|
|
1545
|
+
type: ASSET_MODULE_TYPE_SOURCE
|
|
1546
|
+
},
|
|
1547
|
+
{
|
|
1548
|
+
resourceQuery: /(\?|&)url(&|$)/,
|
|
1549
|
+
type: ASSET_MODULE_TYPE_RESOURCE
|
|
1550
|
+
},
|
|
1551
|
+
{
|
|
1552
|
+
resourceQuery: /(\?|&)no-inline(&|$)/,
|
|
1553
|
+
type: ASSET_MODULE_TYPE_RESOURCE
|
|
1554
|
+
},
|
|
1555
|
+
{
|
|
1556
|
+
resourceQuery: /(\?|&)inline(&|$)/,
|
|
1557
|
+
type: ASSET_MODULE_TYPE_INLINE
|
|
1558
|
+
}
|
|
1559
|
+
]
|
|
1560
|
+
});
|
|
1561
|
+
}
|
|
1410
1562
|
return rules;
|
|
1411
1563
|
});
|
|
1412
1564
|
};
|
|
@@ -1565,6 +1717,11 @@ const applyOutputDefaults = (
|
|
|
1565
1717
|
() =>
|
|
1566
1718
|
tp && optimistic(/** @type {boolean | undefined} */ (tp.asyncFunction))
|
|
1567
1719
|
);
|
|
1720
|
+
F(
|
|
1721
|
+
environment,
|
|
1722
|
+
"generator",
|
|
1723
|
+
() => tp && optimistic(/** @type {boolean | undefined} */ (tp.generator))
|
|
1724
|
+
);
|
|
1568
1725
|
F(
|
|
1569
1726
|
environment,
|
|
1570
1727
|
"forOf",
|
|
@@ -1639,6 +1796,30 @@ const applyOutputDefaults = (
|
|
|
1639
1796
|
"document",
|
|
1640
1797
|
() => tp && optimistic(/** @type {boolean | undefined} */ (tp.document))
|
|
1641
1798
|
);
|
|
1799
|
+
F(
|
|
1800
|
+
environment,
|
|
1801
|
+
"modulePreload",
|
|
1802
|
+
() =>
|
|
1803
|
+
tp && optimistic(/** @type {boolean | undefined} */ (tp.modulePreload))
|
|
1804
|
+
);
|
|
1805
|
+
|
|
1806
|
+
// Vite-style default for ESM output (`output.module`): preload the entry's
|
|
1807
|
+
// initial dependency graph, which native `import()` would otherwise fetch in
|
|
1808
|
+
// a waterfall. Classic output loads initial chunks via parallel `<script>`
|
|
1809
|
+
// tags (no waterfall), so it stays opt-in.
|
|
1810
|
+
if (output.module && output.resourceHints === undefined) {
|
|
1811
|
+
output.resourceHints = {};
|
|
1812
|
+
}
|
|
1813
|
+
if (output.resourceHints) {
|
|
1814
|
+
if (output.module) D(output.resourceHints, "initial", true);
|
|
1815
|
+
// `modulePreloadPolyfill` defaults from the target's modulepreload
|
|
1816
|
+
// support: inject the polyfill iff the environment lacks it.
|
|
1817
|
+
D(
|
|
1818
|
+
output.resourceHints,
|
|
1819
|
+
"modulePreloadPolyfill",
|
|
1820
|
+
!environment.modulePreload
|
|
1821
|
+
);
|
|
1822
|
+
}
|
|
1642
1823
|
|
|
1643
1824
|
D(output, "filename", output.module ? "[name].mjs" : "[name].js");
|
|
1644
1825
|
F(output, "iife", () => !output.module);
|
|
@@ -1718,6 +1899,8 @@ const applyOutputDefaults = (
|
|
|
1718
1899
|
D(output, "html", false);
|
|
1719
1900
|
D(output, "assetModuleFilename", "[hash][ext][query][fragment]");
|
|
1720
1901
|
D(output, "webassemblyModuleFilename", "[hash].module.wasm");
|
|
1902
|
+
// On by default like other wasm toolchains; set false to drop the fallback runtime code.
|
|
1903
|
+
D(output, "wasmStreamingFallback", true);
|
|
1721
1904
|
D(output, "compareBeforeEmit", true);
|
|
1722
1905
|
D(output, "charset", !futureDefaults);
|
|
1723
1906
|
const uniqueNameId = Template.toIdentifier(
|
|
@@ -1863,7 +2046,9 @@ const applyOutputDefaults = (
|
|
|
1863
2046
|
D(
|
|
1864
2047
|
output,
|
|
1865
2048
|
"hotUpdateMainFilename",
|
|
1866
|
-
|
|
2049
|
+
// Only `chunkLoading: "import"` loads the manifest via `import()` (needs an
|
|
2050
|
+
// `export default` ES module); every other loader fetches it as raw JSON.
|
|
2051
|
+
`[runtime].[fullhash].hot-update.${output.chunkLoading === "import" ? "json.mjs" : "json"}`
|
|
1867
2052
|
);
|
|
1868
2053
|
D(output, "crossOriginLoading", false);
|
|
1869
2054
|
F(output, "scriptType", () => (output.module ? "module" : false));
|
|
@@ -2255,6 +2440,7 @@ const applyOptimizationDefaults = (
|
|
|
2255
2440
|
* @param {Mode} options.mode mode
|
|
2256
2441
|
* @param {boolean} options.css is css enabled
|
|
2257
2442
|
* @param {boolean} options.html is html enabled
|
|
2443
|
+
* @param {boolean} options.htmlFirst whether `.html` should outrank `.js` when resolving (only when html was explicitly enabled)
|
|
2258
2444
|
* @param {boolean} options.typescript is typescript enabled
|
|
2259
2445
|
* @returns {ResolveOptions} resolve options
|
|
2260
2446
|
*/
|
|
@@ -2265,6 +2451,7 @@ const getResolveDefaults = ({
|
|
|
2265
2451
|
mode,
|
|
2266
2452
|
css,
|
|
2267
2453
|
html,
|
|
2454
|
+
htmlFirst,
|
|
2268
2455
|
typescript
|
|
2269
2456
|
}) => {
|
|
2270
2457
|
/** @type {string[]} */
|
|
@@ -2286,10 +2473,13 @@ const getResolveDefaults = ({
|
|
|
2286
2473
|
? [".ts", ".js", ".json", ".wasm"]
|
|
2287
2474
|
: [".js", ".json", ".wasm"];
|
|
2288
2475
|
|
|
2289
|
-
//
|
|
2476
|
+
// Explicitly enabling html keeps `.html` ahead of `.js` (html-as-entry feature).
|
|
2477
|
+
// Auto-enabled html/css are lower-priority fallbacks after `.js`, so enabling
|
|
2478
|
+
// them by default never makes `x.html`/`x.css` shadow `x.js`.
|
|
2290
2479
|
const esmResolveExtensions = [
|
|
2291
|
-
...(html ? [".html"] : []),
|
|
2480
|
+
...(html && htmlFirst ? [".html"] : []),
|
|
2292
2481
|
...jsExtensions,
|
|
2482
|
+
...(html && !htmlFirst ? [".html"] : []),
|
|
2293
2483
|
...(css ? [".css"] : [])
|
|
2294
2484
|
];
|
|
2295
2485
|
|
|
@@ -133,6 +133,30 @@ const keyedNestedConfig = (value, fn, customKeys) => {
|
|
|
133
133
|
return result;
|
|
134
134
|
};
|
|
135
135
|
|
|
136
|
+
/**
|
|
137
|
+
* Normalize `output.resourceHints` into its object form: the scalar / array /
|
|
138
|
+
* function shorthand becomes `{ initial: <value> }` (with `"preload"` aliased to
|
|
139
|
+
* `true`); an object is passed through, its `initial` getting the same alias.
|
|
140
|
+
* @param {import("../../declarations/WebpackOptions").ResourceHints=} resourceHints raw value
|
|
141
|
+
* @returns {import("../../declarations/WebpackOptions").ResourceHintsOptions | undefined} normalized object form
|
|
142
|
+
*/
|
|
143
|
+
const normalizeResourceHints = (resourceHints) => {
|
|
144
|
+
if (resourceHints === undefined) return undefined;
|
|
145
|
+
/**
|
|
146
|
+
* @param {import("../../declarations/WebpackOptions").ResourceHintsInitial=} value initial value
|
|
147
|
+
* @returns {import("../../declarations/WebpackOptions").ResourceHintsInitial | undefined} `"preload"` aliased to `true`
|
|
148
|
+
*/
|
|
149
|
+
const alias = (value) => (value === "preload" ? true : value);
|
|
150
|
+
if (
|
|
151
|
+
typeof resourceHints === "object" &&
|
|
152
|
+
!Array.isArray(resourceHints) &&
|
|
153
|
+
typeof resourceHints !== "function"
|
|
154
|
+
) {
|
|
155
|
+
return { ...resourceHints, initial: alias(resourceHints.initial) };
|
|
156
|
+
}
|
|
157
|
+
return { initial: alias(resourceHints) };
|
|
158
|
+
};
|
|
159
|
+
|
|
136
160
|
/**
|
|
137
161
|
* Gets normalized webpack options.
|
|
138
162
|
* @param {WebpackOptions} config input config
|
|
@@ -404,6 +428,7 @@ const getNormalizedWebpackOptions = (config) => ({
|
|
|
404
428
|
path: output.path,
|
|
405
429
|
pathinfo: output.pathinfo,
|
|
406
430
|
publicPath: output.publicPath,
|
|
431
|
+
resourceHints: normalizeResourceHints(output.resourceHints),
|
|
407
432
|
sourceMapFilename: output.sourceMapFilename,
|
|
408
433
|
sourcePrefix: output.sourcePrefix,
|
|
409
434
|
strictModuleErrorHandling: output.strictModuleErrorHandling,
|
|
@@ -421,6 +446,7 @@ const getNormalizedWebpackOptions = (config) => ({
|
|
|
421
446
|
),
|
|
422
447
|
uniqueName: output.uniqueName,
|
|
423
448
|
wasmLoading: output.wasmLoading,
|
|
449
|
+
wasmStreamingFallback: output.wasmStreamingFallback,
|
|
424
450
|
webassemblyModuleFilename: output.webassemblyModuleFilename,
|
|
425
451
|
workerPublicPath: output.workerPublicPath,
|
|
426
452
|
workerChunkFilename: output.workerChunkFilename,
|