@depup/webpack 5.110.1-depup.0 → 5.111.1-depup.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/README.md +7 -8
- package/changes.json +7 -11
- package/lib/APIPlugin.js +26 -11
- package/lib/AutomaticPrefetchPlugin.js +1 -1
- package/lib/Cache.js +8 -3
- package/lib/CacheFacade.js +1 -1
- package/lib/ChunkGraph.js +20 -18
- package/lib/CircularModulesPlugin.js +157 -55
- package/lib/CleanPlugin.js +2 -2
- package/lib/CompatibilityPlugin.js +3 -4
- package/lib/Compilation.js +337 -338
- package/lib/Compiler.js +213 -51
- package/lib/ConcatenationScope.js +25 -35
- package/lib/ConstPlugin.js +16 -132
- package/lib/CopyPlugin.js +1054 -0
- package/lib/DefinePlugin.js +24 -8
- package/lib/DependencyTemplate.js +2 -1
- package/lib/DotenvPlugin.js +64 -40
- package/lib/ErrorHelpers.js +113 -0
- package/lib/ExportsInfo.js +30 -16
- package/lib/ExternalModule.js +47 -22
- package/lib/FileSystemInfo.js +17 -14
- package/lib/FlagDependencyExportsPlugin.js +53 -34
- package/lib/FlagDependencyUsagePlugin.js +17 -15
- package/lib/Generator.js +24 -2
- package/lib/HotModuleReplacementPlugin.js +55 -7
- package/lib/IgnorePlugin.js +1 -1
- package/lib/JavascriptMetaInfoPlugin.js +5 -3
- package/lib/LoaderOptionsPlugin.js +1 -1
- package/lib/MainTemplate.js +5 -1
- package/lib/Module.js +19 -10
- package/lib/ModuleGraph.js +6 -9
- package/lib/MultiCompiler.js +7 -17
- package/lib/MultiWatching.js +1 -1
- package/lib/NormalModule.js +148 -70
- package/lib/NormalModuleFactory.js +1 -1
- package/lib/RuntimeGlobals.js +21 -7
- package/lib/RuntimeModule.js +28 -12
- package/lib/RuntimePlugin.js +33 -3
- package/lib/RuntimeTemplate.js +1147 -847
- package/lib/SourceMapDevToolPlugin.js +54 -104
- package/lib/TemplatedPathPlugin.js +16 -59
- package/lib/Watching.js +9 -0
- package/lib/WebpackOptionsApply.js +84 -91
- package/lib/asset/AssetBytesGenerator.js +7 -1
- package/lib/asset/AssetGenerator.js +50 -24
- package/lib/asset/AssetModule.js +3 -0
- package/lib/asset/AssetSourceGenerator.js +7 -1
- package/lib/asset/WebManifestParser.js +7 -5
- package/lib/async-modules/AsyncModuleHelpers.js +10 -4
- package/lib/buildChunkGraph.js +11 -15
- package/lib/cache/AddBuildDependenciesPlugin.js +33 -4
- package/lib/cache/IdleFileCachePlugin.js +2 -2
- package/lib/cache/MemoryCachePlugin.js +4 -4
- package/lib/cache/MemoryWithGcCachePlugin.js +7 -8
- package/lib/cache/PackFileCacheStrategy.js +17 -19
- package/lib/cache/getLazyHashedEtag.js +3 -5
- package/lib/config/browserslistTargetHandler.js +17 -4
- package/lib/config/defaults.js +162 -142
- package/lib/config/getClaimedAssetTypes.js +10 -11
- package/lib/config/normalization.js +100 -20
- package/lib/config/target.js +13 -4
- package/lib/container/ContainerReferencePlugin.js +6 -0
- package/lib/container/RemoteRuntimeModule.js +9 -0
- package/lib/container/declaredRemotes.js +39 -0
- package/lib/{ContextExclusionPlugin.js → context/ContextExclusionPlugin.js} +1 -1
- package/lib/{ContextModule.js → context/ContextModule.js} +54 -115
- package/lib/{ContextModuleFactory.js → context/ContextModuleFactory.js} +19 -21
- package/lib/{ContextReplacementPlugin.js → context/ContextReplacementPlugin.js} +4 -4
- package/lib/css/CssGenerator.js +27 -11
- package/lib/css/CssInjectStyleRuntimeModule.js +9 -0
- package/lib/css/CssLoadingRuntimeModule.js +92 -15
- package/lib/css/CssModule.js +1 -1
- package/lib/css/CssModulesPlugin.js +3 -10
- package/lib/css/CssParser.js +162 -31
- package/lib/css/CssServerStylesRuntimeModule.js +9 -0
- package/lib/css/cssMinify.js +43 -32
- package/lib/css/data.js +3526 -871
- package/lib/css/syntax.js +6455 -1237
- package/lib/debug/ProfilingPlugin.js +7 -4
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +6 -3
- package/lib/dependencies/AMDRuntimeModules.js +18 -0
- package/lib/dependencies/CommonJsExportRequireDependency.js +13 -12
- package/lib/dependencies/CommonJsExportsParserPlugin.js +12 -13
- package/lib/dependencies/CommonJsImportsParserPlugin.js +5 -5
- package/lib/dependencies/CommonJsPlugin.js +19 -3
- package/lib/dependencies/CommonJsRequireDependency.js +32 -9
- package/lib/dependencies/CommonJsSelfReferenceDependency.js +2 -4
- package/lib/dependencies/ContextDependency.js +1 -1
- package/lib/dependencies/ContextDependencyHelpers.js +3 -9
- package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +20 -7
- package/lib/dependencies/ContextElementDependency.js +1 -1
- package/lib/dependencies/CssIcssExportDependency.js +13 -9
- package/lib/dependencies/CssIcssImportDependency.js +3 -6
- package/lib/dependencies/CssUrlDependency.js +3 -5
- package/lib/dependencies/HarmonyCompatibilityDependency.js +67 -22
- package/lib/dependencies/HarmonyDetectionParserPlugin.js +3 -4
- package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +10 -4
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +12 -7
- package/lib/dependencies/HarmonyExportExpressionDependency.js +47 -33
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +217 -34
- package/lib/dependencies/HarmonyExportInitFragment.js +110 -23
- package/lib/dependencies/HarmonyExportSpecifierDependency.js +25 -58
- package/lib/dependencies/HarmonyImportBareSideEffectDependency.js +59 -0
- package/lib/dependencies/HarmonyImportDependency.js +99 -41
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +198 -25
- package/lib/dependencies/HarmonyImportSideEffectDependency.js +117 -4
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +40 -3
- package/lib/dependencies/HarmonyModulesPlugin.js +20 -0
- package/lib/dependencies/HtmlEntryDependency.js +136 -104
- package/lib/dependencies/HtmlInlineScriptDependency.js +3 -4
- package/lib/dependencies/HtmlInlineStyleDependency.js +3 -4
- package/lib/dependencies/ImportContextDependency.js +43 -3
- package/lib/dependencies/ImportDependency.js +8 -29
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +1 -1
- package/lib/dependencies/ImportMetaGlobHelpers.js +1 -1
- package/lib/dependencies/ImportMetaMainDependency.js +104 -0
- package/lib/dependencies/ImportMetaPlugin.js +67 -25
- package/lib/dependencies/ImportParserPlugin.js +25 -15
- package/lib/dependencies/LoaderPlugin.js +26 -1
- package/lib/dependencies/RequireContextDependencyParserPlugin.js +1 -1
- package/lib/dependencies/RequireHeaderDependency.js +20 -21
- package/lib/dependencies/SystemRuntimeModule.js +9 -0
- package/lib/dependencies/URLContextDependency.js +1 -1
- package/lib/dependencies/URLDependency.js +6 -5
- package/lib/dependencies/WorkerAndWorkletPlugin.js +16 -21
- package/lib/dependencies/WorkerDependency.js +12 -18
- package/lib/dependencies/WorkletDependency.js +12 -20
- package/lib/dependencies/importOptionsCheck.js +47 -0
- package/lib/dll/DelegatedModule.js +18 -1
- package/lib/dll/DllReferencePlugin.js +11 -8
- package/lib/dll/LibManifestPlugin.js +1 -1
- package/lib/errors/AnalyzableBailoutsWarning.js +41 -0
- package/lib/errors/DotenvFileError.js +29 -0
- package/lib/errors/DuplicateModulesWarning.js +12 -7
- package/lib/errors/EmptyCopyPatternWarning.js +26 -0
- package/lib/errors/ExternalStarReexportError.js +44 -0
- package/lib/errors/HookWebpackError.js +3 -2
- package/lib/errors/ImportedBindingAssignmentError.js +30 -0
- package/lib/errors/MissingSourceMapsWarning.js +36 -0
- package/lib/errors/ModuleParseError.js +2 -1
- package/lib/errors/UnusedAssetsWarning.js +36 -0
- package/lib/errors/UnusedFederationWarning.js +35 -0
- package/lib/errors/UnusedModulesWarning.js +38 -0
- package/lib/esm/ExportWebpackRequireRuntimeModule.js +9 -0
- package/lib/esm/ModuleChunkFormatPlugin.js +28 -3
- package/lib/esm/ModuleChunkLoadingPlugin.js +21 -5
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +91 -53
- package/lib/hmr/HotModuleReplacement.runtime.js +8 -2
- package/lib/hmr/HotModuleReplacementRuntimeModule.js +9 -0
- package/lib/hmr/LazyCompilationPlugin.js +3 -5
- package/lib/html/HtmlGenerator.js +72 -87
- package/lib/html/HtmlModulesPlugin.js +479 -215
- package/lib/html/HtmlParser.js +110 -147
- package/lib/html/builtinEmbeddedRenderer.js +107 -0
- package/lib/html/data.js +142 -7
- package/lib/html/htmlMinify.js +92 -122
- package/lib/html/syntax.js +2031 -1556
- package/lib/ids/HashedModuleIdsPlugin.js +2 -1
- package/lib/index.js +49 -3
- package/lib/javascript/ChunkFormatHelpers.js +4 -3
- package/lib/javascript/JavascriptGenerator.js +8 -1
- package/lib/javascript/JavascriptModule.js +1 -0
- package/lib/javascript/JavascriptModulesPlugin.js +76 -80
- package/lib/javascript/JavascriptParser.js +1970 -900
- package/lib/javascript/StartupHelpers.js +27 -3
- package/lib/javascript/data.js +172 -0
- package/lib/javascript/grammar.js +5546 -0
- package/lib/javascript/parser.js +1500 -0
- package/lib/javascript/regexp.js +1762 -0
- package/lib/javascript/regexpData.js +51 -0
- package/lib/javascript/syntax.js +9061 -5262
- package/lib/json/JsonGenerator.js +7 -1
- package/lib/library/ModuleLibraryPlugin.js +171 -132
- package/lib/loaders/LoaderRunner.js +170 -14
- package/lib/node/NodeWatchFileSystem.js +3 -9
- package/lib/node/ReadFileChunkLoadingRuntimeModule.js +22 -0
- package/lib/node/ReadFileCompileAsyncWasmPlugin.js +8 -15
- package/lib/node/RequireChunkLoadingRuntimeModule.js +22 -0
- package/lib/optimize/AggressiveMergingPlugin.js +3 -5
- package/lib/optimize/ConcatenatedModule.js +222 -125
- package/lib/optimize/ConstExportsPlugin.js +50 -34
- package/lib/optimize/FlagIncludedChunksPlugin.js +3 -11
- package/lib/optimize/InlineExports.js +20 -2
- package/lib/optimize/InnerGraphPlugin.js +7 -13
- package/lib/optimize/LimitChunkCountPlugin.js +5 -8
- package/lib/optimize/MangleExportsPlugin.js +13 -4
- package/lib/optimize/ModuleConcatenationPlugin.js +27 -5
- package/lib/optimize/RealContentHashPlugin.js +179 -44
- package/lib/optimize/SideEffectsFlagPlugin.js +24 -28
- package/lib/optimize/SplitChunksPlugin.js +2 -4
- package/lib/performance/AnalyzableBailoutsPlugin.js +115 -0
- package/lib/performance/BroadContextsPlugin.js +1 -1
- package/lib/performance/CacheEffectivenessPlugin.js +7 -7
- package/lib/performance/DuplicateModulesPlugin.js +57 -13
- package/lib/performance/EvalUsagePlugin.js +5 -2
- package/lib/performance/MissingSourceMapsPlugin.js +115 -0
- package/lib/performance/PureAnnotationsPlugin.js +6 -3
- package/lib/performance/SizeLimitsPlugin.js +2 -4
- package/lib/performance/TopLevelThisPlugin.js +5 -4
- package/lib/performance/UnusedAssetsPlugin.js +109 -0
- package/lib/performance/UnusedFederationPlugin.js +147 -0
- package/lib/performance/UnusedModulesPlugin.js +141 -0
- package/lib/performance/UnusedReexportsPlugin.js +1 -55
- package/lib/performance/isOnlyReexported.js +65 -0
- package/lib/prefetch/ChunkPrefetchFunctionRuntimeModule.js +25 -5
- package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +8 -8
- package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +9 -0
- package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +9 -0
- package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +9 -0
- package/lib/prefetch/ResourceHintPlugin.js +29 -35
- package/lib/prefetch/ResourceHintRuntimeModule.js +9 -0
- package/lib/prefetch/StartupAssetHintRuntimeModule.js +16 -10
- package/lib/rules/RuleSetCompiler.js +211 -4
- package/lib/runtime/AsyncModuleRuntimeModule.js +103 -67
- package/lib/runtime/AutoPublicPathRuntimeModule.js +9 -0
- package/lib/runtime/BaseUriRuntimeModule.js +9 -0
- package/lib/runtime/ChunkNameRuntimeModule.js +9 -0
- package/lib/runtime/EnsureChunkRuntimeModule.js +35 -16
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +12 -4
- package/lib/runtime/GetFullHashRuntimeModule.js +9 -0
- package/lib/runtime/GetMainFilenameRuntimeModule.js +9 -0
- package/lib/runtime/GetWorkletBootstrapRuntimeModule.js +9 -0
- package/lib/runtime/GlobalRuntimeModule.js +11 -4
- package/lib/runtime/HasOwnPropertyRuntimeModule.js +9 -0
- package/lib/runtime/HelperRuntimeModule.js +10 -0
- package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +313 -222
- package/lib/runtime/NonceRuntimeModule.js +9 -0
- package/lib/runtime/OnChunksLoadedRuntimeModule.js +67 -20
- package/lib/runtime/PublicPathRuntimeModule.js +9 -0
- package/lib/runtime/RuntimeIdRuntimeModule.js +9 -0
- package/lib/runtime/SpecNamespaceObjectRuntimeModule.js +90 -0
- package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +9 -0
- package/lib/runtime/StartupEntrypointRuntimeModule.js +9 -0
- package/lib/runtime/SystemContextRuntimeModule.js +9 -0
- package/lib/runtime/ToBinaryRuntimeModule.js +9 -0
- package/lib/schemes/DataUriPlugin.js +3 -6
- package/lib/schemes/HttpUriPlugin.js +22 -5
- package/lib/schemes/VirtualUrlPlugin.js +1 -1
- package/lib/serialization/BinaryMiddleware.js +9 -9
- package/lib/serialization/FileMiddleware.js +31 -18
- package/lib/serialization/ObjectMiddleware.js +168 -139
- package/lib/sharing/ConsumeSharedPlugin.js +12 -0
- package/lib/sharing/ConsumeSharedRuntimeModule.js +11 -0
- package/lib/sharing/ShareRuntimeModule.js +9 -0
- package/lib/sharing/declaredShared.js +47 -0
- package/lib/stats/DefaultStatsFactoryPlugin.js +6 -5
- package/lib/stats/DefaultStatsPrinterPlugin.js +3 -0
- package/lib/typescript/TypeScriptPlugin.js +10 -13
- package/lib/url/URLParserPlugin.js +6 -8
- package/lib/util/ArrayQueue.js +3 -3
- package/lib/util/LocConverter.js +4 -7
- package/lib/util/SourceProcessor.js +115 -99
- package/lib/util/URLAbsoluteSpecifier.js +3 -1
- package/lib/util/async.js +292 -0
- package/lib/util/buildDiagnostics.js +69 -0
- package/lib/util/chainedImports.js +3 -4
- package/lib/util/concatenate.js +4 -4
- package/lib/util/conventions.js +5 -1
- package/lib/util/createHooksRegistry.js +1 -2
- package/lib/util/createMappings.js +25 -3
- package/lib/util/dataURL.js +2 -3
- package/lib/util/deterministicGrouping.js +8 -13
- package/lib/util/findGraphRoots.js +6 -13
- package/lib/util/fs.js +27 -1
- package/lib/util/globUtils.js +1 -1
- package/lib/util/handlerKeys.js +40 -0
- package/lib/util/hash/wasm-hash.js +3 -4
- package/lib/util/identifier.js +20 -0
- package/lib/util/internalSerializables.js +7 -1
- package/lib/util/registerExternalSerializer.js +6 -45
- package/lib/util/removeBOM.js +82 -1
- package/lib/util/semver.js +5 -3
- package/lib/wasm-async/AsyncWasmCompileRuntimeModule.js +14 -3
- package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +14 -3
- package/lib/wasm-async/AsyncWebAssemblyGenerator.js +6 -1
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +5 -1
- package/lib/wasm-async/UniversalCompileAsyncWasmPlugin.js +7 -12
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +12 -4
- package/lib/wasm-sync/WebAssemblyGenerator.js +6 -1
- package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +5 -1
- package/lib/wasm-sync/WebAssemblyUtils.js +2 -4
- package/lib/web/FetchCompileAsyncWasmPlugin.js +10 -6
- package/lib/web/FetchCompileWasmPlugin.js +4 -2
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +36 -0
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +19 -0
- package/package.json +55 -46
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +388 -76
- package/schemas/plugins/LoaderOptionsPlugin.check.js +1 -1
- package/schemas/plugins/ManifestPlugin.check.js +1 -1
- package/schemas/plugins/SourceMapDevToolPlugin.check.js +1 -1
- package/schemas/plugins/asset/AssetGeneratorOptions.check.js +1 -1
- package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.js +1 -1
- package/schemas/plugins/container/ContainerPlugin.check.js +1 -1
- package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
- package/schemas/plugins/debug/ProfilingPlugin.check.js +1 -1
- package/schemas/plugins/dll/DllReferencePlugin.check.js +1 -1
- package/schemas/plugins/ids/HashedModuleIdsPlugin.check.js +1 -1
- package/schemas/plugins/schemes/HttpUriPlugin.check.js +1 -1
- package/types.d.ts +1795 -608
- package/lib/dependencies/ExportBindingInitFragment.js +0 -191
- package/lib/errors/EntrypointOverlapWarning.js +0 -45
- package/lib/performance/EntrypointOverlapPlugin.js +0 -122
|
@@ -78,7 +78,6 @@ class ModuleChunkLoadingPlugin {
|
|
|
78
78
|
RuntimeGlobals.ensureChunkHandlers,
|
|
79
79
|
RuntimeGlobals.baseURI,
|
|
80
80
|
RuntimeGlobals.externalInstallChunk,
|
|
81
|
-
RuntimeGlobals.analyzableChunkImport,
|
|
82
81
|
RuntimeGlobals.onChunksLoaded,
|
|
83
82
|
RuntimeGlobals.hmrDownloadUpdateHandlers,
|
|
84
83
|
RuntimeGlobals.hmrDownloadManifest
|
|
@@ -90,7 +89,6 @@ class ModuleChunkLoadingPlugin {
|
|
|
90
89
|
for (const requirement of [
|
|
91
90
|
RuntimeGlobals.ensureChunkHandlers,
|
|
92
91
|
RuntimeGlobals.externalInstallChunk,
|
|
93
|
-
RuntimeGlobals.analyzableChunkImport,
|
|
94
92
|
RuntimeGlobals.hmrDownloadUpdateHandlers
|
|
95
93
|
]) {
|
|
96
94
|
compilation.hooks.runtimeRequirementInTree
|
|
@@ -135,11 +133,29 @@ class ModuleChunkLoadingPlugin {
|
|
|
135
133
|
}
|
|
136
134
|
|
|
137
135
|
// Keyed on `ensureChunk`, not on the handler map: only the runtime chunk loader
|
|
138
|
-
// builds a URL from a chunk id, and
|
|
136
|
+
// builds a URL from a chunk id, and a baked specifier carries its own.
|
|
139
137
|
compilation.hooks.runtimeRequirementInTree
|
|
140
138
|
.for(RuntimeGlobals.ensureChunk)
|
|
141
|
-
.tap(PLUGIN_NAME, (chunk, set) => {
|
|
142
|
-
if (!isEnabledForChunk(chunk))
|
|
139
|
+
.tap(PLUGIN_NAME, (chunk, set, { chunkGraph }) => {
|
|
140
|
+
if (!isEnabledForChunk(chunk)) {
|
|
141
|
+
compilation.runtimeTemplate.reportChunkImportBailout(
|
|
142
|
+
chunk,
|
|
143
|
+
chunkGraph
|
|
144
|
+
);
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// Asked as the runtime module asks, so the two always agree on whether
|
|
149
|
+
// a chunk id is ever turned into a url here.
|
|
150
|
+
const { runtimeTemplate } = compilation;
|
|
151
|
+
if (
|
|
152
|
+
runtimeTemplate.analyzableChunkImports(chunk, chunkGraph, set) !==
|
|
153
|
+
null &&
|
|
154
|
+
!set.has(RuntimeGlobals.hmrDownloadUpdateHandlers) &&
|
|
155
|
+
!runtimeTemplate.chunkImportsNeedRuntimeUrl(chunk, chunkGraph)
|
|
156
|
+
) {
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
143
159
|
|
|
144
160
|
if (compilation.outputOptions.publicPath !== "auto") {
|
|
145
161
|
set.add(RuntimeGlobals.publicPath);
|
|
@@ -17,6 +17,7 @@ const { getInitialChunkIds } = require("../javascript/StartupHelpers");
|
|
|
17
17
|
const { renderBaseUri } = require("../runtime/baseUri");
|
|
18
18
|
const compileBooleanMatcher = require("../util/compileBooleanMatcher");
|
|
19
19
|
const createHooksRegistry = require("../util/createHooksRegistry");
|
|
20
|
+
const { RESOLVABLE_SPECIFIER_REGEXP } = require("../util/identifier");
|
|
20
21
|
const memoize = require("../util/memoize");
|
|
21
22
|
|
|
22
23
|
const getAPIPlugin = memoize(() => require("../APIPlugin"));
|
|
@@ -53,6 +54,54 @@ class ModuleChunkLoadingRuntimeModule extends RuntimeModule {
|
|
|
53
54
|
this._runtimeRequirements = runtimeRequirements;
|
|
54
55
|
}
|
|
55
56
|
|
|
57
|
+
/**
|
|
58
|
+
* The `[handlerMap, key]` pairs this module installs onto a chunk handler map
|
|
59
|
+
* such as `__webpack_require__.f`, or `null` where it cannot name them.
|
|
60
|
+
* @returns {[string, string][] | null} installed chunk handlers (do not mutate)
|
|
61
|
+
*/
|
|
62
|
+
getInstalledChunkHandlers() {
|
|
63
|
+
const compilation = /** @type {Compilation} */ (this.compilation);
|
|
64
|
+
const chunkGraph = /** @type {ChunkGraph} */ (this.chunkGraph);
|
|
65
|
+
const chunk = /** @type {Chunk} */ (this.chunk);
|
|
66
|
+
const runtimeRequirements = this._runtimeRequirements;
|
|
67
|
+
const withHmr = runtimeRequirements.has(
|
|
68
|
+
RuntimeGlobals.hmrDownloadUpdateHandlers
|
|
69
|
+
);
|
|
70
|
+
const withHint =
|
|
71
|
+
compilation.outputOptions.environment.document ||
|
|
72
|
+
compilation.runtimeTemplate.isNeutralPlatform();
|
|
73
|
+
/** @type {[string, string][]} */
|
|
74
|
+
const handlers = [];
|
|
75
|
+
if (
|
|
76
|
+
runtimeRequirements.has(RuntimeGlobals.ensureChunkHandlers) &&
|
|
77
|
+
(runtimeRequirements.has(RuntimeGlobals.ensureChunk) || withHmr)
|
|
78
|
+
) {
|
|
79
|
+
handlers.push([RuntimeGlobals.ensureChunkHandlers, "j"]);
|
|
80
|
+
}
|
|
81
|
+
// The hot update flow installs this one onto the same map while it runs.
|
|
82
|
+
if (withHmr) {
|
|
83
|
+
handlers.push([RuntimeGlobals.ensureChunkHandlers, "moduleHmr"]);
|
|
84
|
+
}
|
|
85
|
+
if (
|
|
86
|
+
withHint &&
|
|
87
|
+
runtimeRequirements.has(RuntimeGlobals.prefetchChunkHandlers) &&
|
|
88
|
+
chunk.hasChildByOrder(chunkGraph, "prefetch", true, chunkHasJs)
|
|
89
|
+
) {
|
|
90
|
+
handlers.push([RuntimeGlobals.prefetchChunkHandlers, "j"]);
|
|
91
|
+
}
|
|
92
|
+
if (
|
|
93
|
+
withHint &&
|
|
94
|
+
runtimeRequirements.has(RuntimeGlobals.preloadChunkHandlers) &&
|
|
95
|
+
chunk.hasChildByOrder(chunkGraph, "preload", true, chunkHasJs)
|
|
96
|
+
) {
|
|
97
|
+
handlers.push([RuntimeGlobals.preloadChunkHandlers, "j"]);
|
|
98
|
+
}
|
|
99
|
+
if (runtimeRequirements.has(RuntimeGlobals.onChunksLoaded)) {
|
|
100
|
+
handlers.push([RuntimeGlobals.onChunksLoaded, "j"]);
|
|
101
|
+
}
|
|
102
|
+
return handlers;
|
|
103
|
+
}
|
|
104
|
+
|
|
56
105
|
/**
|
|
57
106
|
* Returns generated code.
|
|
58
107
|
* @private
|
|
@@ -96,9 +145,6 @@ class ModuleChunkLoadingRuntimeModule extends RuntimeModule {
|
|
|
96
145
|
const withExternalInstallChunk = this._runtimeRequirements.has(
|
|
97
146
|
RuntimeGlobals.externalInstallChunk
|
|
98
147
|
);
|
|
99
|
-
const withAnalyzableImport = this._runtimeRequirements.has(
|
|
100
|
-
RuntimeGlobals.analyzableChunkImport
|
|
101
|
-
);
|
|
102
148
|
const withLoading = this._runtimeRequirements.has(
|
|
103
149
|
RuntimeGlobals.ensureChunkHandlers
|
|
104
150
|
);
|
|
@@ -111,8 +157,8 @@ class ModuleChunkLoadingRuntimeModule extends RuntimeModule {
|
|
|
111
157
|
const withHmrManifest = this._runtimeRequirements.has(
|
|
112
158
|
RuntimeGlobals.hmrDownloadManifest
|
|
113
159
|
);
|
|
114
|
-
// `.f.j` serves `ensureChunk
|
|
115
|
-
//
|
|
160
|
+
// `.f.j` serves `ensureChunk`. HMR's force-load knows only a chunk id, so it
|
|
161
|
+
// needs the loader too.
|
|
116
162
|
const withJsLoading =
|
|
117
163
|
withLoading &&
|
|
118
164
|
(this._runtimeRequirements.has(RuntimeGlobals.ensureChunk) || withHmr);
|
|
@@ -138,6 +184,16 @@ class ModuleChunkLoadingRuntimeModule extends RuntimeModule {
|
|
|
138
184
|
this
|
|
139
185
|
)
|
|
140
186
|
: null;
|
|
187
|
+
// Under module output every chunk the loader reaches is a known file, so it
|
|
188
|
+
// imports a literal specifier read by id instead of a url built from that id.
|
|
189
|
+
const chunkImports = withJsLoading
|
|
190
|
+
? runtimeTemplate.analyzableChunkImports(
|
|
191
|
+
chunk,
|
|
192
|
+
chunkGraph,
|
|
193
|
+
this._runtimeRequirements,
|
|
194
|
+
this
|
|
195
|
+
)
|
|
196
|
+
: null;
|
|
141
197
|
const conditionMap = chunkGraph.getChunkConditionMap(chunk, chunkHasJs);
|
|
142
198
|
const hasJsMatcher = compileBooleanMatcher(conditionMap);
|
|
143
199
|
const initialChunkIds = getInitialChunkIds(chunk, chunkGraph, chunkHasJs);
|
|
@@ -152,7 +208,7 @@ class ModuleChunkLoadingRuntimeModule extends RuntimeModule {
|
|
|
152
208
|
publicPath === "auto"
|
|
153
209
|
? JSON.stringify(rootOutputDir)
|
|
154
210
|
: typeof publicPath === "string" &&
|
|
155
|
-
|
|
211
|
+
!RESOLVABLE_SPECIFIER_REGEXP.test(publicPath) &&
|
|
156
212
|
!getAPIPlugin().usesRuntimePublicPathOverride(compilation)
|
|
157
213
|
? `"./" + ${RuntimeGlobals.publicPath}`
|
|
158
214
|
: RuntimeGlobals.publicPath;
|
|
@@ -173,7 +229,6 @@ class ModuleChunkLoadingRuntimeModule extends RuntimeModule {
|
|
|
173
229
|
const withInstalledChunks =
|
|
174
230
|
withLoading ||
|
|
175
231
|
withExternalInstallChunk ||
|
|
176
|
-
withAnalyzableImport ||
|
|
177
232
|
withOnChunkLoad ||
|
|
178
233
|
withHmr ||
|
|
179
234
|
withPrefetch ||
|
|
@@ -188,6 +243,19 @@ class ModuleChunkLoadingRuntimeModule extends RuntimeModule {
|
|
|
188
243
|
chunkUrls === null
|
|
189
244
|
? `${RuntimeGlobals.publicPath} + ${RuntimeGlobals.getChunkScriptFilename}(${id})`
|
|
190
245
|
: `chunkUrls[${id}]()`;
|
|
246
|
+
const runtimeImport = `${importFunctionName}(${chunkImportBase} + ${RuntimeGlobals.getChunkScriptFilename}(chunkId))`;
|
|
247
|
+
// A hot update can force-load an id this build never saw, and a chunk with a
|
|
248
|
+
// runtime of its own is never named, so only those keep the url form.
|
|
249
|
+
const withRuntimeUrl =
|
|
250
|
+
chunkImports === null ||
|
|
251
|
+
withHmr ||
|
|
252
|
+
runtimeTemplate.chunkImportsNeedRuntimeUrl(chunk, chunkGraph);
|
|
253
|
+
const chunkImport =
|
|
254
|
+
chunkImports === null
|
|
255
|
+
? runtimeImport
|
|
256
|
+
: withRuntimeUrl
|
|
257
|
+
? `(${RuntimeGlobals.hasOwnProperty}(chunkImports, chunkId) ? chunkImports[chunkId]() : ${runtimeImport})`
|
|
258
|
+
: "chunkImports[chunkId]()";
|
|
191
259
|
return Template.asString([
|
|
192
260
|
withBaseURI
|
|
193
261
|
? this._generateBaseUri(chunk, rootOutputDir)
|
|
@@ -205,6 +273,20 @@ class ModuleChunkLoadingRuntimeModule extends RuntimeModule {
|
|
|
205
273
|
""
|
|
206
274
|
]
|
|
207
275
|
: []),
|
|
276
|
+
...(chunkImports
|
|
277
|
+
? [
|
|
278
|
+
`${cst} chunkImports = {\n${Template.indent(
|
|
279
|
+
Array.from(
|
|
280
|
+
chunkImports,
|
|
281
|
+
([id, specifier]) =>
|
|
282
|
+
`${JSON.stringify(String(id))}: ${runtimeTemplate.returningFunction(
|
|
283
|
+
`${importFunctionName}(${specifier})`
|
|
284
|
+
)}`
|
|
285
|
+
).join(",\n")
|
|
286
|
+
)}\n};`,
|
|
287
|
+
""
|
|
288
|
+
]
|
|
289
|
+
: []),
|
|
208
290
|
withInstalledChunks
|
|
209
291
|
? Template.asString([
|
|
210
292
|
"// object to store loaded and loading chunks",
|
|
@@ -221,7 +303,7 @@ class ModuleChunkLoadingRuntimeModule extends RuntimeModule {
|
|
|
221
303
|
])
|
|
222
304
|
: "// no installed chunks",
|
|
223
305
|
"",
|
|
224
|
-
withLoading || withExternalInstallChunk
|
|
306
|
+
withLoading || withExternalInstallChunk
|
|
225
307
|
? `${cst} installChunk = ${runtimeTemplate.basicFunction("data", [
|
|
226
308
|
runtimeTemplate.destructureObject(
|
|
227
309
|
[
|
|
@@ -280,9 +362,7 @@ class ModuleChunkLoadingRuntimeModule extends RuntimeModule {
|
|
|
280
362
|
: `if(${hasJsMatcher("chunkId")}) {`,
|
|
281
363
|
Template.indent([
|
|
282
364
|
"// setup Promise in chunk cache",
|
|
283
|
-
`${lt} promise = ${
|
|
284
|
-
RuntimeGlobals.getChunkScriptFilename
|
|
285
|
-
}(chunkId)).then(installChunk, ${runtimeTemplate.basicFunction(
|
|
365
|
+
`${lt} promise = ${chunkImport}.then(installChunk, ${runtimeTemplate.basicFunction(
|
|
286
366
|
"e",
|
|
287
367
|
[
|
|
288
368
|
"if(installedChunks[chunkId] !== 0) installedChunks[chunkId] = undefined;",
|
|
@@ -422,48 +502,6 @@ class ModuleChunkLoadingRuntimeModule extends RuntimeModule {
|
|
|
422
502
|
])
|
|
423
503
|
: "// no external install chunk",
|
|
424
504
|
"",
|
|
425
|
-
withAnalyzableImport
|
|
426
|
-
? `${
|
|
427
|
-
RuntimeGlobals.analyzableChunkImport
|
|
428
|
-
} = ${runtimeTemplate.basicFunction("chunkId, importFn", [
|
|
429
|
-
// `ensureChunk` with its `.j` half replaced by a literal `import()` a foreign
|
|
430
|
-
// bundler can follow. The remaining handlers still run, so a chunk's css and
|
|
431
|
-
// its prefetch/preload children are not lost by taking this path.
|
|
432
|
-
`${lt} promises = [];`,
|
|
433
|
-
`${lt} installedChunkData = ${RuntimeGlobals.hasOwnProperty}(installedChunks, chunkId) ? installedChunks[chunkId] : undefined;`,
|
|
434
|
-
'if(installedChunkData !== 0) { // 0 means "already installed".',
|
|
435
|
-
Template.indent([
|
|
436
|
-
'// a Promise means "currently loading".',
|
|
437
|
-
"if(installedChunkData) {",
|
|
438
|
-
Template.indent(["promises.push(installedChunkData[1]);"]),
|
|
439
|
-
"} else {",
|
|
440
|
-
Template.indent([
|
|
441
|
-
`${lt} promise = importFn().then(installChunk, ${runtimeTemplate.basicFunction(
|
|
442
|
-
"e",
|
|
443
|
-
[
|
|
444
|
-
"if(installedChunks[chunkId] !== 0) installedChunks[chunkId] = undefined;",
|
|
445
|
-
"throw e;"
|
|
446
|
-
]
|
|
447
|
-
)});`,
|
|
448
|
-
`promise = Promise.race([promise, new Promise(${runtimeTemplate.expressionFunction(
|
|
449
|
-
"installedChunkData = installedChunks[chunkId] = [resolve]",
|
|
450
|
-
"resolve"
|
|
451
|
-
)})]);`,
|
|
452
|
-
"promises.push((installedChunkData[1] = promise));"
|
|
453
|
-
]),
|
|
454
|
-
"}"
|
|
455
|
-
]),
|
|
456
|
-
"}",
|
|
457
|
-
withLoading
|
|
458
|
-
? `Object.keys(${fn}).forEach(${runtimeTemplate.basicFunction(
|
|
459
|
-
"key",
|
|
460
|
-
[`if(key !== "j") ${fn}[key](chunkId, promises);`]
|
|
461
|
-
)});`
|
|
462
|
-
: "// no other chunk loading handlers",
|
|
463
|
-
"return Promise.all(promises);"
|
|
464
|
-
])};`
|
|
465
|
-
: "// no analyzable chunk import",
|
|
466
|
-
"",
|
|
467
505
|
withOnChunkLoad
|
|
468
506
|
? `${
|
|
469
507
|
RuntimeGlobals.onChunksLoaded
|
|
@@ -26,14 +26,20 @@
|
|
|
26
26
|
|
|
27
27
|
/** @typedef {(options: ApplyOptions) => ApplyResult} ApplyHandler */
|
|
28
28
|
/** @typedef {(moduleId: ModuleId, applyHandlers: ApplyHandler[]) => void} InvalidateModuleHandler */
|
|
29
|
-
/**
|
|
29
|
+
/**
|
|
30
|
+
* @typedef {object} CssUpdateManifest
|
|
31
|
+
* @property {ModuleId[]} r updated chunk ids that no longer have a stylesheet
|
|
32
|
+
* @property {Record<string, string>=} n the stylesheet name of each updated chunk whose name moved with its content
|
|
33
|
+
*/
|
|
34
|
+
|
|
35
|
+
/** @typedef {(chunkIds: ModuleId[], removedChunks: ModuleId[], removedModules: ModuleId[], promises: Promise<unknown>[], applyHandlers: ApplyHandler[], updatedModulesList: ModuleId[], css: CssUpdateManifest | undefined, forceLoadChunks: ModuleId[] | undefined) => void} DownloadUpdateHandler */
|
|
30
36
|
|
|
31
37
|
/**
|
|
32
38
|
* @typedef {object} HMRManifest
|
|
33
39
|
* @property {ModuleId[]} c updated chunk ids
|
|
34
40
|
* @property {ModuleId[]} r removed chunk ids
|
|
35
41
|
* @property {ModuleId[]} m removed module ids
|
|
36
|
-
* @property {
|
|
42
|
+
* @property {CssUpdateManifest=} css what the stylesheet loader needs to know about the update
|
|
37
43
|
* @property {ModuleId[]=} f chunk ids to force-load
|
|
38
44
|
*/
|
|
39
45
|
|
|
@@ -16,6 +16,15 @@ class HotModuleReplacementRuntimeModule extends RuntimeModule {
|
|
|
16
16
|
super("hot module replacement", RuntimeModule.STAGE_BASIC);
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
+
/**
|
|
20
|
+
* The `[handlerMap, key]` pairs this module installs onto a chunk handler map
|
|
21
|
+
* such as `__webpack_require__.f`, or `null` where it cannot name them.
|
|
22
|
+
* @returns {[string, string][] | null} installed chunk handlers (do not mutate)
|
|
23
|
+
*/
|
|
24
|
+
getInstalledChunkHandlers() {
|
|
25
|
+
return RuntimeModule.NO_CHUNK_HANDLERS;
|
|
26
|
+
}
|
|
27
|
+
|
|
19
28
|
/**
|
|
20
29
|
* Generates runtime code for this runtime module.
|
|
21
30
|
* @returns {string | null} runtime code
|
|
@@ -335,11 +335,9 @@ class LazyCompilationProxyModule extends Module {
|
|
|
335
335
|
block.addDependency(dep);
|
|
336
336
|
this.addBlock(block);
|
|
337
337
|
} else if (hasClosureLibrary(compilation.options.output)) {
|
|
338
|
-
// Reserve statically
|
|
339
|
-
//
|
|
340
|
-
//
|
|
341
|
-
// Once the proxy activates and the lazily-built module references those
|
|
342
|
-
// externals, the identifiers resolve normally instead of throwing.
|
|
338
|
+
// Reserve the statically declared externals on the inactive proxy, so the
|
|
339
|
+
// entry chunk's library wrapper already exposes their closure identifiers
|
|
340
|
+
// and they resolve rather than throw once the proxy activates.
|
|
343
341
|
const requests = collectStaticExternalRequests(
|
|
344
342
|
options.externals,
|
|
345
343
|
this.layer
|
|
@@ -9,6 +9,7 @@ const ConcatenationScope = require("../ConcatenationScope");
|
|
|
9
9
|
const Generator = require("../Generator");
|
|
10
10
|
const {
|
|
11
11
|
HTML_TYPE,
|
|
12
|
+
HTML_TYPES,
|
|
12
13
|
JAVASCRIPT_TYPE,
|
|
13
14
|
JAVASCRIPT_TYPES
|
|
14
15
|
} = require("../ModuleSourceTypeConstants");
|
|
@@ -225,12 +226,9 @@ const CHUNK_URL_SENTINEL_REGEXP =
|
|
|
225
226
|
const HTML_PAGE_URL_SENTINEL_REGEXP =
|
|
226
227
|
/__WEBPACK_HTML_PAGE_URL__([0-9a-f]+)__END__/g;
|
|
227
228
|
|
|
228
|
-
// Sentinel for a URL-referenced asset
|
|
229
|
-
//
|
|
230
|
-
//
|
|
231
|
-
// HtmlEntry deps run *while* the HTML module is being codegen'd — the asset
|
|
232
|
-
// module's own codegen might not have completed yet. Keyed by the asset
|
|
233
|
-
// module's identifier, hex-encoded so any character in it is safe in a URL.
|
|
229
|
+
// Sentinel for a URL-referenced asset in a resource-hint `<link>`, resolved at
|
|
230
|
+
// `HtmlModulesPlugin` render because HtmlEntry deps run while the HTML module
|
|
231
|
+
// is codegen'd, before the asset's own. Keyed by hex-encoded identifier.
|
|
234
232
|
const ASSET_URL_SENTINEL_REGEXP =
|
|
235
233
|
/__WEBPACK_HTML_ASSET_URL__([0-9a-f]+)__END__/g;
|
|
236
234
|
|
|
@@ -239,11 +237,9 @@ const ASSET_URL_SENTINEL_REGEXP =
|
|
|
239
237
|
/** @type {WeakSet<Compilation>} */
|
|
240
238
|
const integritySentinelCompilations = new WeakSet();
|
|
241
239
|
|
|
242
|
-
// Matches the whole ` integrity="<sentinel>"
|
|
243
|
-
//
|
|
244
|
-
//
|
|
245
|
-
// optional and back-referenced to keep the pair matched; the replacement always
|
|
246
|
-
// re-quotes, since an SRI list carries spaces and `=` padding.
|
|
240
|
+
// Matches the whole ` integrity="<sentinel>"`, so the attribute can be dropped
|
|
241
|
+
// when the per-asset `integrity` returns `false`. Minification runs first and
|
|
242
|
+
// may have unquoted it, hence the optional back-referenced quote.
|
|
247
243
|
const INTEGRITY_SENTINEL_REGEXP =
|
|
248
244
|
/ integrity=(["']?)__WEBPACK_HTML_INTEGRITY__([0-9a-f]+)__([a-z]+)__END__\1/g;
|
|
249
245
|
|
|
@@ -252,10 +248,9 @@ const INTEGRITY_SENTINEL_REGEXP =
|
|
|
252
248
|
const INTEGRITY_SENTINEL_STRIP_REGEXP =
|
|
253
249
|
/ integrity=(\\?["']|)__WEBPACK_HTML_INTEGRITY__[0-9a-f]+__[a-z]+__END__\1/g;
|
|
254
250
|
|
|
255
|
-
// The trailing `(?:__<hash>)?` is the inlined chunk's content hash, embedded
|
|
256
|
-
//
|
|
257
|
-
//
|
|
258
|
-
// resolver ignores it.
|
|
251
|
+
// The trailing `(?:__<hash>)?` is the inlined chunk's content hash, embedded so
|
|
252
|
+
// the host page's bytes and `[contenthash]` change with the inlined content.
|
|
253
|
+
// The resolver ignores it.
|
|
259
254
|
const INLINE_SENTINEL_REGEXP =
|
|
260
255
|
/__WEBPACK_HTML_INLINE__([0-9a-f]+)__([a-z]+)(?:__[0-9a-f]+)?__END__/g;
|
|
261
256
|
|
|
@@ -448,12 +443,9 @@ class HtmlGenerator extends Generator {
|
|
|
448
443
|
const url =
|
|
449
444
|
/** @type {Record<string, string | undefined> | undefined} */
|
|
450
445
|
(data.get("url"));
|
|
451
|
-
// Prefer the `asset-url` channel
|
|
452
|
-
//
|
|
453
|
-
//
|
|
454
|
-
// `__webpack_require__.p + "…"`); for those we reconstruct the URL
|
|
455
|
-
// from the emitted `filename` + `PUBLIC_PATH_AUTO` so the same
|
|
456
|
-
// undo-path substitution runs at asset render.
|
|
446
|
+
// Prefer the `asset-url` channel, which is the real URL string. An asset
|
|
447
|
+
// reached only from JS has none — its URL is a JS expression — so rebuild
|
|
448
|
+
// one from `filename` and let the undo-path substitution run.
|
|
457
449
|
if (url && url["asset-url"]) return url["asset-url"];
|
|
458
450
|
const filename = /** @type {string | undefined} */ (data.get("filename"));
|
|
459
451
|
if (filename) return `${PUBLIC_PATH_AUTO}${filename}`;
|
|
@@ -692,10 +684,9 @@ class HtmlGenerator extends Generator {
|
|
|
692
684
|
bodyDepth++;
|
|
693
685
|
}
|
|
694
686
|
},
|
|
695
|
-
// Collected on exit
|
|
696
|
-
// closes
|
|
697
|
-
//
|
|
698
|
-
// exiting keeps them in source order.
|
|
687
|
+
// Collected on exit, since an element's `end` is final only once it
|
|
688
|
+
// closes. `script`, `style`, `link` and `meta` never nest in each
|
|
689
|
+
// other, so exiting keeps them in source order.
|
|
699
690
|
exit: (path) => {
|
|
700
691
|
const name = path.tagName();
|
|
701
692
|
if (name === "head") {
|
|
@@ -1047,19 +1038,19 @@ class HtmlGenerator extends Generator {
|
|
|
1047
1038
|
* Creates an instance of HtmlGenerator.
|
|
1048
1039
|
* @param {HtmlGeneratorOptions=} options generator options
|
|
1049
1040
|
* @param {ModuleGraph=} moduleGraph the module graph; used to detect when an HTML module is reached as a compilation entry so `extract` can default to `true` for it
|
|
1041
|
+
* @param {((module: NormalModule) => boolean)=} isPageOnly tells whether the module's only output is its emitted page, so it exposes no JavaScript
|
|
1050
1042
|
*/
|
|
1051
|
-
constructor(options, moduleGraph) {
|
|
1043
|
+
constructor(options, moduleGraph, isPageOnly) {
|
|
1052
1044
|
super();
|
|
1053
1045
|
/** @type {HtmlGeneratorOptions} */
|
|
1054
1046
|
this.options = options || {};
|
|
1055
1047
|
/** @type {ModuleGraph | undefined} */
|
|
1056
1048
|
this._moduleGraph = moduleGraph;
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
//
|
|
1060
|
-
//
|
|
1061
|
-
// so
|
|
1062
|
-
// and releases with it. The two passes differ only in `undoPath`.
|
|
1049
|
+
/** @type {((module: NormalModule) => boolean) | undefined} */
|
|
1050
|
+
this._isPageOnly = isPageOnly;
|
|
1051
|
+
// Raw render shared between the JS and HTML passes of one `codeGeneration()`
|
|
1052
|
+
// call, which differ only in `undoPath`. Keyed by that call's
|
|
1053
|
+
// `runtimeRequirements` Set, so the entry is scoped to it and releases with it.
|
|
1063
1054
|
/** @type {WeakMap<RuntimeRequirements, string>} */
|
|
1064
1055
|
this._rawRenderCache = new WeakMap();
|
|
1065
1056
|
}
|
|
@@ -1071,11 +1062,9 @@ class HtmlGenerator extends Generator {
|
|
|
1071
1062
|
* @returns {string | undefined} reason why this module can't be concatenated, undefined when it can be concatenated
|
|
1072
1063
|
*/
|
|
1073
1064
|
getConcatenationBailoutReason(module, context) {
|
|
1074
|
-
// The HMR shim references the per-module `module.hot
|
|
1075
|
-
//
|
|
1076
|
-
//
|
|
1077
|
-
// would target the wrong module id. Bail out of concatenation so the
|
|
1078
|
-
// HMR-aware HTML module keeps its own module scope.
|
|
1065
|
+
// The HMR shim references the per-module `module.hot`, and a concatenated
|
|
1066
|
+
// file shares one `module`, so the self-accept wiring would target the wrong
|
|
1067
|
+
// id. Bail out, keeping the module's own scope.
|
|
1079
1068
|
if (module.hot) {
|
|
1080
1069
|
return "HTML module needs its own module scope for HMR";
|
|
1081
1070
|
}
|
|
@@ -1134,6 +1123,9 @@ class HtmlGenerator extends Generator {
|
|
|
1134
1123
|
*/
|
|
1135
1124
|
getTypes(module) {
|
|
1136
1125
|
if (this._shouldExposeHtmlType(module)) {
|
|
1126
|
+
// A page nothing else reads has no JavaScript side: that chunk would
|
|
1127
|
+
// only re-export the markup already emitted as the `.html` asset.
|
|
1128
|
+
if (this._isPageOnly && this._isPageOnly(module)) return HTML_TYPES;
|
|
1137
1129
|
return JAVASCRIPT_AND_HTML_TYPES;
|
|
1138
1130
|
}
|
|
1139
1131
|
return JAVASCRIPT_TYPES;
|
|
@@ -1143,10 +1135,9 @@ class HtmlGenerator extends Generator {
|
|
|
1143
1135
|
* @returns {boolean} whether getTypes() depends on the module's incoming connections
|
|
1144
1136
|
*/
|
|
1145
1137
|
getTypesDependOnIncomingConnections() {
|
|
1146
|
-
//
|
|
1147
|
-
//
|
|
1148
|
-
|
|
1149
|
-
return extract !== true && extract !== false && extract !== "inline";
|
|
1138
|
+
// Every page that can expose the html type reads incoming connections —
|
|
1139
|
+
// for the `extract` default, and for the page-only JavaScript drop.
|
|
1140
|
+
return this.options.extract !== false;
|
|
1150
1141
|
}
|
|
1151
1142
|
|
|
1152
1143
|
/**
|
|
@@ -1272,10 +1263,9 @@ class HtmlGenerator extends Generator {
|
|
|
1272
1263
|
* @returns {string} the rewritten HTML
|
|
1273
1264
|
*/
|
|
1274
1265
|
_renderHtml(module, generateContext, undoPath) {
|
|
1275
|
-
//
|
|
1276
|
-
//
|
|
1277
|
-
//
|
|
1278
|
-
// passes diverge only in the `[webpack/auto]` substitution below.
|
|
1266
|
+
// No dependency template branches on `type` or writes
|
|
1267
|
+
// `runtimeRequirements`, so the raw render is computed once per
|
|
1268
|
+
// `codeGeneration()`; the passes diverge only in the substitution below.
|
|
1279
1269
|
const cacheKey = generateContext.runtimeRequirements;
|
|
1280
1270
|
let rawContent = this._rawRenderCache.get(cacheKey);
|
|
1281
1271
|
if (rawContent === undefined) {
|
|
@@ -1339,11 +1329,9 @@ class HtmlGenerator extends Generator {
|
|
|
1339
1329
|
|
|
1340
1330
|
/** @type {string} */
|
|
1341
1331
|
let sourceContent;
|
|
1342
|
-
// `module.hot`
|
|
1343
|
-
//
|
|
1344
|
-
//
|
|
1345
|
-
// would target the wrong id) — `getConcatenationBailoutReason` keeps
|
|
1346
|
-
// us out of concatenation in that case.
|
|
1332
|
+
// `module.hot` marks HMR being enabled, and concatenation merges into a
|
|
1333
|
+
// parent's scope where `module.hot.accept` would target the wrong id.
|
|
1334
|
+
// `getConcatenationBailoutReason` keeps such a module out of it.
|
|
1347
1335
|
if (generateContext.concatenationScope && !module.hot) {
|
|
1348
1336
|
generateContext.concatenationScope.registerNamespaceExport(
|
|
1349
1337
|
ConcatenationScope.NAMESPACE_OBJECT_EXPORT
|
|
@@ -1417,15 +1405,11 @@ class HtmlGenerator extends Generator {
|
|
|
1417
1405
|
const acceptBlock = extracting
|
|
1418
1406
|
? [
|
|
1419
1407
|
"module.hot.accept();",
|
|
1420
|
-
//
|
|
1421
|
-
//
|
|
1422
|
-
//
|
|
1423
|
-
//
|
|
1424
|
-
//
|
|
1425
|
-
// `<body>`/`</body>`/`<title>` inside a comment can no
|
|
1426
|
-
// longer fool the tag regexes (the non-greedy `*?` would
|
|
1427
|
-
// otherwise stop at the FIRST `</body>` it sees, even one
|
|
1428
|
-
// inside a comment).
|
|
1408
|
+
// WHY: a `</body>` inside a comment stops the non-greedy `*?` at the
|
|
1409
|
+
// wrong place, so comments are masked before any tag regex runs.
|
|
1410
|
+
// Masking rather than deleting keeps offsets stable, so the body and
|
|
1411
|
+
// title can still be sliced out of the original HTML with their
|
|
1412
|
+
// comments intact.
|
|
1429
1413
|
`${declare} __webpack_mask_comments__ = ${runtimeTemplate.returningFunction(
|
|
1430
1414
|
`h.replace(/<!--[\\s\\S]*?-->/g, ${runtimeTemplate.returningFunction(
|
|
1431
1415
|
'c.replace(/[^\\n]/g, " ")',
|
|
@@ -1469,9 +1453,8 @@ class HtmlGenerator extends Generator {
|
|
|
1469
1453
|
]
|
|
1470
1454
|
)};`,
|
|
1471
1455
|
// A `<script>` parsed out of a string carries the already-started flag,
|
|
1472
|
-
// so appending
|
|
1473
|
-
//
|
|
1474
|
-
// replaces would have done.
|
|
1456
|
+
// so appending it would never run. A fresh one with the same attributes
|
|
1457
|
+
// and body does, as the reload this replaces would have.
|
|
1475
1458
|
`${declare} __webpack_revive_script__ = ${runtimeTemplate.basicFunction(
|
|
1476
1459
|
"node",
|
|
1477
1460
|
[
|
|
@@ -1487,11 +1470,9 @@ class HtmlGenerator extends Generator {
|
|
|
1487
1470
|
"return script;"
|
|
1488
1471
|
]
|
|
1489
1472
|
)};`,
|
|
1490
|
-
// Apply only the difference between the two authored heads
|
|
1491
|
-
//
|
|
1492
|
-
//
|
|
1493
|
-
// tear them down while a delta never touches them. Reports whether it
|
|
1494
|
-
// could — the caller reloads when it could not.
|
|
1473
|
+
// Apply only the difference between the two authored heads: the
|
|
1474
|
+
// runtime's own injected tags are in neither string, so replacing
|
|
1475
|
+
// `document.head` wholesale would tear them down where a delta cannot.
|
|
1495
1476
|
`${declare} __webpack_patch_head__ = ${runtimeTemplate.basicFunction(
|
|
1496
1477
|
"oldHtml, newHtml",
|
|
1497
1478
|
[
|
|
@@ -1527,14 +1508,12 @@ class HtmlGenerator extends Generator {
|
|
|
1527
1508
|
`${declare} removed = surplus(oldChildren, newChildren);`,
|
|
1528
1509
|
`${declare} added = surplus(newChildren, oldChildren);`,
|
|
1529
1510
|
"if (removed.length === 0 && added.length === 0) return true;",
|
|
1530
|
-
//
|
|
1531
|
-
//
|
|
1532
|
-
// `type` that is neither a JavaScript MIME
|
|
1533
|
-
// `importmap`
|
|
1534
|
-
//
|
|
1535
|
-
//
|
|
1536
|
-
// Every JavaScript MIME essence ends in `script`, and a type
|
|
1537
|
-
// nothing here recognizes falls back to the reload.
|
|
1511
|
+
// WHY: a script that has run cannot be un-run, so dropping one is the
|
|
1512
|
+
// single edit still worth a reload — but only a script that ran. A
|
|
1513
|
+
// `type` that is neither a JavaScript MIME essence, all of which end
|
|
1514
|
+
// in `script`, nor `module`, `importmap` or `speculationrules` is a
|
|
1515
|
+
// data block the browser never executed, as safe to remove as a
|
|
1516
|
+
// `<meta>`. An unrecognized type falls back to the reload.
|
|
1538
1517
|
`if (removed.some(${runtimeTemplate.basicFunction("node", [
|
|
1539
1518
|
'if (node.nodeName !== "SCRIPT") return false;',
|
|
1540
1519
|
`${declare} type = (node.getAttribute("type") || "").trim().toLowerCase();`,
|
|
@@ -1558,11 +1537,9 @@ class HtmlGenerator extends Generator {
|
|
|
1558
1537
|
]),
|
|
1559
1538
|
"}",
|
|
1560
1539
|
`for (${mutable} i = 0; i < live.length; i++) document.head.removeChild(live[i]);`,
|
|
1561
|
-
// Pair each retained element with its live node, scanning
|
|
1562
|
-
//
|
|
1563
|
-
//
|
|
1564
|
-
// cannot express falls back to the reload. Injected nodes simply
|
|
1565
|
-
// never match, so they neither anchor nor block anything.
|
|
1540
|
+
// Pair each retained element with its live node, scanning forward
|
|
1541
|
+
// only: a moved element then finds no match and falls back to the
|
|
1542
|
+
// reload, while an injected node never matches either way.
|
|
1566
1543
|
`${declare} liveByNew = [];`,
|
|
1567
1544
|
`${mutable} searchFrom = 0;`,
|
|
1568
1545
|
`for (${mutable} i = 0; i < newChildren.length; i++) {`,
|
|
@@ -1642,13 +1619,22 @@ class HtmlGenerator extends Generator {
|
|
|
1642
1619
|
*/
|
|
1643
1620
|
generateError(error, module, generateContext) {
|
|
1644
1621
|
if (generateContext.type === HTML_TYPE) {
|
|
1645
|
-
// Strip `<`, `>`, `--` runs from
|
|
1646
|
-
const safe =
|
|
1622
|
+
// Strip `<`, `>`, `--` runs from the message so it can't escape the comment.
|
|
1623
|
+
const safe = Generator.buildErrorMessage(
|
|
1624
|
+
error,
|
|
1625
|
+
generateContext.runtimeTemplate.requestShortener
|
|
1626
|
+
)
|
|
1647
1627
|
.replace(/[<>]/g, "")
|
|
1648
1628
|
.replace(/-{2,}/g, (m) => `${"-".repeat(m.length - 1)} `);
|
|
1649
1629
|
return new RawSource(`<!-- webpack error: ${safe} -->`);
|
|
1650
1630
|
}
|
|
1651
|
-
return new RawSource(
|
|
1631
|
+
return new RawSource(
|
|
1632
|
+
Generator.throwBuildErrorCode(
|
|
1633
|
+
error,
|
|
1634
|
+
undefined,
|
|
1635
|
+
generateContext.runtimeTemplate.requestShortener
|
|
1636
|
+
)
|
|
1637
|
+
);
|
|
1652
1638
|
}
|
|
1653
1639
|
|
|
1654
1640
|
/**
|
|
@@ -1658,10 +1644,9 @@ class HtmlGenerator extends Generator {
|
|
|
1658
1644
|
*/
|
|
1659
1645
|
updateHash(hash, updateHashContext) {
|
|
1660
1646
|
hash.update("html");
|
|
1661
|
-
//
|
|
1662
|
-
// `extracting` branch
|
|
1663
|
-
//
|
|
1664
|
-
// One `_shouldExtract` walk covers both checks (expose = extract ∪ inline).
|
|
1647
|
+
// The source-type set turns on html-type exposure and the HMR shim's
|
|
1648
|
+
// `extracting` branch on the emit decision. They differ only for
|
|
1649
|
+
// `"inline"`, which exposes html without emitting, so hash both.
|
|
1665
1650
|
const extract = this._shouldExtract(updateHashContext.module);
|
|
1666
1651
|
if (extract || this.options.extract === "inline") {
|
|
1667
1652
|
hash.update("html-type");
|