webpack 5.104.1 → 5.105.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/webpack.js +6 -3
- package/lib/APIPlugin.js +85 -15
- package/lib/AbstractMethodError.js +1 -0
- package/lib/AsyncDependenciesBlock.js +13 -1
- package/lib/AsyncDependencyToInitialChunkError.js +1 -0
- package/lib/AutomaticPrefetchPlugin.js +1 -1
- package/lib/BannerPlugin.js +2 -0
- package/lib/CacheFacade.js +2 -2
- package/lib/CaseSensitiveModulesWarning.js +1 -0
- package/lib/Chunk.js +8 -4
- package/lib/ChunkGraph.js +30 -9
- package/lib/ChunkGroup.js +6 -3
- package/lib/ChunkRenderError.js +2 -0
- package/lib/CleanPlugin.js +4 -1
- package/lib/CodeGenerationError.js +7 -1
- package/lib/CodeGenerationResults.js +10 -3
- package/lib/CommentCompilationWarning.js +2 -1
- package/lib/Compilation.js +280 -236
- package/lib/Compiler.js +3 -2
- package/lib/ConcatenationScope.js +2 -1
- package/lib/ConcurrentCompilationError.js +3 -3
- package/lib/ContextModule.js +248 -111
- package/lib/ContextModuleFactory.js +14 -2
- package/lib/DefinePlugin.js +3 -1
- package/lib/DelegatedModule.js +6 -0
- package/lib/DelegatedModuleFactoryPlugin.js +2 -0
- package/lib/Dependency.js +6 -1
- package/lib/DependencyTemplates.js +3 -2
- package/lib/DllModule.js +2 -0
- package/lib/DllReferencePlugin.js +1 -0
- package/lib/DotenvPlugin.js +11 -5
- package/lib/DynamicEntryPlugin.js +1 -0
- package/lib/EnvironmentNotSupportAsyncWarning.js +1 -0
- package/lib/EvalSourceMapDevToolPlugin.js +17 -13
- package/lib/ExportsInfo.js +8 -4
- package/lib/ExternalModule.js +16 -0
- package/lib/FalseIIFEUmdWarning.js +1 -0
- package/lib/FileSystemInfo.js +49 -25
- package/lib/FlagDependencyExportsPlugin.js +8 -1
- package/lib/FlagDependencyUsagePlugin.js +9 -7
- package/lib/HarmonyLinkingError.js +1 -0
- package/lib/HookWebpackError.js +2 -0
- package/lib/HotModuleReplacementPlugin.js +16 -2
- package/lib/InitFragment.js +1 -0
- package/lib/InvalidDependenciesModuleWarning.js +1 -0
- package/lib/LibManifestPlugin.js +1 -0
- package/lib/ManifestPlugin.js +4 -1
- package/lib/Module.js +7 -4
- package/lib/ModuleBuildError.js +3 -1
- package/lib/ModuleDependencyError.js +1 -0
- package/lib/ModuleDependencyWarning.js +1 -0
- package/lib/ModuleError.js +2 -1
- package/lib/ModuleFilenameHelpers.js +2 -1
- package/lib/ModuleGraph.js +3 -0
- package/lib/ModuleGraphConnection.js +10 -1
- package/lib/ModuleHashingError.js +2 -0
- package/lib/ModuleInfoHeaderPlugin.js +6 -1
- package/lib/ModuleNotFoundError.js +1 -0
- package/lib/ModuleParseError.js +5 -1
- package/lib/ModuleProfile.js +1 -1
- package/lib/ModuleRestoreError.js +2 -0
- package/lib/ModuleSourceTypeConstants.js +1 -11
- package/lib/ModuleStoreError.js +2 -0
- package/lib/ModuleWarning.js +3 -1
- package/lib/MultiCompiler.js +11 -7
- package/lib/MultiWatching.js +2 -2
- package/lib/NoModeWarning.js +1 -0
- package/lib/NodeStuffInWebError.js +1 -0
- package/lib/NormalModule.js +26 -5
- package/lib/NormalModuleFactory.js +20 -4
- package/lib/OptionsApply.js +3 -1
- package/lib/ProgressPlugin.js +4 -0
- package/lib/RawModule.js +2 -0
- package/lib/RuntimeModule.js +10 -0
- package/lib/RuntimePlugin.js +7 -9
- package/lib/RuntimeTemplate.js +14 -7
- package/lib/SourceMapDevToolPlugin.js +30 -23
- package/lib/Template.js +10 -5
- package/lib/TemplatedPathPlugin.js +4 -2
- package/lib/UnhandledSchemeError.js +1 -0
- package/lib/UnsupportedFeatureWarning.js +1 -0
- package/lib/WarnDeprecatedOptionPlugin.js +1 -0
- package/lib/WatchIgnorePlugin.js +1 -1
- package/lib/Watching.js +5 -0
- package/lib/WebpackError.js +4 -0
- package/lib/WebpackOptionsApply.js +60 -40
- package/lib/asset/AssetBytesGenerator.js +1 -0
- package/lib/asset/AssetGenerator.js +9 -3
- package/lib/asset/AssetModulesPlugin.js +33 -2
- package/lib/asset/AssetSourceGenerator.js +1 -0
- package/lib/asset/RawDataUrlModule.js +4 -0
- package/lib/async-modules/AwaitDependenciesInitFragment.js +4 -1
- package/lib/buildChunkGraph.js +31 -2
- package/lib/cache/MemoryWithGcCachePlugin.js +1 -0
- package/lib/cache/PackFileCacheStrategy.js +41 -8
- package/lib/cache/getLazyHashedEtag.js +13 -4
- package/lib/cache/mergeEtags.js +3 -1
- package/lib/cli.js +3 -1
- package/lib/config/defaults.js +65 -44
- package/lib/config/normalization.js +96 -0
- package/lib/container/ContainerEntryModule.js +4 -0
- package/lib/container/FallbackModule.js +2 -0
- package/lib/container/HoistContainerReferencesPlugin.js +6 -0
- package/lib/container/RemoteModule.js +19 -0
- package/lib/css/CssGenerator.js +31 -4
- package/lib/css/CssModulesPlugin.js +26 -30
- package/lib/css/CssParser.js +12 -9
- package/lib/debug/ProfilingPlugin.js +1 -0
- package/lib/dependencies/AMDDefineDependency.js +3 -1
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +6 -0
- package/lib/dependencies/AMDPlugin.js +1 -1
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +7 -1
- package/lib/dependencies/CachedConstDependency.js +1 -0
- package/lib/dependencies/CommonJsDependencyHelpers.js +2 -0
- package/lib/dependencies/CommonJsExportRequireDependency.js +1 -0
- package/lib/dependencies/CommonJsFullRequireDependency.js +2 -0
- package/lib/dependencies/CommonJsImportsParserPlugin.js +3 -0
- package/lib/dependencies/CommonJsRequireContextDependency.js +2 -2
- package/lib/dependencies/CommonJsSelfReferenceDependency.js +1 -0
- package/lib/dependencies/ConstDependency.js +1 -0
- package/lib/dependencies/ContextDependencyHelpers.js +11 -4
- package/lib/dependencies/ContextElementDependency.js +1 -0
- package/lib/dependencies/CriticalDependencyWarning.js +1 -0
- package/lib/dependencies/CssIcssExportDependency.js +5 -4
- package/lib/dependencies/CssIcssSymbolDependency.js +1 -0
- package/lib/dependencies/CssUrlDependency.js +2 -3
- package/lib/dependencies/ExternalModuleInitFragment.js +4 -1
- package/lib/dependencies/ExternalModuleInitFragmentDependency.js +0 -9
- package/lib/dependencies/HarmonyAcceptDependency.js +3 -0
- package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +1 -0
- package/lib/dependencies/HarmonyExportExpressionDependency.js +4 -0
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +8 -1
- package/lib/dependencies/HarmonyExportInitFragment.js +17 -3
- package/lib/dependencies/HarmonyExportSpecifierDependency.js +4 -0
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +266 -5
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +22 -3
- package/lib/dependencies/ImportDependency.js +1 -0
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +1 -0
- package/lib/dependencies/ImportMetaPlugin.js +53 -11
- package/lib/dependencies/ImportParserPlugin.js +7 -12
- package/lib/dependencies/LoaderPlugin.js +3 -0
- package/lib/dependencies/ModuleDecoratorDependency.js +1 -0
- package/lib/dependencies/ModuleDependency.js +1 -0
- package/lib/dependencies/ModuleInitFragmentDependency.js +87 -0
- package/lib/dependencies/ProvidedDependency.js +1 -0
- package/lib/dependencies/RequireContextPlugin.js +1 -0
- package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +7 -2
- package/lib/dependencies/RuntimeRequirementsDependency.js +1 -0
- package/lib/dependencies/WorkerDependency.js +9 -3
- package/lib/dependencies/WorkerPlugin.js +1 -0
- package/lib/dependencies/getFunctionExpression.js +3 -1
- package/lib/errors/BuildCycleError.js +4 -1
- package/lib/esm/ModuleChunkFormatPlugin.js +6 -4
- package/lib/esm/ModuleChunkLoadingPlugin.js +1 -0
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +1 -0
- package/lib/hmr/LazyCompilationPlugin.js +5 -0
- package/lib/hmr/lazyCompilationBackend.js +3 -2
- package/lib/ids/ChunkModuleIdRangePlugin.js +2 -0
- package/lib/ids/IdHelpers.js +10 -8
- package/lib/ids/OccurrenceModuleIdsPlugin.js +15 -7
- package/lib/ids/SyncModuleIdsPlugin.js +5 -1
- package/lib/javascript/BasicEvaluatedExpression.js +1 -0
- package/lib/javascript/EnableChunkLoadingPlugin.js +5 -2
- package/lib/javascript/JavascriptModulesPlugin.js +29 -8
- package/lib/javascript/JavascriptParser.js +47 -14
- package/lib/json/JsonParser.js +6 -0
- package/lib/library/AbstractLibraryPlugin.js +4 -1
- package/lib/library/AmdLibraryPlugin.js +2 -1
- package/lib/library/AssignLibraryPlugin.js +6 -2
- package/lib/library/EnableLibraryPlugin.js +1 -0
- package/lib/library/ExportPropertyLibraryPlugin.js +1 -1
- package/lib/library/JsonpLibraryPlugin.js +1 -1
- package/lib/library/ModuleLibraryPlugin.js +130 -13
- package/lib/library/SystemLibraryPlugin.js +4 -1
- package/lib/library/UmdLibraryPlugin.js +4 -3
- package/lib/logging/createConsoleLogger.js +3 -0
- package/lib/logging/truncateArgs.js +1 -1
- package/lib/node/CommonJsChunkLoadingPlugin.js +1 -0
- package/lib/node/NodeTargetPlugin.js +1 -0
- package/lib/node/NodeWatchFileSystem.js +3 -0
- package/lib/node/nodeConsole.js +18 -1
- package/lib/optimize/AggressiveMergingPlugin.js +2 -1
- package/lib/optimize/AggressiveSplittingPlugin.js +10 -6
- package/lib/optimize/ConcatenatedModule.js +33 -19
- package/lib/optimize/FlagIncludedChunksPlugin.js +11 -1
- package/lib/optimize/InnerGraph.js +5 -3
- package/lib/optimize/InnerGraphPlugin.js +25 -25
- package/lib/optimize/MangleExportsPlugin.js +14 -2
- package/lib/optimize/MergeDuplicateChunksPlugin.js +3 -0
- package/lib/optimize/MinChunkSizePlugin.js +5 -2
- package/lib/optimize/ModuleConcatenationPlugin.js +19 -4
- package/lib/optimize/RealContentHashPlugin.js +35 -27
- package/lib/optimize/RemoveParentModulesPlugin.js +12 -3
- package/lib/optimize/SideEffectsFlagPlugin.js +3 -0
- package/lib/optimize/SplitChunksPlugin.js +14 -3
- package/lib/performance/AssetsOverSizeLimitWarning.js +6 -2
- package/lib/performance/EntrypointsOverSizeLimitWarning.js +6 -2
- package/lib/performance/NoAsyncChunksWarning.js +1 -0
- package/lib/rules/BasicEffectRulePlugin.js +2 -0
- package/lib/rules/BasicMatcherRulePlugin.js +3 -0
- package/lib/rules/ObjectMatcherRulePlugin.js +5 -1
- package/lib/rules/RuleSetCompiler.js +2 -0
- package/lib/runtime/AsyncModuleRuntimeModule.js +1 -0
- package/lib/runtime/ChunkNameRuntimeModule.js +1 -0
- package/lib/runtime/CompatRuntimeModule.js +1 -0
- package/lib/runtime/EnsureChunkRuntimeModule.js +1 -0
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +4 -0
- package/lib/runtime/GetMainFilenameRuntimeModule.js +2 -0
- package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +1 -0
- package/lib/runtime/LoadScriptRuntimeModule.js +2 -0
- package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +15 -32
- package/lib/runtime/PublicPathRuntimeModule.js +1 -0
- package/lib/runtime/StartupChunkDependenciesPlugin.js +2 -0
- package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +1 -0
- package/lib/runtime/StartupEntrypointRuntimeModule.js +1 -0
- package/lib/schemes/HttpUriPlugin.js +27 -7
- package/lib/schemes/VirtualUrlPlugin.js +7 -2
- package/lib/serialization/BinaryMiddleware.js +4 -0
- package/lib/serialization/FileMiddleware.js +9 -4
- package/lib/serialization/ObjectMiddleware.js +34 -11
- package/lib/serialization/PlainObjectSerializer.js +2 -0
- package/lib/sharing/ConsumeSharedModule.js +60 -0
- package/lib/sharing/ConsumeSharedPlugin.js +5 -4
- package/lib/sharing/ProvideSharedModule.js +4 -0
- package/lib/sharing/ProvideSharedPlugin.js +24 -25
- package/lib/sharing/resolveMatchedConfigs.js +2 -2
- package/lib/sharing/utils.js +8 -6
- package/lib/stats/DefaultStatsFactoryPlugin.js +14 -12
- package/lib/stats/DefaultStatsPrinterPlugin.js +6 -5
- package/lib/stats/StatsFactory.js +2 -2
- package/lib/url/URLParserPlugin.js +4 -3
- package/lib/util/AppendOnlyStackedSet.js +57 -0
- package/lib/util/Hash.js +1 -0
- package/lib/util/IterableHelpers.js +1 -0
- package/lib/util/LazyBucketSortedSet.js +1 -0
- package/lib/util/LazySet.js +1 -0
- package/lib/util/ParallelismFactorCalculator.js +1 -0
- package/lib/util/SortableSet.js +1 -0
- package/lib/util/StringXor.js +1 -0
- package/lib/util/binarySearchBounds.js +15 -8
- package/lib/util/chainedImports.js +1 -1
- package/lib/util/cleverMerge.js +6 -1
- package/lib/util/comparators.js +21 -1
- package/lib/util/compileBooleanMatcher.js +3 -3
- package/lib/util/concatenate.js +3 -2
- package/lib/util/conventions.js +3 -2
- package/lib/util/deterministicGrouping.js +13 -1
- package/lib/util/extractSourceMap.js +12 -13
- package/lib/util/fs.js +15 -19
- package/lib/util/hash/BatchedHash.js +3 -0
- package/lib/util/hash/BulkUpdateHash.js +7 -1
- package/lib/util/hash/hash-digest.js +1 -0
- package/lib/util/hash/wasm-hash.js +16 -1
- package/lib/util/identifier.js +7 -2
- package/lib/util/magicComment.js +1 -1
- package/lib/util/propertyName.js +1 -1
- package/lib/util/registerExternalSerializer.js +1 -0
- package/lib/util/runtime.js +15 -1
- package/lib/util/semver.js +1 -0
- package/lib/util/serialization.js +2 -2
- package/lib/wasm/EnableWasmLoadingPlugin.js +1 -0
- package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +11 -3
- package/lib/wasm-async/AsyncWebAssemblyGenerator.js +1 -0
- package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +3 -2
- package/lib/wasm-sync/UnsupportedWebAssemblyFeatureError.js +5 -1
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +3 -0
- package/lib/wasm-sync/WebAssemblyInInitialChunkError.js +2 -0
- package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +7 -3
- package/lib/wasm-sync/WebAssemblyModulesPlugin.js +2 -2
- package/lib/wasm-sync/WebAssemblyParser.js +3 -1
- package/lib/web/FetchCompileWasmPlugin.js +1 -0
- package/lib/web/JsonpChunkLoadingPlugin.js +1 -0
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +1 -0
- package/lib/webpack.js +13 -3
- package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +1 -0
- package/package.json +20 -28
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +71 -5
- package/types.d.ts +339 -93
package/lib/ContextModule.js
CHANGED
|
@@ -17,6 +17,10 @@ const { JAVASCRIPT_MODULE_TYPE_DYNAMIC } = require("./ModuleTypeConstants");
|
|
|
17
17
|
const RuntimeGlobals = require("./RuntimeGlobals");
|
|
18
18
|
const Template = require("./Template");
|
|
19
19
|
const WebpackError = require("./WebpackError");
|
|
20
|
+
const {
|
|
21
|
+
getOutgoingAsyncModules
|
|
22
|
+
} = require("./async-modules/AsyncModuleHelpers");
|
|
23
|
+
const { ImportPhase, ImportPhaseUtils } = require("./dependencies/ImportPhase");
|
|
20
24
|
const {
|
|
21
25
|
compareLocations,
|
|
22
26
|
compareModulesById,
|
|
@@ -54,6 +58,8 @@ const makeSerializable = require("./util/makeSerializable");
|
|
|
54
58
|
/** @typedef {import("./Module").LibIdent} LibIdent */
|
|
55
59
|
/** @typedef {import("./Module").NeedBuildCallback} NeedBuildCallback */
|
|
56
60
|
/** @typedef {import("./Module").NeedBuildContext} NeedBuildContext */
|
|
61
|
+
/** @typedef {import("./Module").RuntimeRequirements} RuntimeRequirements */
|
|
62
|
+
/** @typedef {import("./Module").Sources} Sources */
|
|
57
63
|
/** @typedef {import("./RequestShortener")} RequestShortener */
|
|
58
64
|
/** @typedef {import("./ResolverFactory").ResolverWithOptions} ResolverWithOptions */
|
|
59
65
|
/** @typedef {import("./RuntimeTemplate")} RuntimeTemplate */
|
|
@@ -62,6 +68,7 @@ const makeSerializable = require("./util/makeSerializable");
|
|
|
62
68
|
/** @typedef {import("./serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
|
63
69
|
/** @typedef {import("./serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
|
64
70
|
/** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */
|
|
71
|
+
/** @typedef {import("./dependencies/ImportPhase").ImportPhaseType} ImportPhaseType */
|
|
65
72
|
|
|
66
73
|
/** @typedef {"sync" | "eager" | "weak" | "async-weak" | "lazy" | "lazy-once"} ContextMode Context mode */
|
|
67
74
|
|
|
@@ -81,6 +88,7 @@ const makeSerializable = require("./util/makeSerializable");
|
|
|
81
88
|
* @property {RawReferencedExports | null=} referencedExports exports referenced from modules (won't be mangled)
|
|
82
89
|
* @property {string | null=} layer
|
|
83
90
|
* @property {ImportAttributes=} attributes
|
|
91
|
+
* @property {ImportPhaseType=} phase
|
|
84
92
|
*/
|
|
85
93
|
|
|
86
94
|
/**
|
|
@@ -110,6 +118,7 @@ const makeSerializable = require("./util/makeSerializable");
|
|
|
110
118
|
/** @typedef {1 | 3 | 7 | 9} FakeMapType */
|
|
111
119
|
|
|
112
120
|
/** @typedef {Record<ModuleId, FakeMapType>} FakeMap */
|
|
121
|
+
/** @typedef {Record<string, ModuleId>} UserRequestMap */
|
|
113
122
|
|
|
114
123
|
class ContextModule extends Module {
|
|
115
124
|
/**
|
|
@@ -260,6 +269,9 @@ class ContextModule extends Module {
|
|
|
260
269
|
if (this.options.attributes) {
|
|
261
270
|
identifier += `|importAttributes: ${JSON.stringify(this.options.attributes)}`;
|
|
262
271
|
}
|
|
272
|
+
if (this.options.phase) {
|
|
273
|
+
identifier += `|importPhase: ${this.options.phase}`;
|
|
274
|
+
}
|
|
263
275
|
if (this.layer) {
|
|
264
276
|
identifier += `|layer: ${this.layer}`;
|
|
265
277
|
}
|
|
@@ -278,7 +290,9 @@ class ContextModule extends Module {
|
|
|
278
290
|
* @returns {string} a user readable identifier of the module
|
|
279
291
|
*/
|
|
280
292
|
readableIdentifier(requestShortener) {
|
|
293
|
+
/** @type {string} */
|
|
281
294
|
let identifier;
|
|
295
|
+
|
|
282
296
|
if (this.context) {
|
|
283
297
|
identifier = `${requestShortener.shorten(this.context)}/`;
|
|
284
298
|
} else if (
|
|
@@ -342,6 +356,7 @@ class ContextModule extends Module {
|
|
|
342
356
|
* @returns {LibIdent | null} an identifier for library inclusion
|
|
343
357
|
*/
|
|
344
358
|
libIdent(options) {
|
|
359
|
+
/** @type {string} */
|
|
345
360
|
let identifier;
|
|
346
361
|
|
|
347
362
|
if (this.context) {
|
|
@@ -509,7 +524,7 @@ class ContextModule extends Module {
|
|
|
509
524
|
for (const dep of dependencies) {
|
|
510
525
|
let chunkName = this.options.chunkName;
|
|
511
526
|
if (chunkName) {
|
|
512
|
-
if (!/\[(index|request)\]/.test(chunkName)) {
|
|
527
|
+
if (!/\[(?:index|request)\]/.test(chunkName)) {
|
|
513
528
|
chunkName += "[index]";
|
|
514
529
|
}
|
|
515
530
|
chunkName = chunkName.replace(/\[index\]/g, `${index++}`);
|
|
@@ -585,7 +600,7 @@ class ContextModule extends Module {
|
|
|
585
600
|
/**
|
|
586
601
|
* @param {Dependency[]} dependencies all dependencies
|
|
587
602
|
* @param {ChunkGraph} chunkGraph chunk graph
|
|
588
|
-
* @returns {
|
|
603
|
+
* @returns {UserRequestMap} map with user requests
|
|
589
604
|
*/
|
|
590
605
|
getUserRequestMap(dependencies, chunkGraph) {
|
|
591
606
|
const moduleGraph = chunkGraph.moduleGraph;
|
|
@@ -602,10 +617,13 @@ class ContextModule extends Module {
|
|
|
602
617
|
}
|
|
603
618
|
return a.userRequest < b.userRequest ? -1 : 1;
|
|
604
619
|
});
|
|
620
|
+
/** @type {UserRequestMap} */
|
|
605
621
|
const map = Object.create(null);
|
|
606
622
|
for (const dep of sortedDependencies) {
|
|
607
623
|
const module = /** @type {Module} */ (moduleGraph.getModule(dep));
|
|
608
|
-
map[dep.userRequest] =
|
|
624
|
+
map[dep.userRequest] =
|
|
625
|
+
/** @type {ModuleId} */
|
|
626
|
+
(chunkGraph.getModuleId(module));
|
|
609
627
|
}
|
|
610
628
|
return map;
|
|
611
629
|
}
|
|
@@ -690,6 +708,47 @@ class ContextModule extends Module {
|
|
|
690
708
|
: "";
|
|
691
709
|
}
|
|
692
710
|
|
|
711
|
+
/**
|
|
712
|
+
* @param {Dependency[]} dependencies all dependencies
|
|
713
|
+
* @param {ChunkGraph} chunkGraph chunk graph
|
|
714
|
+
* @returns {Map<string, ModuleId[] | undefined>} map with user requests
|
|
715
|
+
*/
|
|
716
|
+
getModuleDeferredAsyncDepsMap(dependencies, chunkGraph) {
|
|
717
|
+
const moduleGraph = chunkGraph.moduleGraph;
|
|
718
|
+
const comparator = compareModulesById(chunkGraph);
|
|
719
|
+
// if we filter first we get a new array
|
|
720
|
+
// therefore we don't need to create a clone of dependencies explicitly
|
|
721
|
+
// therefore the order of this is !important!
|
|
722
|
+
const sortedModules = dependencies
|
|
723
|
+
.map(
|
|
724
|
+
(dependency) =>
|
|
725
|
+
/** @type {Module} */ (moduleGraph.getModule(dependency))
|
|
726
|
+
)
|
|
727
|
+
.filter(Boolean)
|
|
728
|
+
.sort(comparator);
|
|
729
|
+
const map = Object.create(null);
|
|
730
|
+
for (const module of sortedModules) {
|
|
731
|
+
if (!(/** @type {BuildMeta} */ (module.buildMeta).async)) {
|
|
732
|
+
const id = /** @type {ModuleId} */ (chunkGraph.getModuleId(module));
|
|
733
|
+
map[id] = Array.from(
|
|
734
|
+
getOutgoingAsyncModules(chunkGraph.moduleGraph, module),
|
|
735
|
+
(m) => chunkGraph.getModuleId(m)
|
|
736
|
+
).filter((id) => id !== null);
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
return map;
|
|
740
|
+
}
|
|
741
|
+
|
|
742
|
+
/**
|
|
743
|
+
* @param {false | Map<string, ModuleId[] | undefined>} asyncDepsMap fake map
|
|
744
|
+
* @returns {string} async deps map init statement
|
|
745
|
+
*/
|
|
746
|
+
getModuleDeferredAsyncDepsMapInitStatement(asyncDepsMap) {
|
|
747
|
+
return typeof asyncDepsMap === "object"
|
|
748
|
+
? `var asyncDepsMap = ${JSON.stringify(asyncDepsMap, null, "\t")};`
|
|
749
|
+
: "";
|
|
750
|
+
}
|
|
751
|
+
|
|
693
752
|
/**
|
|
694
753
|
* @param {FakeMapType} type type
|
|
695
754
|
* @param {boolean=} asyncModule is async module
|
|
@@ -706,21 +765,30 @@ class ContextModule extends Module {
|
|
|
706
765
|
|
|
707
766
|
/**
|
|
708
767
|
* @param {FakeMap | FakeMapType} fakeMap fake map
|
|
709
|
-
* @param {boolean=} asyncModule
|
|
768
|
+
* @param {boolean=} asyncModule is async module
|
|
769
|
+
* @param {string=} asyncDeps async deps for deferred module
|
|
710
770
|
* @param {string=} fakeMapDataExpression fake map data expression
|
|
711
771
|
* @returns {string} module object source
|
|
712
772
|
*/
|
|
713
773
|
getReturnModuleObjectSource(
|
|
714
774
|
fakeMap,
|
|
715
775
|
asyncModule,
|
|
776
|
+
asyncDeps,
|
|
716
777
|
fakeMapDataExpression = "fakeMap[id]"
|
|
717
778
|
) {
|
|
718
|
-
|
|
719
|
-
|
|
779
|
+
const source =
|
|
780
|
+
typeof fakeMap === "number"
|
|
781
|
+
? this.getReturn(fakeMap, asyncModule)
|
|
782
|
+
: `${RuntimeGlobals.createFakeNamespaceObject}(id, ${fakeMapDataExpression}${asyncModule ? " | 16" : ""})`;
|
|
783
|
+
if (asyncDeps) {
|
|
784
|
+
if (!asyncModule) {
|
|
785
|
+
throw new Error("Must be async when module is deferred");
|
|
786
|
+
}
|
|
787
|
+
const type =
|
|
788
|
+
typeof fakeMap === "number" ? fakeMap : fakeMapDataExpression;
|
|
789
|
+
return `${asyncDeps} ? ${asyncDeps}.length ? ${RuntimeGlobals.deferredModuleAsyncTransitiveDependencies}(${asyncDeps}).then(${RuntimeGlobals.makeDeferredNamespaceObject}.bind(${RuntimeGlobals.require}, id, ${type} ^ 1, true)) : ${RuntimeGlobals.makeDeferredNamespaceObject}(id, ${type} ^ 1 | 16) : ${source}`;
|
|
720
790
|
}
|
|
721
|
-
return
|
|
722
|
-
RuntimeGlobals.createFakeNamespaceObject
|
|
723
|
-
}(id, ${fakeMapDataExpression}${asyncModule ? " | 16" : ""})`;
|
|
791
|
+
return source;
|
|
724
792
|
}
|
|
725
793
|
|
|
726
794
|
/**
|
|
@@ -739,7 +807,7 @@ ${this.getFakeMapInitStatement(fakeMap)}
|
|
|
739
807
|
|
|
740
808
|
function webpackContext(req) {
|
|
741
809
|
var id = webpackContextResolve(req);
|
|
742
|
-
${returnModuleObject}
|
|
810
|
+
return ${returnModuleObject};
|
|
743
811
|
}
|
|
744
812
|
function webpackContextResolve(req) {
|
|
745
813
|
if(!${RuntimeGlobals.hasOwnProperty}(map, req)) {
|
|
@@ -778,7 +846,7 @@ function webpackContext(req) {
|
|
|
778
846
|
e.code = 'MODULE_NOT_FOUND';
|
|
779
847
|
throw e;
|
|
780
848
|
}
|
|
781
|
-
${returnModuleObject}
|
|
849
|
+
return ${returnModuleObject};
|
|
782
850
|
}
|
|
783
851
|
function webpackContextResolve(req) {
|
|
784
852
|
if(!${RuntimeGlobals.hasOwnProperty}(map, req)) {
|
|
@@ -799,43 +867,56 @@ module.exports = webpackContext;`;
|
|
|
799
867
|
/**
|
|
800
868
|
* @param {Dependency[]} dependencies dependencies
|
|
801
869
|
* @param {ModuleId} id module id
|
|
870
|
+
* @param {ImportPhaseType} phase import phase
|
|
802
871
|
* @param {object} context context
|
|
803
872
|
* @param {ChunkGraph} context.chunkGraph the chunk graph
|
|
804
873
|
* @param {RuntimeTemplate} context.runtimeTemplate the chunk graph
|
|
805
874
|
* @returns {string} source code
|
|
806
875
|
*/
|
|
807
|
-
getAsyncWeakSource(dependencies, id, { chunkGraph, runtimeTemplate }) {
|
|
808
|
-
const arrow = runtimeTemplate.supportsArrowFunction();
|
|
876
|
+
getAsyncWeakSource(dependencies, id, phase, { chunkGraph, runtimeTemplate }) {
|
|
809
877
|
const map = this.getUserRequestMap(dependencies, chunkGraph);
|
|
810
878
|
const fakeMap = this.getFakeMap(dependencies, chunkGraph);
|
|
811
|
-
const
|
|
879
|
+
const asyncDepsMap =
|
|
880
|
+
ImportPhaseUtils.isDefer(phase) &&
|
|
881
|
+
this.getModuleDeferredAsyncDepsMap(dependencies, chunkGraph);
|
|
882
|
+
const returnModuleObject = this.getReturnModuleObjectSource(
|
|
883
|
+
fakeMap,
|
|
884
|
+
true,
|
|
885
|
+
asyncDepsMap ? "asyncDepsMap[id]" : undefined
|
|
886
|
+
);
|
|
812
887
|
|
|
813
888
|
return `var map = ${JSON.stringify(map, null, "\t")};
|
|
814
889
|
${this.getFakeMapInitStatement(fakeMap)}
|
|
890
|
+
${this.getModuleDeferredAsyncDepsMapInitStatement(asyncDepsMap)}
|
|
815
891
|
|
|
816
892
|
function webpackAsyncContext(req) {
|
|
817
|
-
return webpackAsyncContextResolve(req).then(${
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
893
|
+
return webpackAsyncContextResolve(req).then(${runtimeTemplate.basicFunction(
|
|
894
|
+
"id",
|
|
895
|
+
[
|
|
896
|
+
`if(!${RuntimeGlobals.moduleFactories}[id]) {`,
|
|
897
|
+
Template.indent([
|
|
898
|
+
'var e = new Error("Module \'" + req + "\' (\'" + id + "\') is not available (weak dependency)");',
|
|
899
|
+
"e.code = 'MODULE_NOT_FOUND';",
|
|
900
|
+
"throw e;"
|
|
901
|
+
]),
|
|
902
|
+
"}",
|
|
903
|
+
`return ${returnModuleObject};`
|
|
904
|
+
]
|
|
905
|
+
)});
|
|
827
906
|
}
|
|
828
907
|
function webpackAsyncContextResolve(req) {
|
|
829
908
|
// Here Promise.resolve().then() is used instead of new Promise() to prevent
|
|
830
909
|
// uncaught exception popping up in devtools
|
|
831
|
-
return Promise.resolve().then(${
|
|
832
|
-
if(!${RuntimeGlobals.hasOwnProperty}(map, req)) {
|
|
833
|
-
|
|
834
|
-
e
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
910
|
+
return Promise.resolve().then(${runtimeTemplate.basicFunction("", [
|
|
911
|
+
`if(!${RuntimeGlobals.hasOwnProperty}(map, req)) {`,
|
|
912
|
+
Template.indent([
|
|
913
|
+
'var e = new Error("Cannot find module \'" + req + "\'");',
|
|
914
|
+
"e.code = 'MODULE_NOT_FOUND';",
|
|
915
|
+
"throw e;"
|
|
916
|
+
]),
|
|
917
|
+
"}",
|
|
918
|
+
"return map[req];"
|
|
919
|
+
])});
|
|
839
920
|
}
|
|
840
921
|
webpackAsyncContext.keys = ${runtimeTemplate.returningFunction(
|
|
841
922
|
"Object.keys(map)"
|
|
@@ -848,23 +929,30 @@ module.exports = webpackAsyncContext;`;
|
|
|
848
929
|
/**
|
|
849
930
|
* @param {Dependency[]} dependencies dependencies
|
|
850
931
|
* @param {ModuleId} id module id
|
|
932
|
+
* @param {ImportPhaseType} phase import phase
|
|
851
933
|
* @param {object} context context
|
|
852
934
|
* @param {ChunkGraph} context.chunkGraph the chunk graph
|
|
853
935
|
* @param {RuntimeTemplate} context.runtimeTemplate the chunk graph
|
|
854
936
|
* @returns {string} source code
|
|
855
937
|
*/
|
|
856
|
-
getEagerSource(dependencies, id, { chunkGraph, runtimeTemplate }) {
|
|
857
|
-
const arrow = runtimeTemplate.supportsArrowFunction();
|
|
938
|
+
getEagerSource(dependencies, id, phase, { chunkGraph, runtimeTemplate }) {
|
|
858
939
|
const map = this.getUserRequestMap(dependencies, chunkGraph);
|
|
859
940
|
const fakeMap = this.getFakeMap(dependencies, chunkGraph);
|
|
860
|
-
const
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
941
|
+
const asyncDepsMap =
|
|
942
|
+
ImportPhaseUtils.isDefer(phase) &&
|
|
943
|
+
this.getModuleDeferredAsyncDepsMap(dependencies, chunkGraph);
|
|
944
|
+
const thenFunction = runtimeTemplate.returningFunction(
|
|
945
|
+
this.getReturnModuleObjectSource(
|
|
946
|
+
fakeMap,
|
|
947
|
+
true,
|
|
948
|
+
asyncDepsMap ? "asyncDepsMap[id]" : undefined
|
|
949
|
+
),
|
|
950
|
+
"id"
|
|
951
|
+
);
|
|
952
|
+
|
|
866
953
|
return `var map = ${JSON.stringify(map, null, "\t")};
|
|
867
954
|
${this.getFakeMapInitStatement(fakeMap)}
|
|
955
|
+
${this.getModuleDeferredAsyncDepsMapInitStatement(asyncDepsMap)}
|
|
868
956
|
|
|
869
957
|
function webpackAsyncContext(req) {
|
|
870
958
|
return webpackAsyncContextResolve(req).then(${thenFunction});
|
|
@@ -872,14 +960,16 @@ function webpackAsyncContext(req) {
|
|
|
872
960
|
function webpackAsyncContextResolve(req) {
|
|
873
961
|
// Here Promise.resolve().then() is used instead of new Promise() to prevent
|
|
874
962
|
// uncaught exception popping up in devtools
|
|
875
|
-
return Promise.resolve().then(${
|
|
876
|
-
if(!${RuntimeGlobals.hasOwnProperty}(map, req)) {
|
|
877
|
-
|
|
878
|
-
e
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
963
|
+
return Promise.resolve().then(${runtimeTemplate.basicFunction("", [
|
|
964
|
+
`if(!${RuntimeGlobals.hasOwnProperty}(map, req)) {`,
|
|
965
|
+
Template.indent([
|
|
966
|
+
'var e = new Error("Cannot find module \'" + req + "\'");',
|
|
967
|
+
"e.code = 'MODULE_NOT_FOUND';",
|
|
968
|
+
"throw e;"
|
|
969
|
+
]),
|
|
970
|
+
"}",
|
|
971
|
+
"return map[req];"
|
|
972
|
+
])});
|
|
883
973
|
}
|
|
884
974
|
webpackAsyncContext.keys = ${runtimeTemplate.returningFunction(
|
|
885
975
|
"Object.keys(map)"
|
|
@@ -893,43 +983,58 @@ module.exports = webpackAsyncContext;`;
|
|
|
893
983
|
* @param {AsyncDependenciesBlock} block block
|
|
894
984
|
* @param {Dependency[]} dependencies dependencies
|
|
895
985
|
* @param {ModuleId} id module id
|
|
986
|
+
* @param {ImportPhaseType} phase import phase
|
|
896
987
|
* @param {object} options options object
|
|
897
988
|
* @param {RuntimeTemplate} options.runtimeTemplate the runtime template
|
|
898
989
|
* @param {ChunkGraph} options.chunkGraph the chunk graph
|
|
899
990
|
* @returns {string} source code
|
|
900
991
|
*/
|
|
901
|
-
getLazyOnceSource(
|
|
992
|
+
getLazyOnceSource(
|
|
993
|
+
block,
|
|
994
|
+
dependencies,
|
|
995
|
+
id,
|
|
996
|
+
phase,
|
|
997
|
+
{ runtimeTemplate, chunkGraph }
|
|
998
|
+
) {
|
|
902
999
|
const promise = runtimeTemplate.blockPromise({
|
|
903
1000
|
chunkGraph,
|
|
904
1001
|
block,
|
|
905
1002
|
message: "lazy-once context",
|
|
1003
|
+
/** @type {RuntimeRequirements} */
|
|
906
1004
|
runtimeRequirements: new Set()
|
|
907
1005
|
});
|
|
908
|
-
const arrow = runtimeTemplate.supportsArrowFunction();
|
|
909
1006
|
const map = this.getUserRequestMap(dependencies, chunkGraph);
|
|
910
1007
|
const fakeMap = this.getFakeMap(dependencies, chunkGraph);
|
|
911
|
-
const
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
1008
|
+
const asyncDepsMap =
|
|
1009
|
+
ImportPhaseUtils.isDefer(phase) &&
|
|
1010
|
+
this.getModuleDeferredAsyncDepsMap(dependencies, chunkGraph);
|
|
1011
|
+
const thenFunction = runtimeTemplate.returningFunction(
|
|
1012
|
+
this.getReturnModuleObjectSource(
|
|
1013
|
+
fakeMap,
|
|
1014
|
+
true,
|
|
1015
|
+
asyncDepsMap ? "asyncDepsMap[id]" : undefined
|
|
1016
|
+
),
|
|
1017
|
+
"id"
|
|
1018
|
+
);
|
|
917
1019
|
|
|
918
1020
|
return `var map = ${JSON.stringify(map, null, "\t")};
|
|
919
1021
|
${this.getFakeMapInitStatement(fakeMap)}
|
|
1022
|
+
${this.getModuleDeferredAsyncDepsMapInitStatement(asyncDepsMap)}
|
|
920
1023
|
|
|
921
1024
|
function webpackAsyncContext(req) {
|
|
922
1025
|
return webpackAsyncContextResolve(req).then(${thenFunction});
|
|
923
1026
|
}
|
|
924
1027
|
function webpackAsyncContextResolve(req) {
|
|
925
|
-
return ${promise}.then(${
|
|
926
|
-
if(!${RuntimeGlobals.hasOwnProperty}(map, req)) {
|
|
927
|
-
|
|
928
|
-
e
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
1028
|
+
return ${promise}.then(${runtimeTemplate.basicFunction("", [
|
|
1029
|
+
`if(!${RuntimeGlobals.hasOwnProperty}(map, req)) {`,
|
|
1030
|
+
Template.indent([
|
|
1031
|
+
'var e = new Error("Cannot find module \'" + req + "\'");',
|
|
1032
|
+
"e.code = 'MODULE_NOT_FOUND';",
|
|
1033
|
+
"throw e;"
|
|
1034
|
+
]),
|
|
1035
|
+
"}",
|
|
1036
|
+
"return map[req];"
|
|
1037
|
+
])});
|
|
933
1038
|
}
|
|
934
1039
|
webpackAsyncContext.keys = ${runtimeTemplate.returningFunction(
|
|
935
1040
|
"Object.keys(map)"
|
|
@@ -942,22 +1047,23 @@ module.exports = webpackAsyncContext;`;
|
|
|
942
1047
|
/**
|
|
943
1048
|
* @param {AsyncDependenciesBlock[]} blocks blocks
|
|
944
1049
|
* @param {ModuleId} id module id
|
|
1050
|
+
* @param {ImportPhaseType} phase import phase
|
|
945
1051
|
* @param {object} context context
|
|
946
1052
|
* @param {ChunkGraph} context.chunkGraph the chunk graph
|
|
947
1053
|
* @param {RuntimeTemplate} context.runtimeTemplate the chunk graph
|
|
948
1054
|
* @returns {string} source code
|
|
949
1055
|
*/
|
|
950
|
-
getLazySource(blocks, id, { chunkGraph, runtimeTemplate }) {
|
|
1056
|
+
getLazySource(blocks, id, phase, { chunkGraph, runtimeTemplate }) {
|
|
951
1057
|
const moduleGraph = chunkGraph.moduleGraph;
|
|
952
|
-
const arrow = runtimeTemplate.supportsArrowFunction();
|
|
953
1058
|
let hasMultipleOrNoChunks = false;
|
|
954
1059
|
let hasNoChunk = true;
|
|
1060
|
+
let hasNoModuleDeferred = true;
|
|
955
1061
|
const fakeMap = this.getFakeMap(
|
|
956
1062
|
blocks.map((b) => b.dependencies[0]),
|
|
957
1063
|
chunkGraph
|
|
958
1064
|
);
|
|
959
1065
|
const hasFakeMap = typeof fakeMap === "object";
|
|
960
|
-
/** @typedef {{userRequest: string, dependency: ContextElementDependency, chunks: undefined | Chunk[], module: Module, block: AsyncDependenciesBlock}} Item */
|
|
1066
|
+
/** @typedef {{ userRequest: string, dependency: ContextElementDependency, chunks: undefined | Chunk[], module: Module, block: AsyncDependenciesBlock, asyncDeps: undefined | ModuleId[] }} Item */
|
|
961
1067
|
/**
|
|
962
1068
|
* @type {Item[]}
|
|
963
1069
|
*/
|
|
@@ -971,7 +1077,8 @@ module.exports = webpackAsyncContext;`;
|
|
|
971
1077
|
module: /** @type {Module} */ (moduleGraph.getModule(dependency)),
|
|
972
1078
|
block,
|
|
973
1079
|
userRequest: dependency.userRequest,
|
|
974
|
-
chunks: undefined
|
|
1080
|
+
chunks: undefined,
|
|
1081
|
+
asyncDeps: undefined
|
|
975
1082
|
};
|
|
976
1083
|
})
|
|
977
1084
|
.filter((item) => item.module);
|
|
@@ -985,13 +1092,24 @@ module.exports = webpackAsyncContext;`;
|
|
|
985
1092
|
if (chunks.length !== 1) {
|
|
986
1093
|
hasMultipleOrNoChunks = true;
|
|
987
1094
|
}
|
|
1095
|
+
const isModuleDeferred =
|
|
1096
|
+
ImportPhaseUtils.isDefer(phase) &&
|
|
1097
|
+
!(/** @type {BuildMeta} */ (item.module.buildMeta).async);
|
|
1098
|
+
if (isModuleDeferred) {
|
|
1099
|
+
const asyncDeps = Array.from(
|
|
1100
|
+
getOutgoingAsyncModules(chunkGraph.moduleGraph, item.module),
|
|
1101
|
+
(m) => chunkGraph.getModuleId(m)
|
|
1102
|
+
).filter((id) => id !== null);
|
|
1103
|
+
item.asyncDeps = asyncDeps;
|
|
1104
|
+
hasNoModuleDeferred = false;
|
|
1105
|
+
}
|
|
988
1106
|
}
|
|
989
|
-
const shortMode = hasNoChunk && !hasFakeMap;
|
|
1107
|
+
const shortMode = hasNoChunk && hasNoModuleDeferred && !hasFakeMap;
|
|
990
1108
|
const sortedItems = items.sort((a, b) => {
|
|
991
1109
|
if (a.userRequest === b.userRequest) return 0;
|
|
992
1110
|
return a.userRequest < b.userRequest ? -1 : 1;
|
|
993
1111
|
});
|
|
994
|
-
/** @type {Record<string, ModuleId | (ModuleId[] |
|
|
1112
|
+
/** @type {Record<string, ModuleId | (ModuleId | FakeMapType | ChunkId[] | (ModuleId[] | undefined))[]>} */
|
|
995
1113
|
const map = Object.create(null);
|
|
996
1114
|
for (const item of sortedItems) {
|
|
997
1115
|
const moduleId =
|
|
@@ -1000,28 +1118,36 @@ module.exports = webpackAsyncContext;`;
|
|
|
1000
1118
|
if (shortMode) {
|
|
1001
1119
|
map[item.userRequest] = moduleId;
|
|
1002
1120
|
} else {
|
|
1003
|
-
/** @type {(ModuleId | ChunkId)[]} */
|
|
1004
|
-
const
|
|
1121
|
+
/** @type {(ModuleId | FakeMapType | ChunkId[] | (ModuleId[] | undefined))[]} */
|
|
1122
|
+
const array = [moduleId];
|
|
1005
1123
|
if (hasFakeMap) {
|
|
1006
|
-
|
|
1124
|
+
array.push(fakeMap[moduleId]);
|
|
1125
|
+
}
|
|
1126
|
+
if (!hasNoChunk) {
|
|
1127
|
+
array.push(
|
|
1128
|
+
/** @type {Chunk[]} */ (item.chunks).map(
|
|
1129
|
+
(chunk) => /** @type {ChunkId} */ (chunk.id)
|
|
1130
|
+
)
|
|
1131
|
+
);
|
|
1007
1132
|
}
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
];
|
|
1133
|
+
if (!hasNoModuleDeferred) {
|
|
1134
|
+
array.push(item.asyncDeps);
|
|
1135
|
+
}
|
|
1136
|
+
map[item.userRequest] = array;
|
|
1013
1137
|
}
|
|
1014
1138
|
}
|
|
1015
1139
|
|
|
1016
|
-
const
|
|
1140
|
+
const chunksPosition = hasFakeMap ? 2 : 1;
|
|
1141
|
+
const asyncDepsPosition = chunksPosition + 1;
|
|
1017
1142
|
const requestPrefix = hasNoChunk
|
|
1018
1143
|
? "Promise.resolve()"
|
|
1019
1144
|
: hasMultipleOrNoChunks
|
|
1020
|
-
? `Promise.all(ids
|
|
1021
|
-
: `${RuntimeGlobals.ensureChunk}(ids[${
|
|
1145
|
+
? `Promise.all(ids[${chunksPosition}].map(${RuntimeGlobals.ensureChunk}))`
|
|
1146
|
+
: `${RuntimeGlobals.ensureChunk}(ids[${chunksPosition}][0])`;
|
|
1022
1147
|
const returnModuleObject = this.getReturnModuleObjectSource(
|
|
1023
1148
|
fakeMap,
|
|
1024
1149
|
true,
|
|
1150
|
+
hasNoModuleDeferred ? undefined : `ids[${asyncDepsPosition}]`,
|
|
1025
1151
|
shortMode ? "invalid" : "ids[1]"
|
|
1026
1152
|
);
|
|
1027
1153
|
|
|
@@ -1029,30 +1155,29 @@ module.exports = webpackAsyncContext;`;
|
|
|
1029
1155
|
requestPrefix === "Promise.resolve()"
|
|
1030
1156
|
? `
|
|
1031
1157
|
function webpackAsyncContext(req) {
|
|
1032
|
-
return Promise.resolve().then(${
|
|
1033
|
-
if(!${RuntimeGlobals.hasOwnProperty}(map, req)) {
|
|
1034
|
-
|
|
1035
|
-
e
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1158
|
+
return Promise.resolve().then(${runtimeTemplate.basicFunction("", [
|
|
1159
|
+
`if(!${RuntimeGlobals.hasOwnProperty}(map, req)) {`,
|
|
1160
|
+
Template.indent([
|
|
1161
|
+
'var e = new Error("Cannot find module \'" + req + "\'");',
|
|
1162
|
+
"e.code = 'MODULE_NOT_FOUND';",
|
|
1163
|
+
"throw e;"
|
|
1164
|
+
]),
|
|
1165
|
+
"}",
|
|
1166
|
+
shortMode ? "var id = map[req];" : "var ids = map[req], id = ids[0];",
|
|
1167
|
+
`return ${returnModuleObject};`
|
|
1168
|
+
])});
|
|
1042
1169
|
}`
|
|
1043
1170
|
: `function webpackAsyncContext(req) {
|
|
1044
1171
|
if(!${RuntimeGlobals.hasOwnProperty}(map, req)) {
|
|
1045
|
-
return Promise.resolve().then(${
|
|
1046
|
-
var e = new Error("Cannot find module '" + req + "'");
|
|
1047
|
-
e.code = 'MODULE_NOT_FOUND';
|
|
1048
|
-
throw e;
|
|
1049
|
-
});
|
|
1172
|
+
return Promise.resolve().then(${runtimeTemplate.basicFunction("", [
|
|
1173
|
+
'var e = new Error("Cannot find module \'" + req + "\'");',
|
|
1174
|
+
"e.code = 'MODULE_NOT_FOUND';",
|
|
1175
|
+
"throw e;"
|
|
1176
|
+
])});
|
|
1050
1177
|
}
|
|
1051
1178
|
|
|
1052
1179
|
var ids = map[req], id = ids[0];
|
|
1053
|
-
return ${requestPrefix}.then(${
|
|
1054
|
-
${returnModuleObject}
|
|
1055
|
-
});
|
|
1180
|
+
return ${requestPrefix}.then(${runtimeTemplate.returningFunction(returnModuleObject)});
|
|
1056
1181
|
}`;
|
|
1057
1182
|
|
|
1058
1183
|
return `var map = ${JSON.stringify(map, null, "\t")};
|
|
@@ -1087,15 +1212,14 @@ module.exports = webpackEmptyContext;`;
|
|
|
1087
1212
|
* @returns {string} source for empty async context
|
|
1088
1213
|
*/
|
|
1089
1214
|
getSourceForEmptyAsyncContext(id, runtimeTemplate) {
|
|
1090
|
-
const arrow = runtimeTemplate.supportsArrowFunction();
|
|
1091
1215
|
return `function webpackEmptyAsyncContext(req) {
|
|
1092
1216
|
// Here Promise.resolve().then() is used instead of new Promise() to prevent
|
|
1093
1217
|
// uncaught exception popping up in devtools
|
|
1094
|
-
return Promise.resolve().then(${
|
|
1095
|
-
var e = new Error("Cannot find module '" + req + "'");
|
|
1096
|
-
e.code = 'MODULE_NOT_FOUND';
|
|
1097
|
-
throw e;
|
|
1098
|
-
});
|
|
1218
|
+
return Promise.resolve().then(${runtimeTemplate.basicFunction("", [
|
|
1219
|
+
'var e = new Error("Cannot find module \'" + req + "\'");',
|
|
1220
|
+
"e.code = 'MODULE_NOT_FOUND';",
|
|
1221
|
+
"throw e;"
|
|
1222
|
+
])});
|
|
1099
1223
|
}
|
|
1100
1224
|
webpackEmptyAsyncContext.keys = ${runtimeTemplate.returningFunction("[]")};
|
|
1101
1225
|
webpackEmptyAsyncContext.resolve = webpackEmptyAsyncContext;
|
|
@@ -1105,14 +1229,15 @@ module.exports = webpackEmptyAsyncContext;`;
|
|
|
1105
1229
|
|
|
1106
1230
|
/**
|
|
1107
1231
|
* @param {string} asyncMode module mode
|
|
1232
|
+
* @param {ImportPhaseType} phase import phase
|
|
1108
1233
|
* @param {CodeGenerationContext} context context info
|
|
1109
1234
|
* @returns {string} the source code
|
|
1110
1235
|
*/
|
|
1111
|
-
getSourceString(asyncMode, { runtimeTemplate, chunkGraph }) {
|
|
1236
|
+
getSourceString(asyncMode, phase, { runtimeTemplate, chunkGraph }) {
|
|
1112
1237
|
const id = /** @type {ModuleId} */ (chunkGraph.getModuleId(this));
|
|
1113
1238
|
if (asyncMode === "lazy") {
|
|
1114
1239
|
if (this.blocks && this.blocks.length > 0) {
|
|
1115
|
-
return this.getLazySource(this.blocks, id, {
|
|
1240
|
+
return this.getLazySource(this.blocks, id, phase, {
|
|
1116
1241
|
runtimeTemplate,
|
|
1117
1242
|
chunkGraph
|
|
1118
1243
|
});
|
|
@@ -1121,7 +1246,7 @@ module.exports = webpackEmptyAsyncContext;`;
|
|
|
1121
1246
|
}
|
|
1122
1247
|
if (asyncMode === "eager") {
|
|
1123
1248
|
if (this.dependencies && this.dependencies.length > 0) {
|
|
1124
|
-
return this.getEagerSource(this.dependencies, id, {
|
|
1249
|
+
return this.getEagerSource(this.dependencies, id, phase, {
|
|
1125
1250
|
chunkGraph,
|
|
1126
1251
|
runtimeTemplate
|
|
1127
1252
|
});
|
|
@@ -1131,7 +1256,7 @@ module.exports = webpackEmptyAsyncContext;`;
|
|
|
1131
1256
|
if (asyncMode === "lazy-once") {
|
|
1132
1257
|
const block = this.blocks[0];
|
|
1133
1258
|
if (block) {
|
|
1134
|
-
return this.getLazyOnceSource(block, block.dependencies, id, {
|
|
1259
|
+
return this.getLazyOnceSource(block, block.dependencies, id, phase, {
|
|
1135
1260
|
runtimeTemplate,
|
|
1136
1261
|
chunkGraph
|
|
1137
1262
|
});
|
|
@@ -1140,7 +1265,7 @@ module.exports = webpackEmptyAsyncContext;`;
|
|
|
1140
1265
|
}
|
|
1141
1266
|
if (asyncMode === "async-weak") {
|
|
1142
1267
|
if (this.dependencies && this.dependencies.length > 0) {
|
|
1143
|
-
return this.getAsyncWeakSource(this.dependencies, id, {
|
|
1268
|
+
return this.getAsyncWeakSource(this.dependencies, id, phase, {
|
|
1144
1269
|
chunkGraph,
|
|
1145
1270
|
runtimeTemplate
|
|
1146
1271
|
});
|
|
@@ -1185,14 +1310,21 @@ module.exports = webpackEmptyAsyncContext;`;
|
|
|
1185
1310
|
*/
|
|
1186
1311
|
codeGeneration(context) {
|
|
1187
1312
|
const { chunkGraph, compilation } = context;
|
|
1313
|
+
|
|
1314
|
+
/** @type {Sources} */
|
|
1188
1315
|
const sources = new Map();
|
|
1189
1316
|
sources.set(
|
|
1190
1317
|
JAVASCRIPT_TYPE,
|
|
1191
1318
|
this.getSource(
|
|
1192
|
-
this.getSourceString(
|
|
1319
|
+
this.getSourceString(
|
|
1320
|
+
this.options.mode,
|
|
1321
|
+
this.options.phase || ImportPhase.Evaluation,
|
|
1322
|
+
context
|
|
1323
|
+
),
|
|
1193
1324
|
compilation
|
|
1194
1325
|
)
|
|
1195
1326
|
);
|
|
1327
|
+
/** @type {RuntimeRequirements} */
|
|
1196
1328
|
const set = new Set();
|
|
1197
1329
|
const allDeps =
|
|
1198
1330
|
this.dependencies.length > 0
|
|
@@ -1219,6 +1351,11 @@ module.exports = webpackEmptyAsyncContext;`;
|
|
|
1219
1351
|
if (this.getFakeMap(allDeps, chunkGraph) !== 9) {
|
|
1220
1352
|
set.add(RuntimeGlobals.createFakeNamespaceObject);
|
|
1221
1353
|
}
|
|
1354
|
+
if (
|
|
1355
|
+
ImportPhaseUtils.isDefer(this.options.phase || ImportPhase.Evaluation)
|
|
1356
|
+
) {
|
|
1357
|
+
set.add(RuntimeGlobals.makeDeferredNamespaceObject);
|
|
1358
|
+
}
|
|
1222
1359
|
}
|
|
1223
1360
|
return {
|
|
1224
1361
|
sources,
|