webpack 5.99.9 → 5.100.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 +8 -2
- package/hot/log.js +15 -15
- package/hot/poll.js +1 -0
- package/lib/APIPlugin.js +3 -3
- package/lib/AbstractMethodError.js +1 -0
- package/lib/AutomaticPrefetchPlugin.js +1 -0
- package/lib/BannerPlugin.js +1 -1
- package/lib/CaseSensitiveModulesWarning.js +4 -4
- package/lib/Chunk.js +6 -6
- package/lib/ChunkGraph.js +37 -31
- package/lib/ChunkGroup.js +4 -4
- package/lib/ChunkTemplate.js +1 -1
- package/lib/CleanPlugin.js +94 -17
- package/lib/CodeGenerationResults.js +1 -1
- package/lib/CompatibilityPlugin.js +5 -2
- package/lib/Compilation.js +67 -45
- package/lib/Compiler.js +46 -16
- package/lib/ConcatenationScope.js +15 -6
- package/lib/ConstPlugin.js +5 -3
- package/lib/ContextModule.js +16 -12
- package/lib/ContextModuleFactory.js +4 -3
- package/lib/ContextReplacementPlugin.js +4 -2
- package/lib/CssModule.js +2 -2
- package/lib/DefinePlugin.js +111 -3
- package/lib/DelegatedModuleFactoryPlugin.js +18 -18
- package/lib/Dependency.js +11 -4
- package/lib/DependencyTemplate.js +1 -0
- package/lib/DllEntryPlugin.js +3 -1
- package/lib/DllPlugin.js +4 -3
- package/lib/DllReferencePlugin.js +2 -2
- package/lib/DynamicEntryPlugin.js +1 -1
- package/lib/EntryOptionPlugin.js +5 -0
- package/lib/ErrorHelpers.js +4 -4
- package/lib/EvalDevToolModulePlugin.js +3 -3
- package/lib/EvalSourceMapDevToolPlugin.js +7 -7
- package/lib/ExportsInfo.js +48 -39
- package/lib/ExternalModule.js +15 -11
- package/lib/ExternalModuleFactoryPlugin.js +5 -2
- package/lib/FileSystemInfo.js +51 -36
- package/lib/FlagDependencyExportsPlugin.js +14 -7
- package/lib/FlagDependencyUsagePlugin.js +1 -1
- package/lib/Generator.js +14 -1
- package/lib/HookWebpackError.js +1 -0
- package/lib/HotModuleReplacementPlugin.js +77 -50
- package/lib/IgnorePlugin.js +5 -2
- package/lib/InvalidDependenciesModuleWarning.js +1 -1
- package/lib/JavascriptMetaInfoPlugin.js +0 -1
- package/lib/LibManifestPlugin.js +4 -2
- package/lib/LoaderOptionsPlugin.js +6 -4
- package/lib/MainTemplate.js +2 -2
- package/lib/Module.js +21 -6
- package/lib/ModuleFactory.js +1 -0
- package/lib/ModuleGraph.js +24 -2
- package/lib/ModuleGraphConnection.js +5 -5
- package/lib/ModuleInfoHeaderPlugin.js +2 -1
- package/lib/ModuleParseError.js +1 -0
- package/lib/ModuleSourceTypesConstants.js +12 -12
- package/lib/ModuleTemplate.js +1 -1
- package/lib/ModuleTypeConstants.js +21 -21
- package/lib/MultiCompiler.js +6 -6
- package/lib/NormalModule.js +31 -44
- package/lib/NormalModuleFactory.js +34 -20
- package/lib/NormalModuleReplacementPlugin.js +1 -1
- package/lib/NullFactory.js +1 -0
- package/lib/OptimizationStages.js +1 -1
- package/lib/Parser.js +1 -0
- package/lib/ProgressPlugin.js +12 -5
- package/lib/ProvidePlugin.js +5 -1
- package/lib/RawModule.js +14 -0
- package/lib/RecordIdsPlugin.js +3 -3
- package/lib/RuntimeGlobals.js +175 -155
- package/lib/RuntimeModule.js +1 -0
- package/lib/RuntimePlugin.js +33 -7
- package/lib/RuntimeTemplate.js +111 -11
- package/lib/SourceMapDevToolModuleOptionsPlugin.js +15 -25
- package/lib/SourceMapDevToolPlugin.js +19 -17
- package/lib/Template.js +2 -2
- package/lib/TemplatedPathPlugin.js +1 -1
- package/lib/WarnDeprecatedOptionPlugin.js +7 -8
- package/lib/WatchIgnorePlugin.js +4 -3
- package/lib/WebpackIsIncludedPlugin.js +2 -1
- package/lib/WebpackOptionsApply.js +115 -27
- package/lib/asset/AssetGenerator.js +15 -11
- package/lib/asset/AssetModulesPlugin.js +19 -17
- package/lib/asset/AssetSourceGenerator.js +4 -4
- package/lib/asset/RawDataUrlModule.js +4 -2
- package/lib/async-modules/AwaitDependenciesInitFragment.js +1 -1
- package/lib/buildChunkGraph.js +6 -3
- package/lib/cache/AddBuildDependenciesPlugin.js +5 -6
- package/lib/cache/IdleFileCachePlugin.js +7 -4
- package/lib/cache/MemoryCachePlugin.js +1 -0
- package/lib/cache/MemoryWithGcCachePlugin.js +1 -0
- package/lib/cache/PackFileCacheStrategy.js +26 -20
- package/lib/cache/ResolverCachePlugin.js +16 -8
- package/lib/cli.js +15 -10
- package/lib/config/browserslistTargetHandler.js +3 -3
- package/lib/config/defaults.js +25 -17
- package/lib/config/normalization.js +2 -1
- package/lib/config/target.js +6 -5
- package/lib/container/ContainerPlugin.js +1 -1
- package/lib/container/ContainerReferencePlugin.js +1 -1
- package/lib/container/FallbackModule.js +2 -1
- package/lib/container/HoistContainerReferencesPlugin.js +1 -1
- package/lib/container/ModuleFederationPlugin.js +2 -2
- package/lib/container/RemoteModule.js +1 -1
- package/lib/css/CssGenerator.js +9 -6
- package/lib/css/CssModulesPlugin.js +44 -31
- package/lib/css/CssParser.js +6 -4
- package/lib/css/walkCssTokens.js +33 -37
- package/lib/debug/ProfilingPlugin.js +6 -6
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +8 -8
- package/lib/dependencies/AMDPlugin.js +12 -8
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +28 -26
- package/lib/dependencies/CachedConstDependency.js +1 -5
- package/lib/dependencies/CommonJsExportRequireDependency.js +6 -4
- package/lib/dependencies/CommonJsExportsParserPlugin.js +22 -25
- package/lib/dependencies/CommonJsFullRequireDependency.js +1 -9
- package/lib/dependencies/CommonJsImportsParserPlugin.js +100 -114
- package/lib/dependencies/CommonJsPlugin.js +15 -16
- package/lib/dependencies/ContextDependencyHelpers.js +2 -1
- package/lib/dependencies/ContextDependencyTemplateAsId.js +1 -0
- package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +1 -0
- package/lib/dependencies/CssIcssExportDependency.js +1 -1
- package/lib/dependencies/CssLocalIdentifierDependency.js +2 -2
- package/lib/dependencies/CssSelfLocalIdentifierDependency.js +2 -1
- package/lib/dependencies/DynamicExports.js +9 -9
- package/lib/dependencies/ExportsInfoDependency.js +1 -1
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +122 -101
- package/lib/dependencies/HarmonyExportExpressionDependency.js +1 -1
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +95 -19
- package/lib/dependencies/HarmonyExportInitFragment.js +1 -1
- package/lib/dependencies/HarmonyImportDependency.js +11 -5
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +238 -162
- package/lib/dependencies/HarmonyImportSideEffectDependency.js +4 -1
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +20 -9
- package/lib/dependencies/HarmonyModulesPlugin.js +23 -12
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +1 -0
- package/lib/dependencies/ImportMetaContextPlugin.js +2 -1
- package/lib/dependencies/ImportMetaPlugin.js +2 -2
- package/lib/dependencies/ImportParserPlugin.js +40 -9
- package/lib/dependencies/ImportPlugin.js +3 -1
- package/lib/dependencies/LoaderPlugin.js +1 -0
- package/lib/dependencies/ModuleDependency.js +3 -1
- package/lib/dependencies/ModuleDependencyTemplateAsRequireId.js +1 -0
- package/lib/dependencies/RequireContextPlugin.js +3 -1
- package/lib/dependencies/RequireEnsurePlugin.js +6 -6
- package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +33 -34
- package/lib/dependencies/RequireIncludePlugin.js +1 -0
- package/lib/dependencies/RuntimeRequirementsDependency.js +1 -1
- package/lib/dependencies/SystemPlugin.js +1 -1
- package/lib/dependencies/URLContextDependency.js +65 -0
- package/lib/dependencies/URLPlugin.js +17 -157
- package/lib/dependencies/WorkerPlugin.js +23 -10
- package/lib/dependencies/processExportInfo.js +2 -1
- package/lib/esm/ModuleChunkFormatPlugin.js +269 -185
- package/lib/esm/ModuleChunkLoadingPlugin.js +39 -1
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +70 -3
- package/lib/hmr/HotModuleReplacement.runtime.js +0 -1
- package/lib/hmr/HotModuleReplacementRuntimeModule.js +1 -1
- package/lib/hmr/JavascriptHotModuleReplacementHelper.js +37 -0
- package/lib/hmr/LazyCompilationPlugin.js +4 -2
- package/lib/hmr/lazyCompilationBackend.js +4 -2
- package/lib/ids/ChunkModuleIdRangePlugin.js +6 -3
- package/lib/ids/DeterministicChunkIdsPlugin.js +30 -35
- package/lib/ids/DeterministicModuleIdsPlugin.js +4 -3
- package/lib/ids/HashedModuleIdsPlugin.js +5 -4
- package/lib/ids/IdHelpers.js +21 -17
- package/lib/ids/NamedChunkIdsPlugin.js +5 -5
- package/lib/ids/NamedModuleIdsPlugin.js +4 -4
- package/lib/ids/NaturalChunkIdsPlugin.js +2 -1
- package/lib/ids/NaturalModuleIdsPlugin.js +1 -1
- package/lib/ids/OccurrenceChunkIdsPlugin.js +3 -2
- package/lib/ids/OccurrenceModuleIdsPlugin.js +1 -1
- package/lib/ids/SyncModuleIdsPlugin.js +1 -1
- package/lib/index.js +13 -3
- package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +113 -119
- package/lib/javascript/BasicEvaluatedExpression.js +2 -1
- package/lib/javascript/ChunkHelpers.js +1 -0
- package/lib/javascript/CommonJsChunkFormatPlugin.js +121 -136
- package/lib/javascript/EnableChunkLoadingPlugin.js +6 -3
- package/lib/javascript/JavascriptGenerator.js +14 -2
- package/lib/javascript/JavascriptModulesPlugin.js +68 -27
- package/lib/javascript/JavascriptParser.js +117 -76
- package/lib/javascript/JavascriptParserHelpers.js +41 -41
- package/lib/javascript/StartupHelpers.js +17 -17
- package/lib/json/JsonGenerator.js +4 -2
- package/lib/json/JsonModulesPlugin.js +2 -2
- package/lib/json/JsonParser.js +1 -1
- package/lib/library/AbstractLibraryPlugin.js +6 -2
- package/lib/library/AssignLibraryPlugin.js +21 -6
- package/lib/library/EnableLibraryPlugin.js +23 -3
- package/lib/library/UmdLibraryPlugin.js +15 -6
- package/lib/logging/createConsoleLogger.js +3 -3
- package/lib/logging/runtime.js +9 -9
- package/lib/node/ReadFileChunkLoadingRuntimeModule.js +4 -22
- package/lib/node/RequireChunkLoadingRuntimeModule.js +4 -22
- package/lib/node/nodeConsole.js +4 -2
- package/lib/optimize/AggressiveMergingPlugin.js +45 -46
- package/lib/optimize/AggressiveSplittingPlugin.js +13 -12
- package/lib/optimize/ConcatenatedModule.js +227 -57
- package/lib/optimize/EnsureChunkConditionsPlugin.js +58 -58
- package/lib/optimize/FlagIncludedChunksPlugin.js +3 -1
- package/lib/optimize/InnerGraph.js +115 -112
- package/lib/optimize/InnerGraphPlugin.js +2 -2
- package/lib/optimize/LimitChunkCountPlugin.js +4 -2
- package/lib/optimize/MangleExportsPlugin.js +4 -3
- package/lib/optimize/MergeDuplicateChunksPlugin.js +80 -81
- package/lib/optimize/MinChunkSizePlugin.js +6 -3
- package/lib/optimize/ModuleConcatenationPlugin.js +31 -22
- package/lib/optimize/RealContentHashPlugin.js +26 -20
- package/lib/optimize/RemoveEmptyChunksPlugin.js +2 -1
- package/lib/optimize/RemoveParentModulesPlugin.js +1 -0
- package/lib/optimize/SideEffectsFlagPlugin.js +3 -2
- package/lib/optimize/SplitChunksPlugin.js +16 -13
- package/lib/rules/BasicEffectRulePlugin.js +4 -2
- package/lib/rules/BasicMatcherRulePlugin.js +3 -1
- package/lib/rules/ObjectMatcherRulePlugin.js +3 -1
- package/lib/rules/RuleSetCompiler.js +19 -5
- package/lib/rules/UseEffectRulePlugin.js +17 -9
- package/lib/runtime/AsyncModuleRuntimeModule.js +64 -9
- package/lib/runtime/CreateFakeNamespaceObjectRuntimeModule.js +1 -1
- package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +214 -0
- package/lib/runtime/RuntimeIdRuntimeModule.js +2 -1
- package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +8 -7
- package/lib/schemes/FileUriPlugin.js +1 -1
- package/lib/schemes/HttpUriPlugin.js +27 -19
- package/lib/schemes/VirtualUrlPlugin.js +222 -0
- package/lib/serialization/AggregateErrorSerializer.js +1 -1
- package/lib/serialization/BinaryMiddleware.js +5 -4
- package/lib/serialization/FileMiddleware.js +7 -4
- package/lib/serialization/ObjectMiddleware.js +14 -8
- package/lib/serialization/Serializer.js +5 -3
- package/lib/serialization/SerializerMiddleware.js +2 -0
- package/lib/sharing/ConsumeSharedModule.js +1 -1
- package/lib/sharing/ConsumeSharedPlugin.js +3 -3
- package/lib/sharing/ConsumeSharedRuntimeModule.js +2 -2
- package/lib/sharing/ProvideSharedModule.js +1 -1
- package/lib/sharing/ProvideSharedPlugin.js +3 -2
- package/lib/sharing/SharePlugin.js +2 -1
- package/lib/sharing/ShareRuntimeModule.js +3 -5
- package/lib/sharing/utils.js +34 -34
- package/lib/stats/DefaultStatsFactoryPlugin.js +49 -46
- package/lib/stats/DefaultStatsPresetPlugin.js +13 -13
- package/lib/stats/DefaultStatsPrinterPlugin.js +15 -9
- package/lib/stats/StatsFactory.js +6 -3
- package/lib/stats/StatsPrinter.js +6 -7
- package/lib/url/URLParserPlugin.js +266 -0
- package/lib/util/ArrayQueue.js +1 -1
- package/lib/util/AsyncQueue.js +1 -1
- package/lib/util/Hash.js +2 -0
- package/lib/util/IterableHelpers.js +1 -1
- package/lib/util/LazyBucketSortedSet.js +2 -1
- package/lib/util/LazySet.js +11 -6
- package/lib/util/ParallelismFactorCalculator.js +1 -1
- package/lib/util/SetHelpers.js +3 -3
- package/lib/util/SortableSet.js +2 -2
- package/lib/util/StackedCacheMap.js +3 -1
- package/lib/util/StackedMap.js +2 -2
- package/lib/util/StringXor.js +1 -0
- package/lib/util/TupleSet.js +1 -0
- package/lib/util/URLAbsoluteSpecifier.js +1 -1
- package/lib/util/cleverMerge.js +95 -58
- package/lib/util/comparators.js +154 -127
- package/lib/util/compileBooleanMatcher.js +8 -3
- package/lib/util/concatenate.js +8 -7
- package/lib/util/conventions.js +72 -73
- package/lib/util/create-schema-validation.js +2 -1
- package/lib/util/createHash.js +10 -4
- package/lib/util/deprecation.js +69 -66
- package/lib/util/deterministicGrouping.js +4 -2
- package/lib/util/extractUrlAndGlobal.js +1 -1
- package/lib/util/findGraphRoots.js +2 -2
- package/lib/util/fs.js +30 -23
- package/lib/util/hash/md4.js +2 -2
- package/lib/util/hash/wasm-hash.js +4 -2
- package/lib/util/identifier.js +13 -12
- package/lib/util/internalSerializables.js +2 -0
- package/lib/util/magicComment.js +5 -5
- package/lib/util/processAsyncTree.js +1 -1
- package/lib/util/propertyAccess.js +1 -1
- package/lib/util/propertyName.js +1 -1
- package/lib/util/registerExternalSerializer.js +1 -2
- package/lib/util/removeBOM.js +1 -1
- package/lib/util/runtime.js +29 -21
- package/lib/util/semver.js +1 -1
- package/lib/util/serialization.js +3 -0
- package/lib/util/source.js +3 -2
- package/lib/validateSchema.js +1 -0
- package/lib/wasm/EnableWasmLoadingPlugin.js +6 -3
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +4 -1
- package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +46 -49
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +2 -2
- package/lib/wasm-sync/WebAssemblyGenerator.js +2 -3
- package/lib/wasm-sync/WebAssemblyInInitialChunkError.js +3 -2
- package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +3 -0
- package/lib/wasm-sync/WebAssemblyUtils.js +1 -1
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +4 -22
- package/lib/webpack.js +4 -5
- package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +1 -0
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +6 -24
- package/lib/webworker/WebWorkerTemplatePlugin.js +1 -0
- package/package.json +119 -113
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +17 -0
- package/schemas/plugins/schemes/VirtualUrlPlugin.check.d.ts +7 -0
- package/schemas/plugins/schemes/VirtualUrlPlugin.check.js +6 -0
- package/schemas/plugins/schemes/VirtualUrlPlugin.json +77 -0
- package/types.d.ts +1243 -409
|
@@ -6,21 +6,111 @@
|
|
|
6
6
|
"use strict";
|
|
7
7
|
|
|
8
8
|
const { ConcatSource } = require("webpack-sources");
|
|
9
|
-
const { RuntimeGlobals } = require("..");
|
|
10
|
-
const HotUpdateChunk = require("../HotUpdateChunk");
|
|
9
|
+
const { HotUpdateChunk, RuntimeGlobals } = require("..");
|
|
11
10
|
const Template = require("../Template");
|
|
12
11
|
const { getAllChunks } = require("../javascript/ChunkHelpers");
|
|
13
12
|
const {
|
|
14
13
|
chunkHasJs,
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
getChunkFilenameTemplate,
|
|
15
|
+
getCompilationHooks
|
|
17
16
|
} = require("../javascript/JavascriptModulesPlugin");
|
|
18
17
|
const { updateHashForEntryStartup } = require("../javascript/StartupHelpers");
|
|
19
18
|
const { getUndoPath } = require("../util/identifier");
|
|
20
19
|
|
|
20
|
+
/** @typedef {import("webpack-sources").Source} Source */
|
|
21
21
|
/** @typedef {import("../Chunk")} Chunk */
|
|
22
|
+
/** @typedef {import("../ChunkGraph")} ChunkGraph */
|
|
23
|
+
/** @typedef {import("../ChunkGroup")} ChunkGroup */
|
|
24
|
+
/** @typedef {import("../Compilation")} Compilation */
|
|
22
25
|
/** @typedef {import("../Compiler")} Compiler */
|
|
23
26
|
/** @typedef {import("../Entrypoint")} Entrypoint */
|
|
27
|
+
/** @typedef {import("../Module")} Module */
|
|
28
|
+
/** @typedef {import("../javascript/JavascriptModulesPlugin").RenderContext} RenderContext */
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Gets information about a chunk including its entries and runtime chunk
|
|
32
|
+
* @param {Chunk} chunk The chunk to get information for
|
|
33
|
+
* @param {ChunkGraph} chunkGraph The chunk graph containing the chunk
|
|
34
|
+
* @returns {{entries: Array<[Module, Entrypoint | undefined]>, runtimeChunk: Chunk|null}} Object containing chunk entries and runtime chunk
|
|
35
|
+
*/
|
|
36
|
+
function getChunkInfo(chunk, chunkGraph) {
|
|
37
|
+
const entries = [
|
|
38
|
+
...chunkGraph.getChunkEntryModulesWithChunkGroupIterable(chunk)
|
|
39
|
+
];
|
|
40
|
+
const runtimeChunk =
|
|
41
|
+
entries.length > 0
|
|
42
|
+
? /** @type {Entrypoint[][]} */
|
|
43
|
+
(entries)[0][1].getRuntimeChunk()
|
|
44
|
+
: null;
|
|
45
|
+
|
|
46
|
+
return {
|
|
47
|
+
entries,
|
|
48
|
+
runtimeChunk
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* @param {Compilation} compilation the compilation instance
|
|
54
|
+
* @param {Chunk} chunk the chunk
|
|
55
|
+
* @param {Chunk} runtimeChunk the runtime chunk
|
|
56
|
+
* @returns {string} the relative path
|
|
57
|
+
*/
|
|
58
|
+
const getRelativePath = (compilation, chunk, runtimeChunk) => {
|
|
59
|
+
const currentOutputName = compilation
|
|
60
|
+
.getPath(
|
|
61
|
+
getChunkFilenameTemplate(runtimeChunk, compilation.outputOptions),
|
|
62
|
+
{
|
|
63
|
+
chunk: runtimeChunk,
|
|
64
|
+
contentHashType: "javascript"
|
|
65
|
+
}
|
|
66
|
+
)
|
|
67
|
+
.replace(/^\/+/g, "")
|
|
68
|
+
.split("/");
|
|
69
|
+
const baseOutputName = [...currentOutputName];
|
|
70
|
+
const chunkOutputName = compilation
|
|
71
|
+
.getPath(getChunkFilenameTemplate(chunk, compilation.outputOptions), {
|
|
72
|
+
chunk,
|
|
73
|
+
contentHashType: "javascript"
|
|
74
|
+
})
|
|
75
|
+
.replace(/^\/+/g, "")
|
|
76
|
+
.split("/");
|
|
77
|
+
|
|
78
|
+
// remove common parts except filename
|
|
79
|
+
while (
|
|
80
|
+
baseOutputName.length > 1 &&
|
|
81
|
+
chunkOutputName.length > 1 &&
|
|
82
|
+
baseOutputName[0] === chunkOutputName[0]
|
|
83
|
+
) {
|
|
84
|
+
baseOutputName.shift();
|
|
85
|
+
chunkOutputName.shift();
|
|
86
|
+
}
|
|
87
|
+
const last = chunkOutputName.join("/");
|
|
88
|
+
// create final path
|
|
89
|
+
return getUndoPath(baseOutputName.join("/"), last, true) + last;
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* @param {Compilation} compilation the compilation instance
|
|
94
|
+
* @param {Chunk} chunk the chunk to render the import for
|
|
95
|
+
* @param {string=} namedImport the named import to use for the import
|
|
96
|
+
* @param {Chunk=} runtimeChunk the runtime chunk
|
|
97
|
+
* @returns {string} the import source
|
|
98
|
+
*/
|
|
99
|
+
function renderChunkImport(compilation, chunk, namedImport, runtimeChunk) {
|
|
100
|
+
return `import ${namedImport ? `* as ${namedImport}` : RuntimeGlobals.require} from ${JSON.stringify(
|
|
101
|
+
getRelativePath(compilation, chunk, runtimeChunk || chunk)
|
|
102
|
+
)};\n`;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* @param {number} index the index of the chunk
|
|
107
|
+
* @returns {string} the named import to use for the import
|
|
108
|
+
*/
|
|
109
|
+
function getChunkNamedImport(index) {
|
|
110
|
+
return `__webpack_chunk_${index}__`;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const PLUGIN_NAME = "ModuleChunkFormatPlugin";
|
|
24
114
|
|
|
25
115
|
class ModuleChunkFormatPlugin {
|
|
26
116
|
/**
|
|
@@ -29,194 +119,188 @@ class ModuleChunkFormatPlugin {
|
|
|
29
119
|
* @returns {void}
|
|
30
120
|
*/
|
|
31
121
|
apply(compiler) {
|
|
32
|
-
compiler.hooks.thisCompilation.tap(
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
(chunk
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
122
|
+
compiler.hooks.thisCompilation.tap(PLUGIN_NAME, compilation => {
|
|
123
|
+
compilation.hooks.additionalChunkRuntimeRequirements.tap(
|
|
124
|
+
PLUGIN_NAME,
|
|
125
|
+
(chunk, set) => {
|
|
126
|
+
if (chunk.hasRuntime()) return;
|
|
127
|
+
if (compilation.chunkGraph.getNumberOfEntryModules(chunk) > 0) {
|
|
128
|
+
set.add(RuntimeGlobals.require);
|
|
129
|
+
set.add(RuntimeGlobals.externalInstallChunk);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
);
|
|
133
|
+
const hooks = getCompilationHooks(compilation);
|
|
134
|
+
/**
|
|
135
|
+
* @param {Set<Chunk>} chunks the chunks to render
|
|
136
|
+
* @param {ChunkGraph} chunkGraph the chunk graph
|
|
137
|
+
* @param {Chunk=} runtimeChunk the runtime chunk
|
|
138
|
+
* @returns {Source|undefined} the source
|
|
139
|
+
*/
|
|
140
|
+
const withDependentChunks = (chunks, chunkGraph, runtimeChunk) => {
|
|
141
|
+
if (/** @type {Set<Chunk>} */ (chunks).size > 0) {
|
|
142
|
+
const source = new ConcatSource();
|
|
143
|
+
let index = 0;
|
|
144
|
+
|
|
145
|
+
for (const chunk of chunks) {
|
|
146
|
+
index++;
|
|
147
|
+
|
|
148
|
+
if (!chunkHasJs(chunk, chunkGraph)) {
|
|
149
|
+
continue;
|
|
43
150
|
}
|
|
151
|
+
const namedImport = getChunkNamedImport(index);
|
|
152
|
+
source.add(
|
|
153
|
+
renderChunkImport(
|
|
154
|
+
compilation,
|
|
155
|
+
chunk,
|
|
156
|
+
namedImport,
|
|
157
|
+
runtimeChunk || chunk
|
|
158
|
+
)
|
|
159
|
+
);
|
|
160
|
+
source.add(
|
|
161
|
+
`${RuntimeGlobals.externalInstallChunk}(${namedImport});\n`
|
|
162
|
+
);
|
|
44
163
|
}
|
|
164
|
+
return source;
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
hooks.renderStartup.tap(
|
|
168
|
+
PLUGIN_NAME,
|
|
169
|
+
(modules, _lastModule, renderContext) => {
|
|
170
|
+
const { chunk, chunkGraph } = renderContext;
|
|
171
|
+
if (!chunk.hasRuntime()) {
|
|
172
|
+
return modules;
|
|
173
|
+
}
|
|
174
|
+
const entryDependentChunks =
|
|
175
|
+
chunkGraph.getChunkEntryDependentChunksIterable(chunk);
|
|
176
|
+
const sourceWithDependentChunks = withDependentChunks(
|
|
177
|
+
/** @type {Set<Chunk>} */ (entryDependentChunks),
|
|
178
|
+
chunkGraph,
|
|
179
|
+
chunk
|
|
180
|
+
);
|
|
181
|
+
if (!sourceWithDependentChunks) {
|
|
182
|
+
return modules;
|
|
183
|
+
}
|
|
184
|
+
if (modules.size() === 0) {
|
|
185
|
+
return sourceWithDependentChunks;
|
|
186
|
+
}
|
|
187
|
+
const source = new ConcatSource();
|
|
188
|
+
source.add(sourceWithDependentChunks);
|
|
189
|
+
source.add("\n");
|
|
190
|
+
source.add(modules);
|
|
191
|
+
return source;
|
|
192
|
+
}
|
|
193
|
+
);
|
|
194
|
+
hooks.renderChunk.tap(PLUGIN_NAME, (modules, renderContext) => {
|
|
195
|
+
const { chunk, chunkGraph, runtimeTemplate } = renderContext;
|
|
196
|
+
const hotUpdateChunk = chunk instanceof HotUpdateChunk ? chunk : null;
|
|
197
|
+
const source = new ConcatSource();
|
|
198
|
+
source.add(
|
|
199
|
+
`export const __webpack_id__ = ${JSON.stringify(chunk.id)};\n`
|
|
45
200
|
);
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
const getRelativePath = chunk => {
|
|
102
|
-
const baseOutputName = currentOutputName.slice();
|
|
103
|
-
const chunkOutputName = compilation
|
|
104
|
-
.getPath(
|
|
105
|
-
getChunkFilenameTemplate(
|
|
106
|
-
chunk,
|
|
107
|
-
compilation.outputOptions
|
|
108
|
-
),
|
|
109
|
-
{
|
|
110
|
-
chunk,
|
|
111
|
-
contentHashType: "javascript"
|
|
112
|
-
}
|
|
113
|
-
)
|
|
114
|
-
.replace(/^\/+/g, "")
|
|
115
|
-
.split("/");
|
|
116
|
-
|
|
117
|
-
// remove common parts except filename
|
|
118
|
-
while (
|
|
119
|
-
baseOutputName.length > 1 &&
|
|
120
|
-
chunkOutputName.length > 1 &&
|
|
121
|
-
baseOutputName[0] === chunkOutputName[0]
|
|
122
|
-
) {
|
|
123
|
-
baseOutputName.shift();
|
|
124
|
-
chunkOutputName.shift();
|
|
125
|
-
}
|
|
126
|
-
const last = chunkOutputName.join("/");
|
|
127
|
-
// create final path
|
|
128
|
-
return (
|
|
129
|
-
getUndoPath(baseOutputName.join("/"), last, true) + last
|
|
130
|
-
);
|
|
131
|
-
};
|
|
132
|
-
|
|
133
|
-
const entrySource = new ConcatSource();
|
|
134
|
-
entrySource.add(source);
|
|
135
|
-
entrySource.add(";\n\n// load runtime\n");
|
|
136
|
-
entrySource.add(
|
|
137
|
-
`import ${RuntimeGlobals.require} from ${JSON.stringify(
|
|
138
|
-
getRelativePath(/** @type {Chunk} */ (runtimeChunk))
|
|
139
|
-
)};\n`
|
|
140
|
-
);
|
|
141
|
-
|
|
142
|
-
const startupSource = new ConcatSource();
|
|
143
|
-
startupSource.add(
|
|
144
|
-
`var __webpack_exec__ = ${runtimeTemplate.returningFunction(
|
|
145
|
-
`${RuntimeGlobals.require}(${RuntimeGlobals.entryModuleId} = moduleId)`,
|
|
146
|
-
"moduleId"
|
|
147
|
-
)}\n`
|
|
148
|
-
);
|
|
149
|
-
|
|
150
|
-
const loadedChunks = new Set();
|
|
151
|
-
let index = 0;
|
|
152
|
-
for (let i = 0; i < entries.length; i++) {
|
|
153
|
-
const [module, entrypoint] = entries[i];
|
|
154
|
-
if (
|
|
155
|
-
!chunkGraph.getModuleSourceTypes(module).has("javascript")
|
|
156
|
-
) {
|
|
157
|
-
continue;
|
|
158
|
-
}
|
|
159
|
-
const final = i + 1 === entries.length;
|
|
160
|
-
const moduleId = chunkGraph.getModuleId(module);
|
|
161
|
-
const chunks = getAllChunks(
|
|
162
|
-
/** @type {Entrypoint} */ (entrypoint),
|
|
163
|
-
/** @type {Chunk} */ (runtimeChunk),
|
|
164
|
-
undefined
|
|
165
|
-
);
|
|
166
|
-
for (const chunk of chunks) {
|
|
167
|
-
if (
|
|
168
|
-
loadedChunks.has(chunk) ||
|
|
169
|
-
!chunkHasJs(chunk, chunkGraph)
|
|
170
|
-
)
|
|
171
|
-
continue;
|
|
172
|
-
loadedChunks.add(chunk);
|
|
173
|
-
startupSource.add(
|
|
174
|
-
`import * as __webpack_chunk_${index}__ from ${JSON.stringify(
|
|
175
|
-
getRelativePath(chunk)
|
|
176
|
-
)};\n`
|
|
177
|
-
);
|
|
178
|
-
startupSource.add(
|
|
179
|
-
`${RuntimeGlobals.externalInstallChunk}(__webpack_chunk_${index}__);\n`
|
|
180
|
-
);
|
|
181
|
-
index++;
|
|
182
|
-
}
|
|
183
|
-
startupSource.add(
|
|
184
|
-
`${
|
|
185
|
-
final ? `var ${RuntimeGlobals.exports} = ` : ""
|
|
186
|
-
}__webpack_exec__(${JSON.stringify(moduleId)});\n`
|
|
187
|
-
);
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
entrySource.add(
|
|
191
|
-
hooks.renderStartup.call(
|
|
192
|
-
startupSource,
|
|
193
|
-
entries[entries.length - 1][0],
|
|
194
|
-
{
|
|
195
|
-
...renderContext,
|
|
196
|
-
inlined: false
|
|
197
|
-
}
|
|
198
|
-
)
|
|
199
|
-
);
|
|
200
|
-
return entrySource;
|
|
201
|
+
source.add(
|
|
202
|
+
`export const __webpack_ids__ = ${JSON.stringify(chunk.ids)};\n`
|
|
203
|
+
);
|
|
204
|
+
source.add("export const __webpack_modules__ = ");
|
|
205
|
+
source.add(modules);
|
|
206
|
+
source.add(";\n");
|
|
207
|
+
const runtimeModules = chunkGraph.getChunkRuntimeModulesInOrder(chunk);
|
|
208
|
+
if (runtimeModules.length > 0) {
|
|
209
|
+
source.add("export const __webpack_runtime__ =\n");
|
|
210
|
+
source.add(
|
|
211
|
+
Template.renderChunkRuntimeModules(runtimeModules, renderContext)
|
|
212
|
+
);
|
|
213
|
+
}
|
|
214
|
+
if (hotUpdateChunk) {
|
|
215
|
+
return source;
|
|
216
|
+
}
|
|
217
|
+
const { entries, runtimeChunk } = getChunkInfo(chunk, chunkGraph);
|
|
218
|
+
if (runtimeChunk) {
|
|
219
|
+
const entrySource = new ConcatSource();
|
|
220
|
+
entrySource.add(source);
|
|
221
|
+
entrySource.add(";\n\n// load runtime\n");
|
|
222
|
+
entrySource.add(
|
|
223
|
+
renderChunkImport(compilation, runtimeChunk, "", chunk)
|
|
224
|
+
);
|
|
225
|
+
const startupSource = new ConcatSource();
|
|
226
|
+
startupSource.add(
|
|
227
|
+
`var __webpack_exec__ = ${runtimeTemplate.returningFunction(
|
|
228
|
+
`${RuntimeGlobals.require}(${RuntimeGlobals.entryModuleId} = moduleId)`,
|
|
229
|
+
"moduleId"
|
|
230
|
+
)}\n`
|
|
231
|
+
);
|
|
232
|
+
|
|
233
|
+
const loadedChunks = new Set();
|
|
234
|
+
for (let i = 0; i < entries.length; i++) {
|
|
235
|
+
const [module, entrypoint] = entries[i];
|
|
236
|
+
if (!chunkGraph.getModuleSourceTypes(module).has("javascript")) {
|
|
237
|
+
continue;
|
|
238
|
+
}
|
|
239
|
+
const final = i + 1 === entries.length;
|
|
240
|
+
const moduleId = chunkGraph.getModuleId(module);
|
|
241
|
+
const entryDependentChunks = /** @type {Set<Chunk>} */ (
|
|
242
|
+
chunkGraph.getChunkEntryDependentChunksIterable(chunk)
|
|
243
|
+
);
|
|
244
|
+
const chunks = getAllChunks(
|
|
245
|
+
/** @type {Entrypoint} */ (entrypoint),
|
|
246
|
+
/** @type {Chunk} */ (runtimeChunk),
|
|
247
|
+
undefined
|
|
248
|
+
);
|
|
249
|
+
const processChunks = new Set();
|
|
250
|
+
for (const _chunk of chunks) {
|
|
251
|
+
if (
|
|
252
|
+
loadedChunks.has(_chunk) ||
|
|
253
|
+
entryDependentChunks.has(_chunk)
|
|
254
|
+
) {
|
|
255
|
+
continue;
|
|
201
256
|
}
|
|
257
|
+
loadedChunks.add(_chunk);
|
|
258
|
+
processChunks.add(_chunk);
|
|
202
259
|
}
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
260
|
+
const sourceWithDependentChunks = withDependentChunks(
|
|
261
|
+
processChunks,
|
|
262
|
+
chunkGraph,
|
|
263
|
+
chunk
|
|
264
|
+
);
|
|
265
|
+
if (sourceWithDependentChunks) {
|
|
266
|
+
startupSource.add("\n");
|
|
267
|
+
startupSource.add(sourceWithDependentChunks);
|
|
268
|
+
}
|
|
269
|
+
startupSource.add(
|
|
270
|
+
`${
|
|
271
|
+
final ? `var ${RuntimeGlobals.exports} = ` : ""
|
|
272
|
+
}__webpack_exec__(${JSON.stringify(moduleId)});\n`
|
|
214
273
|
);
|
|
215
|
-
updateHashForEntryStartup(hash, chunkGraph, entries, chunk);
|
|
216
274
|
}
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
275
|
+
|
|
276
|
+
entrySource.add(
|
|
277
|
+
hooks.renderStartup.call(
|
|
278
|
+
startupSource,
|
|
279
|
+
entries[entries.length - 1][0],
|
|
280
|
+
{
|
|
281
|
+
...renderContext,
|
|
282
|
+
inlined: false
|
|
283
|
+
}
|
|
284
|
+
)
|
|
285
|
+
);
|
|
286
|
+
return entrySource;
|
|
287
|
+
}
|
|
288
|
+
return source;
|
|
289
|
+
});
|
|
290
|
+
hooks.chunkHash.tap(PLUGIN_NAME, (chunk, hash, { chunkGraph }) => {
|
|
291
|
+
if (chunk.hasRuntime()) return;
|
|
292
|
+
const { entries, runtimeChunk } = getChunkInfo(chunk, chunkGraph);
|
|
293
|
+
hash.update(PLUGIN_NAME);
|
|
294
|
+
hash.update("1");
|
|
295
|
+
if (runtimeChunk && runtimeChunk.hash) {
|
|
296
|
+
// Any change to runtimeChunk should trigger a hash update,
|
|
297
|
+
// we shouldn't depend on or inspect its internal implementation.
|
|
298
|
+
// import __webpack_require__ from "./runtime-main.e9400aee33633a3973bd.js";
|
|
299
|
+
hash.update(runtimeChunk.hash);
|
|
300
|
+
}
|
|
301
|
+
updateHashForEntryStartup(hash, chunkGraph, entries, chunk);
|
|
302
|
+
});
|
|
303
|
+
});
|
|
220
304
|
}
|
|
221
305
|
}
|
|
222
306
|
|
|
@@ -63,10 +63,19 @@ class ModuleChunkLoadingPlugin {
|
|
|
63
63
|
compilation.hooks.runtimeRequirementInTree
|
|
64
64
|
.for(RuntimeGlobals.onChunksLoaded)
|
|
65
65
|
.tap(PLUGIN_NAME, handler);
|
|
66
|
+
compilation.hooks.runtimeRequirementInTree
|
|
67
|
+
.for(RuntimeGlobals.hmrDownloadUpdateHandlers)
|
|
68
|
+
.tap(PLUGIN_NAME, handler);
|
|
69
|
+
compilation.hooks.runtimeRequirementInTree
|
|
70
|
+
.for(RuntimeGlobals.hmrDownloadManifest)
|
|
71
|
+
.tap(PLUGIN_NAME, handler);
|
|
66
72
|
compilation.hooks.runtimeRequirementInTree
|
|
67
73
|
.for(RuntimeGlobals.externalInstallChunk)
|
|
68
|
-
.tap(PLUGIN_NAME, (chunk, set) => {
|
|
74
|
+
.tap(PLUGIN_NAME, (chunk, set, { chunkGraph }) => {
|
|
69
75
|
if (!isEnabledForChunk(chunk)) return;
|
|
76
|
+
// If a chunk contains an entryModule, all exports are determined by the entryModule.
|
|
77
|
+
// The ExportWebpackRequireRuntimeModule is for internal use only and not exposed to users.
|
|
78
|
+
if (chunkGraph.getNumberOfEntryModules(chunk) > 0) return;
|
|
70
79
|
compilation.addRuntimeModule(
|
|
71
80
|
chunk,
|
|
72
81
|
new ExportWebpackRequireRuntimeModule()
|
|
@@ -99,6 +108,35 @@ class ModuleChunkLoadingPlugin {
|
|
|
99
108
|
|
|
100
109
|
set.add(RuntimeGlobals.getChunkScriptFilename);
|
|
101
110
|
});
|
|
111
|
+
|
|
112
|
+
compilation.hooks.runtimeRequirementInTree
|
|
113
|
+
.for(RuntimeGlobals.hmrDownloadUpdateHandlers)
|
|
114
|
+
.tap(PLUGIN_NAME, (chunk, set) => {
|
|
115
|
+
if (!isEnabledForChunk(chunk)) return;
|
|
116
|
+
set.add(RuntimeGlobals.publicPath);
|
|
117
|
+
set.add(RuntimeGlobals.loadScript);
|
|
118
|
+
set.add(RuntimeGlobals.getChunkUpdateScriptFilename);
|
|
119
|
+
set.add(RuntimeGlobals.moduleCache);
|
|
120
|
+
set.add(RuntimeGlobals.hmrModuleData);
|
|
121
|
+
set.add(RuntimeGlobals.moduleFactoriesAddOnly);
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
compilation.hooks.runtimeRequirementInTree
|
|
125
|
+
.for(RuntimeGlobals.hmrDownloadManifest)
|
|
126
|
+
.tap(PLUGIN_NAME, (chunk, set) => {
|
|
127
|
+
if (!isEnabledForChunk(chunk)) return;
|
|
128
|
+
set.add(RuntimeGlobals.publicPath);
|
|
129
|
+
set.add(RuntimeGlobals.getUpdateManifestFilename);
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
compilation.hooks.additionalTreeRuntimeRequirements.tap(
|
|
133
|
+
PLUGIN_NAME,
|
|
134
|
+
(chunk, set, { chunkGraph }) => {
|
|
135
|
+
if (chunkGraph.hasChunkEntryDependentChunks(chunk)) {
|
|
136
|
+
set.add(RuntimeGlobals.externalInstallChunk);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
);
|
|
102
140
|
});
|
|
103
141
|
}
|
|
104
142
|
}
|
|
@@ -10,8 +10,11 @@ const RuntimeGlobals = require("../RuntimeGlobals");
|
|
|
10
10
|
const RuntimeModule = require("../RuntimeModule");
|
|
11
11
|
const Template = require("../Template");
|
|
12
12
|
const {
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
generateJavascriptHMR
|
|
14
|
+
} = require("../hmr/JavascriptHotModuleReplacementHelper");
|
|
15
|
+
const {
|
|
16
|
+
chunkHasJs,
|
|
17
|
+
getChunkFilenameTemplate
|
|
15
18
|
} = require("../javascript/JavascriptModulesPlugin");
|
|
16
19
|
const { getInitialChunkIds } = require("../javascript/StartupHelpers");
|
|
17
20
|
const compileBooleanMatcher = require("../util/compileBooleanMatcher");
|
|
@@ -109,6 +112,9 @@ class ModuleChunkLoadingRuntimeModule extends RuntimeModule {
|
|
|
109
112
|
const withHmr = this._runtimeRequirements.has(
|
|
110
113
|
RuntimeGlobals.hmrDownloadUpdateHandlers
|
|
111
114
|
);
|
|
115
|
+
const withHmrManifest = this._runtimeRequirements.has(
|
|
116
|
+
RuntimeGlobals.hmrDownloadManifest
|
|
117
|
+
);
|
|
112
118
|
const { linkPreload, linkPrefetch } =
|
|
113
119
|
ModuleChunkLoadingRuntimeModule.getCompilationHooks(compilation);
|
|
114
120
|
const isNeutralPlatform = runtimeTemplate.isNeutralPlatform();
|
|
@@ -346,7 +352,68 @@ class ModuleChunkLoadingRuntimeModule extends RuntimeModule {
|
|
|
346
352
|
"installedChunks[chunkId] === 0",
|
|
347
353
|
"chunkId"
|
|
348
354
|
)};`
|
|
349
|
-
: "// no on chunks loaded"
|
|
355
|
+
: "// no on chunks loaded",
|
|
356
|
+
withHmr
|
|
357
|
+
? Template.asString([
|
|
358
|
+
generateJavascriptHMR("module"),
|
|
359
|
+
"",
|
|
360
|
+
"function loadUpdateChunk(chunkId, updatedModulesList) {",
|
|
361
|
+
Template.indent([
|
|
362
|
+
`return new Promise(${runtimeTemplate.basicFunction(
|
|
363
|
+
"resolve, reject",
|
|
364
|
+
[
|
|
365
|
+
"// start update chunk loading",
|
|
366
|
+
`var url = ${RuntimeGlobals.publicPath} + ${RuntimeGlobals.getChunkUpdateScriptFilename}(chunkId);`,
|
|
367
|
+
`var onResolve = ${runtimeTemplate.basicFunction("obj", [
|
|
368
|
+
"var updatedModules = obj.__webpack_modules__;",
|
|
369
|
+
"var updatedRuntime = obj.__webpack_runtime__;",
|
|
370
|
+
"if(updatedRuntime) currentUpdateRuntime.push(updatedRuntime);",
|
|
371
|
+
"for(var moduleId in updatedModules) {",
|
|
372
|
+
Template.indent([
|
|
373
|
+
`if(${RuntimeGlobals.hasOwnProperty}(updatedModules, moduleId)) {`,
|
|
374
|
+
Template.indent([
|
|
375
|
+
"currentUpdate[moduleId] = updatedModules[moduleId];",
|
|
376
|
+
"if(updatedModulesList) updatedModulesList.push(moduleId);"
|
|
377
|
+
]),
|
|
378
|
+
"}"
|
|
379
|
+
]),
|
|
380
|
+
"}",
|
|
381
|
+
"resolve(obj);"
|
|
382
|
+
])};`,
|
|
383
|
+
`var onReject = ${runtimeTemplate.basicFunction("error", [
|
|
384
|
+
"var errorMsg = error.message || 'unknown reason';",
|
|
385
|
+
"error.message = 'Loading hot update chunk ' + chunkId + ' failed.\\n(' + errorMsg + ')';",
|
|
386
|
+
"error.name = 'ChunkLoadError';",
|
|
387
|
+
"reject(error);"
|
|
388
|
+
])}`,
|
|
389
|
+
`var loadScript = ${runtimeTemplate.basicFunction(
|
|
390
|
+
"url, onResolve, onReject",
|
|
391
|
+
[
|
|
392
|
+
`return ${importFunctionName}(/* webpackIgnore: true */ url).then(onResolve).catch(onReject)`
|
|
393
|
+
]
|
|
394
|
+
)}
|
|
395
|
+
loadScript(url, onResolve, onReject);`
|
|
396
|
+
]
|
|
397
|
+
)});`
|
|
398
|
+
]),
|
|
399
|
+
"}",
|
|
400
|
+
""
|
|
401
|
+
])
|
|
402
|
+
: "// no HMR",
|
|
403
|
+
"",
|
|
404
|
+
withHmrManifest
|
|
405
|
+
? Template.asString([
|
|
406
|
+
`${
|
|
407
|
+
RuntimeGlobals.hmrDownloadManifest
|
|
408
|
+
} = ${runtimeTemplate.basicFunction("", [
|
|
409
|
+
`return ${importFunctionName}(/* webpackIgnore: true */ ${RuntimeGlobals.publicPath} + ${
|
|
410
|
+
RuntimeGlobals.getUpdateManifestFilename
|
|
411
|
+
}()).then(${runtimeTemplate.basicFunction("obj", [
|
|
412
|
+
"return obj.default;"
|
|
413
|
+
])});`
|
|
414
|
+
])};`
|
|
415
|
+
])
|
|
416
|
+
: "// no HMR manifest"
|
|
350
417
|
]);
|
|
351
418
|
}
|
|
352
419
|
}
|
|
@@ -19,7 +19,7 @@ class HotModuleReplacementRuntimeModule extends RuntimeModule {
|
|
|
19
19
|
*/
|
|
20
20
|
generate() {
|
|
21
21
|
return Template.getFunctionContent(
|
|
22
|
-
require("./HotModuleReplacement.runtime
|
|
22
|
+
require("./HotModuleReplacement.runtime")
|
|
23
23
|
)
|
|
24
24
|
.replace(
|
|
25
25
|
/\$interceptModuleExecution\$/g,
|