webpack 5.107.1 → 5.108.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/hot/dev-server.js +2 -0
- package/lib/APIPlugin.js +8 -4
- package/lib/CacheFacade.js +7 -0
- package/lib/Chunk.js +4 -0
- package/lib/ChunkGraph.js +30 -9
- package/lib/CircularModulesPlugin.js +190 -0
- package/lib/CleanPlugin.js +2 -1
- package/lib/Compilation.js +396 -65
- package/lib/Compiler.js +52 -14
- package/lib/ConcatenationScope.js +10 -3
- package/lib/ContextExclusionPlugin.js +1 -0
- package/lib/ContextModule.js +92 -47
- package/lib/ContextModuleFactory.js +45 -38
- package/lib/ContextReplacementPlugin.js +4 -0
- package/lib/DefinePlugin.js +89 -15
- package/lib/Dependency.js +111 -7
- package/lib/EntryOptionPlugin.js +39 -2
- package/lib/EntryPlugin.js +2 -0
- package/lib/ExportsInfo.js +314 -73
- package/lib/ExternalModule.js +82 -34
- package/lib/ExternalModuleFactoryPlugin.js +1 -0
- package/lib/ExternalsPlugin.js +1 -0
- package/lib/FileSystemInfo.js +173 -23
- package/lib/FlagAllModulesAsUsedPlugin.js +1 -5
- package/lib/FlagDependencyExportsPlugin.js +23 -0
- package/lib/FlagDependencyUsagePlugin.js +87 -5
- package/lib/FlagEntryExportAsUsedPlugin.js +2 -0
- package/lib/Generator.js +8 -0
- package/lib/HotModuleReplacementPlugin.js +65 -28
- package/lib/IgnorePlugin.js +1 -0
- package/lib/InitFragment.js +5 -0
- package/lib/JavascriptMetaInfoPlugin.js +7 -5
- package/lib/LazyBarrel.js +361 -0
- package/lib/LoaderTargetPlugin.js +1 -0
- package/lib/Module.js +21 -42
- package/lib/ModuleGraph.js +3 -2
- package/lib/ModuleProfile.js +27 -1
- package/lib/ModuleTemplate.js +2 -0
- package/lib/MultiCompiler.js +16 -0
- package/lib/MultiStats.js +1 -0
- package/lib/MultiWatching.js +2 -0
- package/lib/NodeStuffPlugin.js +22 -17
- package/lib/NormalModule.js +557 -77
- package/lib/NormalModuleReplacementPlugin.js +2 -0
- package/lib/PrefetchPlugin.js +2 -0
- package/lib/ProgressPlugin.js +9 -1
- package/lib/ProvidePlugin.js +1 -0
- package/lib/RawModule.js +20 -16
- package/lib/RecordIdsPlugin.js +1 -0
- package/lib/RuntimeGlobals.js +5 -0
- package/lib/RuntimePlugin.js +58 -26
- package/lib/RuntimeTemplate.js +278 -21
- package/lib/SelfModuleFactory.js +1 -0
- package/lib/SourceMapDevToolPlugin.js +105 -30
- package/lib/Stats.js +1 -0
- package/lib/Template.js +8 -2
- package/lib/TemplatedPathPlugin.js +473 -131
- package/lib/WarnCaseSensitiveModulesPlugin.js +1 -0
- package/lib/WarnDeprecatedOptionPlugin.js +4 -0
- package/lib/WarnNoModeSetPlugin.js +1 -0
- package/lib/WatchIgnorePlugin.js +1 -0
- package/lib/Watching.js +9 -0
- package/lib/WebpackOptionsApply.js +50 -5
- package/lib/asset/AssetBytesGenerator.js +11 -3
- package/lib/asset/AssetGenerator.js +47 -22
- package/lib/asset/AssetModule.js +47 -0
- package/lib/asset/AssetModulesPlugin.js +14 -14
- package/lib/asset/AssetParser.js +2 -2
- package/lib/asset/AssetSourceGenerator.js +8 -0
- package/lib/asset/RawDataUrlModule.js +12 -13
- package/lib/buildChunkGraph.js +88 -9
- package/lib/bun/BunTargetPlugin.js +48 -0
- package/lib/cache/AddBuildDependenciesPlugin.js +1 -0
- package/lib/cache/AddManagedPathsPlugin.js +3 -0
- package/lib/cache/IdleFileCachePlugin.js +4 -0
- package/lib/cache/MemoryWithGcCachePlugin.js +1 -0
- package/lib/cache/PackFileCacheStrategy.js +1 -0
- package/lib/cache/ResolverCachePlugin.js +2 -0
- package/lib/cache/getLazyHashedEtag.js +9 -2
- package/lib/cache/mergeEtags.js +2 -0
- package/lib/cli.js +109 -19
- package/lib/config/browserslistTargetHandler.js +99 -0
- package/lib/config/defaults.js +147 -7
- package/lib/config/defineConfig.js +31 -0
- package/lib/config/normalization.js +5 -0
- package/lib/config/target.js +181 -2
- package/lib/container/ContainerEntryModule.js +15 -14
- package/lib/container/ContainerExposedDependency.js +2 -2
- package/lib/container/ContainerReferencePlugin.js +1 -1
- package/lib/container/FallbackDependency.js +5 -7
- package/lib/container/FallbackModule.js +10 -9
- package/lib/container/RemoteModule.js +20 -10
- package/lib/container/RemoteRuntimeModule.js +14 -12
- package/lib/css/CssGenerator.js +353 -327
- package/lib/css/CssInjectStyleRuntimeModule.js +36 -8
- package/lib/css/CssLoadingRuntimeModule.js +118 -47
- package/lib/css/CssModule.js +52 -23
- package/lib/css/CssModulesPlugin.js +107 -124
- package/lib/css/CssParser.js +2759 -2205
- package/lib/css/syntax.js +2859 -0
- package/lib/debug/ProfilingPlugin.js +2 -0
- package/lib/deno/DenoTargetPlugin.js +47 -0
- package/lib/dependencies/AMDDefineDependency.js +22 -17
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +1 -0
- package/lib/dependencies/AMDRequireArrayDependency.js +7 -11
- package/lib/dependencies/AMDRequireContextDependency.js +7 -11
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +1 -0
- package/lib/dependencies/AMDRequireDependency.js +24 -20
- package/lib/dependencies/CachedConstDependency.js +3 -0
- package/lib/dependencies/CommonJsDependencyHelpers.js +1 -0
- package/lib/dependencies/CommonJsExportRequireDependency.js +79 -31
- package/lib/dependencies/CommonJsExportsDependency.js +21 -16
- package/lib/dependencies/CommonJsExportsParserPlugin.js +230 -7
- package/lib/dependencies/CommonJsFullRequireDependency.js +27 -19
- package/lib/dependencies/CommonJsImportsParserPlugin.js +51 -16
- package/lib/dependencies/CommonJsPlugin.js +1 -1
- package/lib/dependencies/CommonJsRequireContextDependency.js +10 -13
- package/lib/dependencies/CommonJsRequireDependency.js +42 -11
- package/lib/dependencies/CommonJsSelfReferenceDependency.js +22 -14
- package/lib/dependencies/ConstDependency.js +16 -11
- package/lib/dependencies/ContextDependency.js +4 -0
- package/lib/dependencies/ContextDependencyTemplateAsId.js +1 -1
- package/lib/dependencies/ContextElementDependency.js +23 -14
- package/lib/dependencies/CreateRequireParserPlugin.js +1 -0
- package/lib/dependencies/CreateScriptUrlDependency.js +5 -7
- package/lib/dependencies/CriticalDependencyWarning.js +1 -0
- package/lib/dependencies/CssIcssExportDependency.js +512 -574
- package/lib/dependencies/CssIcssImportDependency.js +9 -9
- package/lib/dependencies/CssIcssSymbolDependency.js +22 -15
- package/lib/dependencies/CssImportDependency.js +25 -1
- package/lib/dependencies/CssUrlDependency.js +23 -14
- package/lib/dependencies/DllEntryDependency.js +9 -13
- package/lib/dependencies/ExportBindingInitFragment.js +164 -0
- package/lib/dependencies/ExportsInfoDependency.js +12 -12
- package/lib/dependencies/ExternalModuleDependency.js +8 -5
- package/lib/dependencies/ExternalModuleInitFragment.js +7 -5
- package/lib/dependencies/ExternalModuleInitFragmentDependency.js +13 -10
- package/lib/dependencies/HarmonyAcceptDependency.js +11 -11
- package/lib/dependencies/HarmonyAcceptImportDependency.js +1 -0
- package/lib/dependencies/HarmonyDetectionParserPlugin.js +47 -22
- package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +28 -2
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +46 -22
- package/lib/dependencies/HarmonyExportExpressionDependency.js +107 -30
- package/lib/dependencies/HarmonyExportHeaderDependency.js +7 -9
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +109 -31
- package/lib/dependencies/HarmonyExportInitFragment.js +22 -20
- package/lib/dependencies/HarmonyExportSpecifierDependency.js +83 -18
- package/lib/dependencies/HarmonyExports.js +4 -1
- package/lib/dependencies/HarmonyImportDependency.js +24 -0
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +110 -74
- package/lib/dependencies/HarmonyImportGuard.js +254 -0
- package/lib/dependencies/HarmonyImportSideEffectDependency.js +18 -1
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +118 -14
- package/lib/dependencies/HarmonyLinkingError.js +1 -0
- package/lib/dependencies/HarmonyModulesPlugin.js +1 -0
- package/lib/dependencies/{HtmlScriptSrcDependency.js → HtmlEntryDependency.js} +267 -154
- package/lib/dependencies/HtmlInlineHtmlDependency.js +107 -0
- package/lib/dependencies/HtmlInlineScriptDependency.js +20 -27
- package/lib/dependencies/HtmlInlineStyleDependency.js +62 -11
- package/lib/dependencies/HtmlSourceDependency.js +18 -0
- package/lib/dependencies/ImportContextDependency.js +5 -9
- package/lib/dependencies/ImportDependency.js +44 -2
- package/lib/dependencies/ImportMetaHotAcceptDependency.js +1 -0
- package/lib/dependencies/ImportMetaHotDeclineDependency.js +1 -0
- package/lib/dependencies/ImportMetaPlugin.js +74 -30
- package/lib/dependencies/ImportParserPlugin.js +19 -0
- package/lib/dependencies/ImportWeakDependency.js +1 -0
- package/lib/dependencies/JsonExportsDependency.js +9 -9
- package/lib/dependencies/LoaderImportDependency.js +1 -0
- package/lib/dependencies/LocalModule.js +11 -12
- package/lib/dependencies/LocalModuleDependency.js +11 -13
- package/lib/dependencies/ModuleDecoratorDependency.js +9 -9
- package/lib/dependencies/ModuleDependency.js +7 -0
- package/lib/dependencies/ModuleHotAcceptDependency.js +1 -0
- package/lib/dependencies/ModuleHotDeclineDependency.js +1 -0
- package/lib/dependencies/ModuleInitFragmentDependency.js +15 -11
- package/lib/dependencies/ProvidedDependency.js +31 -27
- package/lib/dependencies/PureExpressionDependency.js +7 -9
- package/lib/dependencies/RequireEnsureDependency.js +12 -13
- package/lib/dependencies/RequireHeaderDependency.js +3 -4
- package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +3 -0
- package/lib/dependencies/RequireResolveContextDependency.js +7 -11
- package/lib/dependencies/RequireResolveDependency.js +1 -0
- package/lib/dependencies/RequireResolveHeaderDependency.js +3 -5
- package/lib/dependencies/RuntimeRequirementsDependency.js +6 -7
- package/lib/dependencies/StaticExportsDependency.js +10 -10
- package/lib/dependencies/SystemPlugin.js +2 -0
- package/lib/dependencies/URLContextDependency.js +5 -7
- package/lib/dependencies/URLDependency.js +14 -16
- package/lib/dependencies/UnsupportedDependency.js +8 -13
- package/lib/dependencies/WebAssemblyExportImportedDependency.js +11 -16
- package/lib/dependencies/WebAssemblyImportDependency.js +14 -16
- package/lib/dependencies/WebpackIsIncludedDependency.js +1 -0
- package/lib/dependencies/WorkerDependency.js +19 -8
- package/lib/dependencies/WorkerPlugin.js +40 -10
- package/lib/dependencies/processExportInfo.js +13 -11
- package/lib/dll/DelegatedModule.js +29 -15
- package/lib/dll/DelegatedModuleFactoryPlugin.js +1 -0
- package/lib/dll/DelegatedPlugin.js +1 -0
- package/lib/dll/DllEntryPlugin.js +3 -0
- package/lib/dll/DllModule.js +3 -2
- package/lib/dll/DllPlugin.js +16 -0
- package/lib/dll/DllReferencePlugin.js +3 -0
- package/lib/dll/LibManifestPlugin.js +1 -0
- package/lib/electron/ElectronTargetPlugin.js +22 -4
- package/lib/errors/ConcurrentCompilationError.js +1 -0
- package/lib/errors/HookWebpackError.js +11 -13
- package/lib/errors/IgnoreErrorModuleFactory.js +1 -0
- package/lib/errors/InvalidDependenciesModuleWarning.js +2 -0
- package/lib/errors/JSONParseError.js +9 -8
- package/lib/errors/ModuleBuildError.js +16 -13
- package/lib/errors/ModuleDependencyError.js +8 -1
- package/lib/errors/ModuleDependencyWarning.js +8 -1
- package/lib/errors/ModuleError.js +5 -11
- package/lib/errors/ModuleHashingError.js +4 -0
- package/lib/errors/ModuleNotFoundError.js +3 -0
- package/lib/errors/ModuleParseError.js +5 -11
- package/lib/errors/ModuleRestoreError.js +2 -0
- package/lib/errors/ModuleStoreError.js +3 -0
- package/lib/errors/ModuleWarning.js +7 -11
- package/lib/errors/NodeStuffInWebError.js +1 -0
- package/lib/errors/NonErrorEmittedError.js +2 -0
- package/lib/errors/UnhandledSchemeError.js +1 -0
- package/lib/esm/ModuleChunkLoadingPlugin.js +0 -1
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +28 -23
- package/lib/hmr/HotModuleReplacement.runtime.js +175 -30
- package/lib/hmr/HotModuleReplacementRuntimeModule.js +7 -0
- package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +173 -26
- package/lib/hmr/LazyCompilationPlugin.js +134 -6
- package/lib/html/HtmlGenerator.js +292 -50
- package/lib/html/HtmlModule.js +40 -0
- package/lib/html/HtmlModulesPlugin.js +287 -60
- package/lib/html/HtmlParser.js +1108 -1099
- package/lib/html/{walkHtmlTokens.js → syntax.js} +4701 -212
- package/lib/ids/IdHelpers.js +4 -2
- package/lib/index.js +19 -0
- package/lib/javascript/BasicEvaluatedExpression.js +1 -0
- package/lib/javascript/EnableChunkLoadingPlugin.js +1 -0
- package/lib/javascript/JavascriptGenerator.js +6 -2
- package/lib/javascript/JavascriptModule.js +54 -0
- package/lib/javascript/JavascriptModulesPlugin.js +257 -102
- package/lib/javascript/JavascriptParser.js +286 -159
- package/lib/json/JsonModule.js +40 -0
- package/lib/json/JsonModulesPlugin.js +7 -0
- package/lib/json/JsonParser.js +4 -2
- package/lib/library/AssignLibraryPlugin.js +5 -3
- package/lib/library/ExportPropertyLibraryPlugin.js +1 -0
- package/lib/library/FalseIIFEUmdWarning.js +1 -0
- package/lib/library/ModuleLibraryPlugin.js +54 -29
- package/lib/library/SystemLibraryPlugin.js +3 -3
- package/lib/node/NodeTargetPlugin.js +1 -0
- package/lib/node/NodeWatchFileSystem.js +38 -22
- package/lib/node/ReadFileChunkLoadingRuntimeModule.js +10 -9
- package/lib/node/RequireChunkLoadingRuntimeModule.js +18 -16
- package/lib/optimize/ConcatenatedModule.js +397 -78
- package/lib/optimize/ConstExportsPlugin.js +211 -0
- package/lib/optimize/InlineExports.js +178 -0
- package/lib/optimize/InnerGraph.js +372 -275
- package/lib/optimize/InnerGraphPlugin.js +196 -99
- package/lib/optimize/ModuleConcatenationPlugin.js +56 -25
- package/lib/optimize/RealContentHashPlugin.js +14 -1
- package/lib/optimize/SideEffectsFlagPlugin.js +234 -64
- package/lib/runtime/AsyncModuleRuntimeModule.js +32 -30
- package/lib/runtime/AutoPublicPathRuntimeModule.js +11 -5
- package/lib/runtime/CompatGetDefaultExportRuntimeModule.js +1 -1
- package/lib/runtime/CreateFakeNamespaceObjectRuntimeModule.js +6 -4
- package/lib/runtime/DefinePropertyGettersRuntimeModule.js +33 -4
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +82 -3
- package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +1 -1
- package/lib/runtime/HasOwnPropertyRuntimeModule.js +1 -1
- package/lib/runtime/LoadScriptRuntimeModule.js +18 -13
- package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +39 -26
- package/lib/runtime/MakeNamespaceObjectRuntimeModule.js +1 -1
- package/lib/runtime/OnChunksLoadedRuntimeModule.js +4 -4
- package/lib/runtime/RelativeUrlRuntimeModule.js +3 -2
- package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +1 -1
- package/lib/runtime/StartupEntrypointRuntimeModule.js +4 -3
- package/lib/runtime/WorkerRuntimeModule.js +33 -0
- package/lib/schemes/HttpUriPlugin.js +3 -2
- package/lib/serialization/AggregateErrorSerializer.js +7 -6
- package/lib/serialization/ArraySerializer.js +4 -8
- package/lib/serialization/BinaryMiddleware.js +538 -468
- package/lib/serialization/DateObjectSerializer.js +2 -2
- package/lib/serialization/ErrorObjectSerializer.js +7 -6
- package/lib/serialization/MapObjectSerializer.js +5 -9
- package/lib/serialization/NullPrototypeObjectSerializer.js +7 -9
- package/lib/serialization/ObjectMiddleware.js +50 -13
- package/lib/serialization/PlainObjectSerializer.js +9 -8
- package/lib/serialization/RegExpObjectSerializer.js +2 -2
- package/lib/serialization/Serializer.js +1 -0
- package/lib/serialization/SetObjectSerializer.js +4 -8
- package/lib/sharing/ConsumeSharedModule.js +6 -7
- package/lib/sharing/ConsumeSharedPlugin.js +1 -0
- package/lib/sharing/ConsumeSharedRuntimeModule.js +46 -41
- package/lib/sharing/ProvideSharedDependency.js +30 -15
- package/lib/sharing/ProvideSharedModule.js +30 -11
- package/lib/sharing/ProvideSharedPlugin.js +4 -2
- package/lib/sharing/SharePlugin.js +3 -0
- package/lib/sharing/ShareRuntimeModule.js +18 -16
- package/lib/sharing/resolveMatchedConfigs.js +2 -1
- package/lib/sharing/utils.js +1 -1
- package/lib/stats/DefaultStatsFactoryPlugin.js +4 -6
- package/lib/stats/DefaultStatsPrinterPlugin.js +14 -14
- package/lib/stats/StatsFactory.js +11 -9
- package/lib/stats/StatsPrinter.js +9 -2
- package/lib/url/URLParserPlugin.js +5 -2
- package/lib/util/AsyncQueue.js +10 -0
- package/lib/util/LazyBucketSortedSet.js +5 -0
- package/lib/util/LazySet.js +6 -4
- package/lib/util/LocConverter.js +11 -1
- package/lib/util/Semaphore.js +1 -0
- package/lib/util/SourceProcessor.js +106 -0
- package/lib/util/TupleSet.js +1 -0
- package/lib/util/WeakTupleMap.js +27 -1
- package/lib/util/chainedImports.js +3 -3
- package/lib/util/comparators.js +2 -2
- package/lib/util/concatenate.js +31 -7
- package/lib/util/createHash.js +0 -1
- package/lib/util/deterministicGrouping.js +19 -12
- package/lib/util/extractSourceMap.js +1 -1
- package/lib/util/findGraphRoots.js +2 -0
- package/lib/util/fs.js +16 -6
- package/lib/util/hash/DebugHash.js +1 -0
- package/lib/util/hash/hash-digest.js +24 -15
- package/lib/util/identifier.js +7 -0
- package/lib/util/internalSerializables.js +11 -2
- package/lib/util/magicComment.js +42 -0
- package/lib/util/makeSerializable.js +1 -0
- package/lib/util/nonNumericOnlyHash.js +30 -1
- package/lib/util/property.js +7 -1
- package/lib/util/publicPathPlaceholder.js +64 -0
- package/lib/util/registerExternalSerializer.js +4 -4
- package/lib/wasm-async/AsyncWasmModule.js +77 -0
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +1 -1
- package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +1 -96
- package/lib/wasm-async/AsyncWebAssemblyParser.js +1 -1
- package/lib/wasm-async/UniversalCompileAsyncWasmPlugin.js +1 -1
- package/lib/wasm-sync/SyncWasmModule.js +39 -0
- package/lib/wasm-sync/UnsupportedWebAssemblyFeatureError.js +1 -0
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +6 -3
- package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +2 -1
- package/lib/wasm-sync/WebAssemblyGenerator.js +1 -0
- package/lib/wasm-sync/WebAssemblyInInitialChunkError.js +2 -0
- package/lib/wasm-sync/WebAssemblyModulesPlugin.js +10 -0
- package/lib/wasm-sync/WebAssemblyParser.js +7 -3
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +45 -39
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +11 -10
- package/package.json +36 -28
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +212 -3
- package/schemas/plugins/HtmlGeneratorOptions.check.js +1 -1
- package/schemas/plugins/HtmlParserOptions.check.d.ts +7 -0
- package/schemas/plugins/HtmlParserOptions.check.js +6 -0
- package/schemas/plugins/HtmlParserOptions.json +3 -0
- package/schemas/plugins/css/CssAutoOrModuleParserOptions.check.js +1 -1
- package/schemas/plugins/css/CssModuleParserOptions.check.js +1 -1
- package/schemas/plugins/css/CssParserOptions.check.js +1 -1
- package/types.d.ts +1592 -314
- package/lib/css/walkCssTokens.js +0 -2020
- package/lib/util/AppendOnlyStackedSet.js +0 -93
|
@@ -5,27 +5,73 @@
|
|
|
5
5
|
"use strict";
|
|
6
6
|
|
|
7
7
|
const { RawSource } = require("webpack-sources");
|
|
8
|
+
const EntryOptionPlugin = require("../EntryOptionPlugin");
|
|
8
9
|
const EntryPlugin = require("../EntryPlugin");
|
|
9
10
|
const HotUpdateChunk = require("../HotUpdateChunk");
|
|
10
11
|
const { HTML_TYPE } = require("../ModuleSourceTypeConstants");
|
|
11
12
|
const { HTML_MODULE_TYPE } = require("../ModuleTypeConstants");
|
|
12
13
|
const NormalModule = require("../NormalModule");
|
|
13
14
|
const ConstDependency = require("../dependencies/ConstDependency");
|
|
15
|
+
const HtmlEntryDependency = require("../dependencies/HtmlEntryDependency");
|
|
16
|
+
const HtmlInlineHtmlDependency = require("../dependencies/HtmlInlineHtmlDependency");
|
|
14
17
|
const HtmlInlineScriptDependency = require("../dependencies/HtmlInlineScriptDependency");
|
|
15
18
|
const HtmlInlineStyleDependency = require("../dependencies/HtmlInlineStyleDependency");
|
|
16
|
-
const HtmlScriptSrcDependency = require("../dependencies/HtmlScriptSrcDependency");
|
|
17
19
|
const HtmlSourceDependency = require("../dependencies/HtmlSourceDependency");
|
|
18
20
|
const StaticExportsDependency = require("../dependencies/StaticExportsDependency");
|
|
21
|
+
const WebpackError = require("../errors/WebpackError");
|
|
19
22
|
const { compareModulesByFullName } = require("../util/comparators");
|
|
23
|
+
const createHash = require("../util/createHash");
|
|
24
|
+
const { digestNonNumericOnly } = require("../util/nonNumericOnlyHash");
|
|
20
25
|
const removeBOM = require("../util/removeBOM");
|
|
21
26
|
const HtmlGenerator = require("./HtmlGenerator");
|
|
27
|
+
const HtmlModule = require("./HtmlModule");
|
|
22
28
|
const HtmlParser = require("./HtmlParser");
|
|
23
29
|
|
|
30
|
+
/** @typedef {import("../../declarations/WebpackOptions").EntryDescriptionNormalized} EntryDescriptionNormalized */
|
|
24
31
|
/** @typedef {import("../Compiler")} Compiler */
|
|
25
|
-
/** @typedef {
|
|
32
|
+
/** @typedef {import("./HtmlModule").HtmlModuleBuildInfo} HtmlModuleBuildInfo */
|
|
33
|
+
/** @typedef {{ request: string, entryName: string, type: "script" | "script-module" | "modulepreload" | "stylesheet" }} EntryScriptInfo */
|
|
26
34
|
|
|
27
35
|
const PLUGIN_NAME = "HtmlModulesPlugin";
|
|
28
36
|
|
|
37
|
+
// `\.html`/`\.css` request matchers for the synthetic `output.html` wrapper.
|
|
38
|
+
const HTML_REQUEST_RE = /\.html(\?|$)/i;
|
|
39
|
+
const CSS_REQUEST_RE = /\.css(\?|$)/i;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Requests an `output.html` page must load for an entry: its `dependOn`
|
|
43
|
+
* ancestors first (transitive, deduped — so a diamond loads each once), then
|
|
44
|
+
* the entry's own imports. `.html` imports are dropped (own HTML entries).
|
|
45
|
+
* @param {string} name entry name
|
|
46
|
+
* @param {Record<string, EntryDescriptionNormalized>} entries normalized static entries
|
|
47
|
+
* @returns {string[]} deduped requests in load order
|
|
48
|
+
*/
|
|
49
|
+
const collectHtmlEntryRequests = (name, entries) => {
|
|
50
|
+
/** @type {string[]} */
|
|
51
|
+
const requests = [];
|
|
52
|
+
/** @type {Set<string>} */
|
|
53
|
+
const seenRequests = new Set();
|
|
54
|
+
/** @type {Set<string>} */
|
|
55
|
+
const visited = new Set();
|
|
56
|
+
const walk = (/** @type {string} */ entryName) => {
|
|
57
|
+
if (visited.has(entryName)) return;
|
|
58
|
+
visited.add(entryName);
|
|
59
|
+
const desc = entries[entryName];
|
|
60
|
+
if (!desc) return;
|
|
61
|
+
if (desc.dependOn) {
|
|
62
|
+
for (const dep of desc.dependOn) walk(dep);
|
|
63
|
+
}
|
|
64
|
+
if (!desc.import) return;
|
|
65
|
+
for (const request of desc.import) {
|
|
66
|
+
if (HTML_REQUEST_RE.test(request) || seenRequests.has(request)) continue;
|
|
67
|
+
seenRequests.add(request);
|
|
68
|
+
requests.push(request);
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
walk(name);
|
|
72
|
+
return requests;
|
|
73
|
+
};
|
|
74
|
+
|
|
29
75
|
/**
|
|
30
76
|
* @param {string} name definition name in `schemas/WebpackOptions.json`
|
|
31
77
|
* @returns {EXPECTED_OBJECT} a schema referencing `#/definitions/<name>`
|
|
@@ -44,16 +90,109 @@ const generatorValidationOptions = {
|
|
|
44
90
|
baseDataPath: "generator"
|
|
45
91
|
};
|
|
46
92
|
|
|
93
|
+
const parserValidationOptions = {
|
|
94
|
+
name: "Html Modules Plugin",
|
|
95
|
+
baseDataPath: "parser"
|
|
96
|
+
};
|
|
97
|
+
|
|
47
98
|
class HtmlModulesPlugin {
|
|
99
|
+
/**
|
|
100
|
+
* `output.hashFunction`/`hashSalt`/`hashDigest`/`hashDigestLength`
|
|
101
|
+
* digest of `content`, with `nonNumericOnlyHash` applied — webpack's
|
|
102
|
+
* standard `[contenthash]` recipe.
|
|
103
|
+
* @param {string | Buffer} content content to hash
|
|
104
|
+
* @param {import("../../declarations/WebpackOptions").Output} outputOptions output options
|
|
105
|
+
* @returns {string} content hash
|
|
106
|
+
*/
|
|
107
|
+
static computeContentHash(content, outputOptions) {
|
|
108
|
+
const hash = createHash(
|
|
109
|
+
/** @type {import("../../declarations/WebpackOptions").HashFunction} */
|
|
110
|
+
(outputOptions.hashFunction)
|
|
111
|
+
);
|
|
112
|
+
if (outputOptions.hashSalt) hash.update(outputOptions.hashSalt);
|
|
113
|
+
hash.update(content);
|
|
114
|
+
return digestNonNumericOnly(
|
|
115
|
+
hash,
|
|
116
|
+
/** @type {string} */ (outputOptions.hashDigest),
|
|
117
|
+
/** @type {number} */ (outputOptions.hashDigestLength)
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
|
|
48
121
|
/**
|
|
49
122
|
* Applies the plugin by registering its hooks on the compiler.
|
|
50
123
|
* @param {Compiler} compiler the compiler instance
|
|
51
124
|
* @returns {void}
|
|
52
125
|
*/
|
|
53
126
|
apply(compiler) {
|
|
127
|
+
const { output } = compiler.options;
|
|
128
|
+
const htmlOption = output.html;
|
|
129
|
+
const scriptLoading =
|
|
130
|
+
(typeof htmlOption === "object" && htmlOption.scriptLoading) || "auto";
|
|
131
|
+
// ESM output emits `type="module"` (already deferred), so scriptLoading
|
|
132
|
+
// is ignored under output.module — warn on an explicit defer/blocking.
|
|
133
|
+
let scriptAttr = " defer";
|
|
134
|
+
if (output.module) {
|
|
135
|
+
scriptAttr = "";
|
|
136
|
+
if (scriptLoading === "defer" || scriptLoading === "blocking") {
|
|
137
|
+
compiler.hooks.thisCompilation.tap(PLUGIN_NAME, (compilation) => {
|
|
138
|
+
compilation.warnings.push(
|
|
139
|
+
new WebpackError(
|
|
140
|
+
`output.html.scriptLoading: "${scriptLoading}" is ignored with output.module — ES module scripts are always deferred.`
|
|
141
|
+
)
|
|
142
|
+
);
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
} else if (scriptLoading === "blocking") {
|
|
146
|
+
scriptAttr = "";
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// `output.html` (or an entry's `html`) wraps a non-HTML entry in a
|
|
150
|
+
// synthetic HTML module so the existing pipeline injects its JS/CSS
|
|
151
|
+
// chunks and applies the `template` option. `dependOn` ancestors are
|
|
152
|
+
// injected first so the page loads the shared/runtime chunks before
|
|
153
|
+
// the entry's own (see `collectHtmlEntryRequests`). `crossOriginLoading`
|
|
154
|
+
// and SRI are applied to the injected tags centrally in
|
|
155
|
+
// HtmlEntryDependency.
|
|
156
|
+
EntryOptionPlugin.getHooks(compiler).entry.tap(
|
|
157
|
+
PLUGIN_NAME,
|
|
158
|
+
(context, name, desc) => {
|
|
159
|
+
const html = desc.html !== undefined ? desc.html : htmlOption;
|
|
160
|
+
const imports = desc.import;
|
|
161
|
+
if (
|
|
162
|
+
!html ||
|
|
163
|
+
!imports ||
|
|
164
|
+
imports.every((r) => HTML_REQUEST_RE.test(r))
|
|
165
|
+
) {
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
const entries = compiler.options.entry;
|
|
169
|
+
const requests =
|
|
170
|
+
typeof entries === "object" && entries[name]
|
|
171
|
+
? collectHtmlEntryRequests(name, entries)
|
|
172
|
+
: imports.filter((r) => !HTML_REQUEST_RE.test(r));
|
|
173
|
+
const links = [];
|
|
174
|
+
const scripts = [];
|
|
175
|
+
for (const r of requests) {
|
|
176
|
+
if (CSS_REQUEST_RE.test(r)) {
|
|
177
|
+
links.push(`<link rel="stylesheet" href="${r}">`);
|
|
178
|
+
} else {
|
|
179
|
+
scripts.push(`<script${scriptAttr} src="${r}"></script>`);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
return `data:text/html,<!doctype html><html><head>${links.join(
|
|
183
|
+
""
|
|
184
|
+
)}</head><body>${scripts.join("")}</body></html>`;
|
|
185
|
+
}
|
|
186
|
+
);
|
|
187
|
+
|
|
188
|
+
// Per-chunk `RawSource` reused across builds when bytes are unchanged:
|
|
189
|
+
// keeping identity stable avoids invalidating `RealContentHashPlugin|analyse`.
|
|
190
|
+
/** @type {Map<string, { content: string, source: import("webpack-sources").RawSource }>} */
|
|
191
|
+
const sentinelResolvedSourceCache = new Map();
|
|
192
|
+
|
|
54
193
|
// `<script src>` and `<link rel="modulepreload">` references collected
|
|
55
|
-
// by HtmlParser become real compilation entries here. The
|
|
56
|
-
// and
|
|
194
|
+
// by HtmlParser become real compilation entries here. The `script`
|
|
195
|
+
// and `script-module` groups are chained via a leader-only dependOn so
|
|
57
196
|
// they share a runtime — the first entry of the group owns it and
|
|
58
197
|
// every subsequent entry sets `dependOn: [leader]`. Modulepreload
|
|
59
198
|
// entries are emitted as independent entries (no dependOn) so they
|
|
@@ -71,17 +210,16 @@ class HtmlModulesPlugin {
|
|
|
71
210
|
|
|
72
211
|
for (const module of compilation.modules) {
|
|
73
212
|
if (module.type !== HTML_MODULE_TYPE) continue;
|
|
74
|
-
const buildInfo =
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
(buildInfo.htmlEntryScripts);
|
|
213
|
+
const buildInfo = /** @type {HtmlModuleBuildInfo | undefined} */ (
|
|
214
|
+
module.buildInfo
|
|
215
|
+
);
|
|
216
|
+
const htmlEntryScripts = buildInfo && buildInfo.htmlEntryScripts;
|
|
79
217
|
if (!htmlEntryScripts) continue;
|
|
80
218
|
|
|
81
219
|
const context = /** @type {string} */ (module.context);
|
|
82
220
|
|
|
83
221
|
for (const [groupKind, group] of Object.entries(htmlEntryScripts)) {
|
|
84
|
-
// Only the script chains (`
|
|
222
|
+
// Only the script chains (`script`, `script-module`) need a
|
|
85
223
|
// shared runtime via leader-only `dependOn` — the others
|
|
86
224
|
// either preload without executing (`modulepreload`) or
|
|
87
225
|
// produce CSS chunks (`stylesheet`) which have no runtime
|
|
@@ -183,12 +321,12 @@ class HtmlModulesPlugin {
|
|
|
183
321
|
new HtmlSourceDependency.Template()
|
|
184
322
|
);
|
|
185
323
|
compilation.dependencyFactories.set(
|
|
186
|
-
|
|
324
|
+
HtmlEntryDependency,
|
|
187
325
|
normalModuleFactory
|
|
188
326
|
);
|
|
189
327
|
compilation.dependencyTemplates.set(
|
|
190
|
-
|
|
191
|
-
new
|
|
328
|
+
HtmlEntryDependency,
|
|
329
|
+
new HtmlEntryDependency.Template()
|
|
192
330
|
);
|
|
193
331
|
// Inline `<script>` content is bundled as its own entry — the
|
|
194
332
|
// same pipeline that handles `<script src>` — via a
|
|
@@ -215,6 +353,17 @@ class HtmlModulesPlugin {
|
|
|
215
353
|
HtmlInlineStyleDependency,
|
|
216
354
|
new HtmlInlineStyleDependency.Template()
|
|
217
355
|
);
|
|
356
|
+
// `<iframe srcdoc>` content is routed back through the HTML
|
|
357
|
+
// pipeline as a `data:text/html` module; the template reads the
|
|
358
|
+
// processed HTML from the nested module's `html` channel.
|
|
359
|
+
compilation.dependencyFactories.set(
|
|
360
|
+
HtmlInlineHtmlDependency,
|
|
361
|
+
normalModuleFactory
|
|
362
|
+
);
|
|
363
|
+
compilation.dependencyTemplates.set(
|
|
364
|
+
HtmlInlineHtmlDependency,
|
|
365
|
+
new HtmlInlineHtmlDependency.Template()
|
|
366
|
+
);
|
|
218
367
|
compilation.dependencyTemplates.set(
|
|
219
368
|
StaticExportsDependency,
|
|
220
369
|
new StaticExportsDependency.Template()
|
|
@@ -227,21 +376,26 @@ class HtmlModulesPlugin {
|
|
|
227
376
|
ConstDependency,
|
|
228
377
|
new ConstDependency.Template()
|
|
229
378
|
);
|
|
230
|
-
|
|
231
|
-
compiler.options.experiments && compiler.options.experiments.css
|
|
232
|
-
);
|
|
233
|
-
normalModuleFactory.hooks.createParser
|
|
379
|
+
normalModuleFactory.hooks.createModuleClass
|
|
234
380
|
.for(HTML_MODULE_TYPE)
|
|
235
381
|
.tap(
|
|
236
382
|
PLUGIN_NAME,
|
|
237
|
-
() =>
|
|
238
|
-
new HtmlParser(
|
|
239
|
-
compilation.outputOptions.hashFunction,
|
|
240
|
-
compiler.context,
|
|
241
|
-
compilation.outputOptions.module,
|
|
242
|
-
cssEnabled
|
|
243
|
-
)
|
|
383
|
+
(createData, _resolveData) => new HtmlModule(createData)
|
|
244
384
|
);
|
|
385
|
+
normalModuleFactory.hooks.createParser
|
|
386
|
+
.for(HTML_MODULE_TYPE)
|
|
387
|
+
.tap(PLUGIN_NAME, (parserOptions) => {
|
|
388
|
+
compiler.validate(
|
|
389
|
+
() => getSchema("HtmlParserOptions"),
|
|
390
|
+
parserOptions,
|
|
391
|
+
parserValidationOptions,
|
|
392
|
+
(options) =>
|
|
393
|
+
require("../../schemas/plugins/HtmlParserOptions.check")(
|
|
394
|
+
options
|
|
395
|
+
)
|
|
396
|
+
);
|
|
397
|
+
return new HtmlParser(parserOptions);
|
|
398
|
+
});
|
|
245
399
|
|
|
246
400
|
normalModuleFactory.hooks.createGenerator
|
|
247
401
|
.for(HTML_MODULE_TYPE)
|
|
@@ -263,8 +417,13 @@ class HtmlModulesPlugin {
|
|
|
263
417
|
(result, module) => {
|
|
264
418
|
if (module.type === HTML_MODULE_TYPE) {
|
|
265
419
|
const [source, ...rest] = result;
|
|
420
|
+
// `applyTemplate` is a no-op unless `module.parser.html.template`
|
|
421
|
+
// is set. Running it here (where the returned source becomes the
|
|
422
|
+
// module's stored source) keeps the parser's dependency offsets
|
|
423
|
+
// and the generator's render base in sync.
|
|
424
|
+
const parser = /** @type {HtmlParser} */ (module.parser);
|
|
266
425
|
|
|
267
|
-
return [removeBOM(source), ...rest];
|
|
426
|
+
return [parser.applyTemplate(removeBOM(source), module), ...rest];
|
|
268
427
|
}
|
|
269
428
|
|
|
270
429
|
return result;
|
|
@@ -296,11 +455,19 @@ class HtmlModulesPlugin {
|
|
|
296
455
|
getUndoPath,
|
|
297
456
|
makePathsRelative
|
|
298
457
|
} = require("../util/identifier");
|
|
299
|
-
const
|
|
300
|
-
|
|
301
|
-
|
|
458
|
+
const {
|
|
459
|
+
PUBLIC_PATH_AUTO: autoPlaceholder
|
|
460
|
+
} = require("../util/publicPathPlaceholder");
|
|
302
461
|
|
|
303
|
-
|
|
462
|
+
// Sentinel-resolved content and its content hash depend only on
|
|
463
|
+
// the HTML-type module source — not on the chunk or output
|
|
464
|
+
// filename — yet `renderManifest` runs per `(chunk, module)`.
|
|
465
|
+
// Memoize so a module landing in multiple chunks resolves and
|
|
466
|
+
// hashes its sentinels once. Scoped to this compilation because
|
|
467
|
+
// sentinel resolution embeds chunk filenames, which change
|
|
468
|
+
// across rebuilds; weakly keyed by source so entries release.
|
|
469
|
+
/** @type {WeakMap<import("webpack-sources").Source, { resolvedContent: string, contentHash: string }>} */
|
|
470
|
+
const resolvedSentinelHashCache = new WeakMap();
|
|
304
471
|
|
|
305
472
|
compilation.hooks.renderManifest.tap(
|
|
306
473
|
PLUGIN_NAME,
|
|
@@ -328,32 +495,56 @@ class HtmlModulesPlugin {
|
|
|
328
495
|
const placeholderSource = codeGenResult.sources.get(HTML_TYPE);
|
|
329
496
|
if (!placeholderSource) continue;
|
|
330
497
|
|
|
498
|
+
// `<iframe srcdoc>` modules expose `html` only so
|
|
499
|
+
// HtmlInlineHtmlDependency can write the processed markup back
|
|
500
|
+
// into the host attribute — they are never standalone pages.
|
|
501
|
+
// `generator.extract: "inline"` marks them so no `.html` file is
|
|
502
|
+
// emitted; without this they'd collide on the `data:text/html`
|
|
503
|
+
// → chunk-name path below (every srcdoc module in a chunk would
|
|
504
|
+
// emit `<chunk>.html`). An O(1) flag check, not a scan.
|
|
505
|
+
const generatorOptions = normalModule.generatorOptions;
|
|
506
|
+
if (generatorOptions && generatorOptions.extract === "inline") {
|
|
507
|
+
continue;
|
|
508
|
+
}
|
|
509
|
+
|
|
331
510
|
const filenameTemplate = chunk.canBeInitial()
|
|
332
511
|
? outputOptions.htmlFilename
|
|
333
512
|
: outputOptions.htmlChunkFilename;
|
|
334
513
|
|
|
335
|
-
const
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
514
|
+
const resource =
|
|
515
|
+
normalModule.getResource() || normalModule.resource;
|
|
516
|
+
// Synthetic `output.html` entries are `data:text/html` modules
|
|
517
|
+
// with no real basename — name the file after the entry instead.
|
|
518
|
+
const sourceFilename =
|
|
519
|
+
resource.startsWith("data:text/html") && chunk.name
|
|
520
|
+
? chunk.name
|
|
521
|
+
: makePathsRelative(
|
|
522
|
+
compiler.context,
|
|
523
|
+
/** @type {string} */ (resource),
|
|
524
|
+
compiler.root
|
|
525
|
+
).replace(/^\.\//, "");
|
|
341
526
|
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
527
|
+
let cached = resolvedSentinelHashCache.get(placeholderSource);
|
|
528
|
+
if (cached === undefined) {
|
|
529
|
+
const placeholderContent = /** @type {string} */ (
|
|
530
|
+
placeholderSource.source()
|
|
531
|
+
);
|
|
532
|
+
// Resolve sentinels *before* hashing so the HTML's `[contenthash]`
|
|
533
|
+
// invalidates with the referenced chunks' filenames.
|
|
534
|
+
const resolvedContent = HtmlGenerator.resolveChunkUrlSentinels(
|
|
535
|
+
placeholderContent,
|
|
536
|
+
compilation
|
|
537
|
+
);
|
|
538
|
+
cached = {
|
|
539
|
+
resolvedContent,
|
|
540
|
+
contentHash: HtmlModulesPlugin.computeContentHash(
|
|
541
|
+
resolvedContent,
|
|
542
|
+
outputOptions
|
|
543
|
+
)
|
|
544
|
+
};
|
|
545
|
+
resolvedSentinelHashCache.set(placeholderSource, cached);
|
|
348
546
|
}
|
|
349
|
-
|
|
350
|
-
const fullContentHash = /** @type {string} */ (
|
|
351
|
-
hashInput.digest(outputOptions.hashDigest)
|
|
352
|
-
);
|
|
353
|
-
const contentHash = nonNumericOnlyHash(
|
|
354
|
-
fullContentHash,
|
|
355
|
-
outputOptions.hashDigestLength
|
|
356
|
-
);
|
|
547
|
+
const { resolvedContent, contentHash } = cached;
|
|
357
548
|
|
|
358
549
|
const { path: filename, info } = compilation.getPathWithInfo(
|
|
359
550
|
/** @type {import("../TemplatedPathPlugin").TemplatePath} */
|
|
@@ -382,7 +573,7 @@ class HtmlModulesPlugin {
|
|
|
382
573
|
/** @type {string} */ (outputOptions.path),
|
|
383
574
|
false
|
|
384
575
|
);
|
|
385
|
-
const finalContent =
|
|
576
|
+
const finalContent = resolvedContent
|
|
386
577
|
.split(autoPlaceholder)
|
|
387
578
|
.join(undoPath);
|
|
388
579
|
const finalSource = new RawSource(finalContent);
|
|
@@ -395,16 +586,9 @@ class HtmlModulesPlugin {
|
|
|
395
586
|
// the post-undo-path content in the hash, so the
|
|
396
587
|
// asset cache can't reuse one variant's bytes at
|
|
397
588
|
// another variant's URL.
|
|
398
|
-
const
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
}
|
|
402
|
-
finalHash.update(finalContent);
|
|
403
|
-
const finalContentHash = nonNumericOnlyHash(
|
|
404
|
-
/** @type {string} */ (
|
|
405
|
-
finalHash.digest(outputOptions.hashDigest)
|
|
406
|
-
),
|
|
407
|
-
outputOptions.hashDigestLength
|
|
589
|
+
const finalContentHash = HtmlModulesPlugin.computeContentHash(
|
|
590
|
+
finalContent,
|
|
591
|
+
outputOptions
|
|
408
592
|
);
|
|
409
593
|
|
|
410
594
|
result.push({
|
|
@@ -421,6 +605,49 @@ class HtmlModulesPlugin {
|
|
|
421
605
|
return result;
|
|
422
606
|
}
|
|
423
607
|
);
|
|
608
|
+
|
|
609
|
+
// Resolve sentinels at JS chunk render time so later passes
|
|
610
|
+
// (SourceMapDevToolPlugin, size optimizers, RealContentHash) see resolved bytes.
|
|
611
|
+
const JavascriptModulesPlugin = require("../javascript/JavascriptModulesPlugin");
|
|
612
|
+
|
|
613
|
+
const jsHooks =
|
|
614
|
+
JavascriptModulesPlugin.getCompilationHooks(compilation);
|
|
615
|
+
jsHooks.render.tap(PLUGIN_NAME, (source, renderContext) => {
|
|
616
|
+
const raw = source.source();
|
|
617
|
+
if (typeof raw !== "string") return source;
|
|
618
|
+
if (!raw.includes("__WEBPACK_HTML_CHUNK_URL__")) return source;
|
|
619
|
+
const resolved = HtmlGenerator.resolveChunkUrlSentinels(
|
|
620
|
+
raw,
|
|
621
|
+
compilation
|
|
622
|
+
)
|
|
623
|
+
.split(autoPlaceholder)
|
|
624
|
+
.join("");
|
|
625
|
+
if (resolved === raw) return source;
|
|
626
|
+
const chunkId = String(renderContext.chunk.id);
|
|
627
|
+
const prior = sentinelResolvedSourceCache.get(chunkId);
|
|
628
|
+
if (prior !== undefined && prior.content === resolved) {
|
|
629
|
+
return prior.source;
|
|
630
|
+
}
|
|
631
|
+
const newSource = new RawSource(resolved);
|
|
632
|
+
sentinelResolvedSourceCache.set(chunkId, {
|
|
633
|
+
content: resolved,
|
|
634
|
+
source: newSource
|
|
635
|
+
});
|
|
636
|
+
return newSource;
|
|
637
|
+
});
|
|
638
|
+
|
|
639
|
+
// Prune cache entries for chunks no longer in the graph so a
|
|
640
|
+
// long watch session can't accumulate stale entries.
|
|
641
|
+
compilation.hooks.afterSeal.tap(PLUGIN_NAME, () => {
|
|
642
|
+
if (sentinelResolvedSourceCache.size === 0) return;
|
|
643
|
+
const live = new Set();
|
|
644
|
+
for (const chunk of compilation.chunks) {
|
|
645
|
+
live.add(String(chunk.id));
|
|
646
|
+
}
|
|
647
|
+
for (const id of sentinelResolvedSourceCache.keys()) {
|
|
648
|
+
if (!live.has(id)) sentinelResolvedSourceCache.delete(id);
|
|
649
|
+
}
|
|
650
|
+
});
|
|
424
651
|
}
|
|
425
652
|
);
|
|
426
653
|
}
|