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
|
@@ -13,10 +13,13 @@ const {
|
|
|
13
13
|
JAVASCRIPT_TYPES
|
|
14
14
|
} = require("../ModuleSourceTypeConstants");
|
|
15
15
|
const RuntimeGlobals = require("../RuntimeGlobals");
|
|
16
|
-
const
|
|
16
|
+
const Template = require("../Template");
|
|
17
|
+
const { PUBLIC_PATH_AUTO } = require("../util/publicPathPlaceholder");
|
|
17
18
|
|
|
18
19
|
/** @typedef {import("webpack-sources").Source} Source */
|
|
19
20
|
/** @typedef {import("../../declarations/WebpackOptions").HtmlGeneratorOptions} HtmlGeneratorOptions */
|
|
21
|
+
/** @typedef {import("../Chunk")} Chunk */
|
|
22
|
+
/** @typedef {import("../Compilation")} Compilation */
|
|
20
23
|
/** @typedef {import("../Compilation").DependencyConstructor} DependencyConstructor */
|
|
21
24
|
/** @typedef {import("../CodeGenerationResults")} CodeGenerationResults */
|
|
22
25
|
/** @typedef {import("../Dependency")} Dependency */
|
|
@@ -28,6 +31,8 @@ const CssUrlDependency = require("../dependencies/CssUrlDependency");
|
|
|
28
31
|
/** @typedef {import("../Module").ConcatenationBailoutReasonContext} ConcatenationBailoutReasonContext */
|
|
29
32
|
/** @typedef {import("../ModuleGraph")} ModuleGraph */
|
|
30
33
|
/** @typedef {import("../NormalModule")} NormalModule */
|
|
34
|
+
/** @typedef {import("../Module").RuntimeRequirements} RuntimeRequirements */
|
|
35
|
+
/** @typedef {import("../RuntimeTemplate")} RuntimeTemplate */
|
|
31
36
|
/** @typedef {import("../util/Hash")} Hash */
|
|
32
37
|
/**
|
|
33
38
|
* @template T
|
|
@@ -39,7 +44,82 @@ const CssUrlDependency = require("../dependencies/CssUrlDependency");
|
|
|
39
44
|
*/
|
|
40
45
|
const JAVASCRIPT_AND_HTML_TYPES = new Set([JAVASCRIPT_TYPE, HTML_TYPE]);
|
|
41
46
|
|
|
47
|
+
/** @type {WeakMap<Compilation, Map<string, Chunk>>} */
|
|
48
|
+
const chunksByIdCache = new WeakMap();
|
|
49
|
+
|
|
50
|
+
// Hoisted so `resolveChunkUrlSentinels` (per chunk × module) doesn't allocate a
|
|
51
|
+
// fresh `RegExp` each call. `String#replace` resets `lastIndex`, so sharing the
|
|
52
|
+
// global-flag instance is safe under these synchronous, non-reentrant calls.
|
|
53
|
+
const CHUNK_URL_SENTINEL_REGEXP =
|
|
54
|
+
/__WEBPACK_HTML_CHUNK_URL__([0-9a-f]+)__([a-z]+)__END__/g;
|
|
55
|
+
|
|
42
56
|
class HtmlGenerator extends Generator {
|
|
57
|
+
/**
|
|
58
|
+
* Emit a sentinel for a chunk URL that can't be resolved at code-gen time
|
|
59
|
+
* (chunk hashes aren't computed yet); `resolveChunkUrlSentinels` swaps it
|
|
60
|
+
* for `${PUBLIC_PATH_AUTO}<chunkFilename>` once they are.
|
|
61
|
+
* @param {Chunk} chunk chunk
|
|
62
|
+
* @param {"javascript" | "css"} contentHashType which chunk content hash slot the resolved URL should reference
|
|
63
|
+
* @returns {string} sentinel
|
|
64
|
+
*/
|
|
65
|
+
static makeChunkUrlSentinel(chunk, contentHashType) {
|
|
66
|
+
const hexId = Buffer.from(String(chunk.id), "utf8").toString("hex");
|
|
67
|
+
return `__WEBPACK_HTML_CHUNK_URL__${hexId}__${contentHashType}__END__`;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Replace every `makeChunkUrlSentinel` sentinel in `content` with
|
|
72
|
+
* `${PUBLIC_PATH_AUTO}<chunkFilename>`. Must run after
|
|
73
|
+
* `Compilation#createHash()` so `[contenthash]` resolves.
|
|
74
|
+
* @param {string} content content
|
|
75
|
+
* @param {Compilation} compilation compilation
|
|
76
|
+
* @returns {string} resolved content
|
|
77
|
+
*/
|
|
78
|
+
static resolveChunkUrlSentinels(content, compilation) {
|
|
79
|
+
if (!content.includes("__WEBPACK_HTML_CHUNK_URL__")) return content;
|
|
80
|
+
const outputOptions = compilation.outputOptions;
|
|
81
|
+
let chunksById = chunksByIdCache.get(compilation);
|
|
82
|
+
if (chunksById === undefined) {
|
|
83
|
+
chunksById = new Map();
|
|
84
|
+
for (const chunk of compilation.chunks) {
|
|
85
|
+
chunksById.set(String(chunk.id), chunk);
|
|
86
|
+
}
|
|
87
|
+
chunksByIdCache.set(compilation, chunksById);
|
|
88
|
+
}
|
|
89
|
+
return content.replace(
|
|
90
|
+
CHUNK_URL_SENTINEL_REGEXP,
|
|
91
|
+
(_, hexId, contentHashType) => {
|
|
92
|
+
const chunkId = Buffer.from(hexId, "hex").toString("utf8");
|
|
93
|
+
const chunk = chunksById.get(chunkId);
|
|
94
|
+
if (!chunk) return "data:,";
|
|
95
|
+
let filenameTemplate;
|
|
96
|
+
if (contentHashType === "css") {
|
|
97
|
+
const CssModulesPlugin = require("../css/CssModulesPlugin");
|
|
98
|
+
|
|
99
|
+
filenameTemplate = CssModulesPlugin.getChunkFilenameTemplate(
|
|
100
|
+
chunk,
|
|
101
|
+
outputOptions
|
|
102
|
+
);
|
|
103
|
+
} else {
|
|
104
|
+
filenameTemplate =
|
|
105
|
+
chunk.filenameTemplate ||
|
|
106
|
+
(chunk.canBeInitial()
|
|
107
|
+
? outputOptions.filename
|
|
108
|
+
: outputOptions.chunkFilename);
|
|
109
|
+
}
|
|
110
|
+
const filename = compilation.getPath(
|
|
111
|
+
/** @type {import("../TemplatedPathPlugin").TemplatePath} */
|
|
112
|
+
(filenameTemplate),
|
|
113
|
+
{
|
|
114
|
+
chunk,
|
|
115
|
+
contentHashType
|
|
116
|
+
}
|
|
117
|
+
);
|
|
118
|
+
return `${PUBLIC_PATH_AUTO}${filename}`;
|
|
119
|
+
}
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
|
|
43
123
|
/**
|
|
44
124
|
* Creates an instance of HtmlGenerator.
|
|
45
125
|
* @param {HtmlGeneratorOptions=} options generator options
|
|
@@ -47,9 +127,18 @@ class HtmlGenerator extends Generator {
|
|
|
47
127
|
*/
|
|
48
128
|
constructor(options, moduleGraph) {
|
|
49
129
|
super();
|
|
130
|
+
/** @type {HtmlGeneratorOptions} */
|
|
50
131
|
this.options = options || {};
|
|
51
132
|
/** @type {ModuleGraph | undefined} */
|
|
52
133
|
this._moduleGraph = moduleGraph;
|
|
134
|
+
// Raw dependency-template render (before `[webpack/auto]` resolution),
|
|
135
|
+
// shared between the JS and HTML type passes of a single
|
|
136
|
+
// `codeGeneration()` call. Keyed by that call's `runtimeRequirements`
|
|
137
|
+
// Set — created once per call and passed to every type's `generate()`,
|
|
138
|
+
// so it uniquely scopes the cache to one module's one code generation
|
|
139
|
+
// and releases with it. The two passes differ only in `undoPath`.
|
|
140
|
+
/** @type {WeakMap<RuntimeRequirements, string>} */
|
|
141
|
+
this._rawRenderCache = new WeakMap();
|
|
53
142
|
}
|
|
54
143
|
|
|
55
144
|
/**
|
|
@@ -59,6 +148,14 @@ class HtmlGenerator extends Generator {
|
|
|
59
148
|
* @returns {string | undefined} reason why this module can't be concatenated, undefined when it can be concatenated
|
|
60
149
|
*/
|
|
61
150
|
getConcatenationBailoutReason(module, context) {
|
|
151
|
+
// The HMR shim references the per-module `module.hot` object — when an
|
|
152
|
+
// HTML module is concatenated, that scope is gone (the merged file
|
|
153
|
+
// shares a single `module`), so the self-accept / DOM-patch wiring
|
|
154
|
+
// would target the wrong module id. Bail out of concatenation so the
|
|
155
|
+
// HMR-aware HTML module keeps its own module scope.
|
|
156
|
+
if (module.hot) {
|
|
157
|
+
return "HTML module needs its own module scope for HMR";
|
|
158
|
+
}
|
|
62
159
|
return undefined;
|
|
63
160
|
}
|
|
64
161
|
|
|
@@ -79,31 +176,53 @@ class HtmlGenerator extends Generator {
|
|
|
79
176
|
|
|
80
177
|
/**
|
|
81
178
|
* Whether to emit the extracted `.html` file for this module.
|
|
82
|
-
* `options.extract === true` always extracts; `false` never;
|
|
83
|
-
* option is left unspecified, extraction defaults to on for HTML
|
|
84
|
-
* used as compilation entries — that's the HTML-as-entry-point
|
|
179
|
+
* `options.extract === true` always extracts; `false` and `"inline"` never;
|
|
180
|
+
* when the option is left unspecified, extraction defaults to on for HTML
|
|
181
|
+
* modules used as compilation entries — that's the HTML-as-entry-point case.
|
|
85
182
|
* @param {NormalModule} module module
|
|
86
183
|
* @returns {boolean} true when the `.html` file should be emitted
|
|
87
184
|
*/
|
|
88
185
|
_shouldExtract(module) {
|
|
89
186
|
const { extract } = this.options;
|
|
90
187
|
if (extract === true) return true;
|
|
91
|
-
if (extract === false) return false;
|
|
188
|
+
if (extract === false || extract === "inline") return false;
|
|
92
189
|
return this._isEntryModule(module);
|
|
93
190
|
}
|
|
94
191
|
|
|
192
|
+
/**
|
|
193
|
+
* Whether this module exposes the `html` source type. Like `_shouldExtract`,
|
|
194
|
+
* but `"inline"` also exposes it — the processed HTML is read back into the
|
|
195
|
+
* host attribute (e.g. `<iframe srcdoc>`) instead of emitted as a file.
|
|
196
|
+
* @param {NormalModule} module module
|
|
197
|
+
* @returns {boolean} true when the `html` source type is available
|
|
198
|
+
*/
|
|
199
|
+
_shouldExposeHtmlType(module) {
|
|
200
|
+
if (this.options.extract === "inline") return true;
|
|
201
|
+
return this._shouldExtract(module);
|
|
202
|
+
}
|
|
203
|
+
|
|
95
204
|
/**
|
|
96
205
|
* Returns the source types available for this module.
|
|
97
206
|
* @param {NormalModule} module fresh module
|
|
98
207
|
* @returns {SourceTypes} available types (do not mutate)
|
|
99
208
|
*/
|
|
100
209
|
getTypes(module) {
|
|
101
|
-
if (this.
|
|
210
|
+
if (this._shouldExposeHtmlType(module)) {
|
|
102
211
|
return JAVASCRIPT_AND_HTML_TYPES;
|
|
103
212
|
}
|
|
104
213
|
return JAVASCRIPT_TYPES;
|
|
105
214
|
}
|
|
106
215
|
|
|
216
|
+
/**
|
|
217
|
+
* @returns {boolean} whether getTypes() depends on the module's incoming connections
|
|
218
|
+
*/
|
|
219
|
+
getTypesDependOnIncomingConnections() {
|
|
220
|
+
// A fixed extract (`true` / `false` / `"inline"`) gives a stable type set;
|
|
221
|
+
// only the unset default reads `_isEntryModule` (incoming connections).
|
|
222
|
+
const { extract } = this.options;
|
|
223
|
+
return extract !== true && extract !== false && extract !== "inline";
|
|
224
|
+
}
|
|
225
|
+
|
|
107
226
|
/**
|
|
108
227
|
* Returns the estimated size for the requested source type.
|
|
109
228
|
* @param {NormalModule} module the module
|
|
@@ -260,36 +379,31 @@ class HtmlGenerator extends Generator {
|
|
|
260
379
|
* @returns {string} the rewritten HTML
|
|
261
380
|
*/
|
|
262
381
|
_renderHtml(module, generateContext, undoPath) {
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
this.
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
382
|
+
// The dependency-template pass is identical for both type passes (no
|
|
383
|
+
// template branches on `type` or writes `runtimeRequirements`), so
|
|
384
|
+
// compute the raw render once per `codeGeneration()` and reuse it; the
|
|
385
|
+
// passes diverge only in the `[webpack/auto]` substitution below.
|
|
386
|
+
const cacheKey = generateContext.runtimeRequirements;
|
|
387
|
+
let rawContent = this._rawRenderCache.get(cacheKey);
|
|
388
|
+
if (rawContent === undefined) {
|
|
389
|
+
const originalSource = /** @type {Source} */ (module.originalSource());
|
|
390
|
+
const source = new ReplaceSource(originalSource);
|
|
391
|
+
/** @type {InitFragment<GenerateContext>[]} */
|
|
392
|
+
const initFragments = [];
|
|
393
|
+
|
|
394
|
+
this.sourceModule(module, initFragments, source, generateContext);
|
|
395
|
+
rawContent = /** @type {string} */ (source.source());
|
|
396
|
+
this._rawRenderCache.set(cacheKey, rawContent);
|
|
272
397
|
}
|
|
273
398
|
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
const autoPlaceholder = CssUrlDependency.PUBLIC_PATH_AUTO;
|
|
278
|
-
const autoPlaceholderLen = autoPlaceholder.length;
|
|
279
|
-
for (
|
|
280
|
-
let idx = moduleSourceContent.indexOf(autoPlaceholder);
|
|
281
|
-
idx !== -1;
|
|
282
|
-
idx = moduleSourceContent.indexOf(
|
|
283
|
-
autoPlaceholder,
|
|
284
|
-
idx + autoPlaceholderLen
|
|
285
|
-
)
|
|
286
|
-
) {
|
|
287
|
-
generatedSource.replace(idx, idx + autoPlaceholderLen - 1, undoPath);
|
|
399
|
+
if (undoPath === undefined) {
|
|
400
|
+
// HTML output — leave sentinels and `[webpack/auto]` for renderManifest.
|
|
401
|
+
return rawContent;
|
|
288
402
|
}
|
|
289
403
|
|
|
290
|
-
//
|
|
291
|
-
|
|
292
|
-
return
|
|
404
|
+
// JS-export path — resolve `[webpack/auto]` inline; chunk-URL sentinels
|
|
405
|
+
// stay for `HtmlModulesPlugin`'s `JavascriptModulesPlugin.render` tap.
|
|
406
|
+
return rawContent.split(PUBLIC_PATH_AUTO).join(undoPath);
|
|
293
407
|
}
|
|
294
408
|
|
|
295
409
|
/**
|
|
@@ -306,21 +420,23 @@ class HtmlGenerator extends Generator {
|
|
|
306
420
|
}
|
|
307
421
|
|
|
308
422
|
if (generateContext.type === HTML_TYPE) {
|
|
309
|
-
// Preserve `[webpack/auto]
|
|
310
|
-
// `renderManifest` hook knows the final `.html` filename and
|
|
311
|
-
// resolves them to an undo path relative to that location.
|
|
423
|
+
// Preserve `[webpack/auto]`; renderManifest resolves it once `.html` filename is known.
|
|
312
424
|
return new RawSource(
|
|
313
425
|
this._renderHtml(module, generateContext, undefined)
|
|
314
426
|
);
|
|
315
427
|
}
|
|
316
428
|
|
|
317
|
-
// JS export:
|
|
318
|
-
// runtime, so resolve placeholders to root-relative URLs.
|
|
429
|
+
// JS export: resolve `[webpack/auto]` to root-relative URLs.
|
|
319
430
|
const generated = this._renderHtml(module, generateContext, "");
|
|
320
431
|
|
|
321
432
|
/** @type {string} */
|
|
322
433
|
let sourceContent;
|
|
323
|
-
|
|
434
|
+
// `module.hot` is set by `HotModuleReplacementPlugin` on every module
|
|
435
|
+
// when HMR is enabled. When set, we cannot use the concatenation path
|
|
436
|
+
// (it merges into a parent's module scope, where `module.hot.accept`
|
|
437
|
+
// would target the wrong id) — `getConcatenationBailoutReason` keeps
|
|
438
|
+
// us out of concatenation in that case.
|
|
439
|
+
if (generateContext.concatenationScope && !module.hot) {
|
|
324
440
|
generateContext.concatenationScope.registerNamespaceExport(
|
|
325
441
|
ConcatenationScope.NAMESPACE_OBJECT_EXPORT
|
|
326
442
|
);
|
|
@@ -329,14 +445,136 @@ class HtmlGenerator extends Generator {
|
|
|
329
445
|
} = ${JSON.stringify(generated)};`;
|
|
330
446
|
} else {
|
|
331
447
|
generateContext.runtimeRequirements.add(RuntimeGlobals.module);
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
448
|
+
if (module.hot) {
|
|
449
|
+
sourceContent = this._renderHmrShim(
|
|
450
|
+
module,
|
|
451
|
+
generated,
|
|
452
|
+
this._shouldExtract(module),
|
|
453
|
+
generateContext.runtimeTemplate
|
|
454
|
+
);
|
|
455
|
+
} else {
|
|
456
|
+
sourceContent = `${module.moduleArgument}.exports = ${JSON.stringify(
|
|
457
|
+
generated
|
|
458
|
+
)};`;
|
|
459
|
+
}
|
|
335
460
|
}
|
|
336
461
|
|
|
337
462
|
return new RawSource(sourceContent);
|
|
338
463
|
}
|
|
339
464
|
|
|
465
|
+
/**
|
|
466
|
+
* Emits the JS shim with HMR self-acceptance. When `extracting` is true the
|
|
467
|
+
* HTML module is also the document the browser is viewing, so the shim
|
|
468
|
+
* additionally patches `document.body` and `document.title` on every hot
|
|
469
|
+
* update so the rendered page reflects the new HTML without a full
|
|
470
|
+
* reload. The patching guard `module.hot.data` ensures the body is only
|
|
471
|
+
* replaced on a re-evaluation after a hot update — never on the initial
|
|
472
|
+
* page load, where `document.body` already matches the extracted HTML.
|
|
473
|
+
*
|
|
474
|
+
* The runtime extracts the body / title / head-sans-title sections from
|
|
475
|
+
* the HTML with regexes. HTML comments are *masked* first — their
|
|
476
|
+
* characters replaced with spaces, preserving length — via a `<!--…-->`
|
|
477
|
+
* regex, so a `<body>` (or `</body>` / `<title>` / etc.) that appears
|
|
478
|
+
* inside a comment can't fool the tag regexes — that was the one
|
|
479
|
+
* well-known sharp edge of HTML+regex. Because masking keeps offsets
|
|
480
|
+
* stable, the body / title content is sliced back out of the *original*
|
|
481
|
+
* HTML, so real comments inside `<body>` survive into the patched DOM
|
|
482
|
+
* exactly as a full page reload would render them.
|
|
483
|
+
*
|
|
484
|
+
* `<head>` changes beyond `<title>` (a new `<meta>`, a swapped
|
|
485
|
+
* `<link rel=icon>`, an inline `<style>` block, …) can't be safely
|
|
486
|
+
* DOM-patched: webpack injects its own runtime scripts and stylesheet
|
|
487
|
+
* links into the head on initial load, and blindly replacing
|
|
488
|
+
* `document.head.innerHTML` would tear them down. So the shim falls
|
|
489
|
+
* back to a full reload — fine in a dev-server context because the
|
|
490
|
+
* regular (non-hot-update) `page.html` chunk is re-emitted on every
|
|
491
|
+
* rebuild, so the reloaded page picks up the new head.
|
|
492
|
+
* @param {NormalModule} module module
|
|
493
|
+
* @param {string} html the rewritten HTML content (with placeholders resolved)
|
|
494
|
+
* @param {boolean} extracting whether the HTML module is being extracted as a real `.html` file
|
|
495
|
+
* @param {RuntimeTemplate} runtimeTemplate runtime template (drives `const`/arrow emission based on environment support)
|
|
496
|
+
* @returns {string} JS shim source
|
|
497
|
+
*/
|
|
498
|
+
_renderHmrShim(module, html, extracting, runtimeTemplate) {
|
|
499
|
+
const declare = runtimeTemplate.renderConst();
|
|
500
|
+
const acceptBlock = extracting
|
|
501
|
+
? [
|
|
502
|
+
"module.hot.accept();",
|
|
503
|
+
// Mask `<!-- … -->` comments — replace their characters
|
|
504
|
+
// with spaces, preserving length — before any tag regex
|
|
505
|
+
// runs. Masking (rather than deleting) keeps string offsets
|
|
506
|
+
// stable, so the body/title content can be sliced back out
|
|
507
|
+
// of the original HTML with comments intact, while a
|
|
508
|
+
// `<body>`/`</body>`/`<title>` inside a comment can no
|
|
509
|
+
// longer fool the tag regexes (the non-greedy `*?` would
|
|
510
|
+
// otherwise stop at the FIRST `</body>` it sees, even one
|
|
511
|
+
// inside a comment).
|
|
512
|
+
`${declare} __webpack_mask_comments__ = ${runtimeTemplate.returningFunction(
|
|
513
|
+
`h.replace(/<!--[\\s\\S]*?-->/g, ${runtimeTemplate.returningFunction(
|
|
514
|
+
'c.replace(/[^\\n]/g, " ")',
|
|
515
|
+
"c"
|
|
516
|
+
)})`,
|
|
517
|
+
"h"
|
|
518
|
+
)};`,
|
|
519
|
+
// Mask comments once per evaluation; reused for every
|
|
520
|
+
// tag-boundary search (head/body/title and the dispose-time
|
|
521
|
+
// head diff) so a large page isn't re-scanned per section.
|
|
522
|
+
`${declare} __webpack_masked_html__ = __webpack_mask_comments__(__webpack_html__);`,
|
|
523
|
+
// Slice the inner content of `<tag>…</tag>` out of the original
|
|
524
|
+
// HTML, using the pre-masked copy to locate the tag boundaries.
|
|
525
|
+
`${declare} __webpack_extract__ = ${runtimeTemplate.basicFunction(
|
|
526
|
+
"tag",
|
|
527
|
+
[
|
|
528
|
+
`${declare} open = new RegExp("<" + tag + "[^>]*>", "i").exec(__webpack_masked_html__);`,
|
|
529
|
+
"if (!open) return null;",
|
|
530
|
+
`${declare} start = open.index + open[0].length;`,
|
|
531
|
+
`${declare} close = new RegExp("</" + tag + ">", "i").exec(__webpack_masked_html__.slice(start));`,
|
|
532
|
+
"if (!close) return null;",
|
|
533
|
+
"return __webpack_html__.slice(start, start + close.index);"
|
|
534
|
+
]
|
|
535
|
+
)};`,
|
|
536
|
+
`${declare} __webpack_extract_head__ = ${runtimeTemplate.basicFunction(
|
|
537
|
+
"",
|
|
538
|
+
[
|
|
539
|
+
// Mask only the small extracted head so a comment-only head
|
|
540
|
+
// edit doesn't force a full reload.
|
|
541
|
+
`${declare} head = __webpack_extract__("head");`,
|
|
542
|
+
'return head === null ? "" : __webpack_mask_comments__(head).replace(/<title[^>]*>[\\s\\S]*?<\\/title>/i, "").trim();'
|
|
543
|
+
]
|
|
544
|
+
)};`,
|
|
545
|
+
"if (module.hot.data && typeof document !== 'undefined') {",
|
|
546
|
+
Template.indent([
|
|
547
|
+
`${declare} __webpack_new_head__ = __webpack_extract_head__();`,
|
|
548
|
+
"if (module.hot.data.__webpack_head__ !== undefined && __webpack_new_head__ !== module.hot.data.__webpack_head__ && typeof window !== 'undefined' && window.location && typeof window.location.reload === 'function') {",
|
|
549
|
+
Template.indent("window.location.reload();"),
|
|
550
|
+
"} else {",
|
|
551
|
+
Template.indent([
|
|
552
|
+
`${declare} __webpack_body__ = __webpack_extract__("body");`,
|
|
553
|
+
"if (__webpack_body__ !== null && document.body) document.body.innerHTML = __webpack_body__;",
|
|
554
|
+
`${declare} __webpack_title__ = __webpack_extract__("title");`,
|
|
555
|
+
"if (__webpack_title__ !== null) document.title = __webpack_title__;"
|
|
556
|
+
]),
|
|
557
|
+
"}"
|
|
558
|
+
]),
|
|
559
|
+
"}",
|
|
560
|
+
// Capture this evaluation's head (sans title, comments
|
|
561
|
+
// masked) on dispose so the next module instance can diff
|
|
562
|
+
// against it.
|
|
563
|
+
`module.hot.dispose(${runtimeTemplate.basicFunction(
|
|
564
|
+
"data",
|
|
565
|
+
"data.__webpack_head__ = __webpack_extract_head__();"
|
|
566
|
+
)});`
|
|
567
|
+
]
|
|
568
|
+
: ["module.hot.accept();"];
|
|
569
|
+
return Template.asString([
|
|
570
|
+
`${declare} __webpack_html__ = ${JSON.stringify(html)};`,
|
|
571
|
+
`${module.moduleArgument}.exports = __webpack_html__;`,
|
|
572
|
+
"if (module.hot) {",
|
|
573
|
+
Template.indent(acceptBlock),
|
|
574
|
+
"}"
|
|
575
|
+
]);
|
|
576
|
+
}
|
|
577
|
+
|
|
340
578
|
/**
|
|
341
579
|
* Generates fallback output for the provided error condition.
|
|
342
580
|
* @param {Error} error the error
|
|
@@ -346,10 +584,7 @@ class HtmlGenerator extends Generator {
|
|
|
346
584
|
*/
|
|
347
585
|
generateError(error, module, generateContext) {
|
|
348
586
|
if (generateContext.type === HTML_TYPE) {
|
|
349
|
-
//
|
|
350
|
-
// input, dep request strings). Strip `<`, `>`, and `--` runs so a
|
|
351
|
-
// crafted message can't close the comment with `-->` (or open a
|
|
352
|
-
// fake nested comment) and inject HTML into the extracted page.
|
|
587
|
+
// Strip `<`, `>`, `--` runs from `error.message` so it can't escape the comment.
|
|
353
588
|
const safe = String(error.message)
|
|
354
589
|
.replace(/[<>]/g, "")
|
|
355
590
|
.replace(/-{2,}/g, (m) => `${"-".repeat(m.length - 1)} `);
|
|
@@ -365,14 +600,21 @@ class HtmlGenerator extends Generator {
|
|
|
365
600
|
*/
|
|
366
601
|
updateHash(hash, updateHashContext) {
|
|
367
602
|
hash.update("html");
|
|
368
|
-
//
|
|
369
|
-
//
|
|
370
|
-
//
|
|
371
|
-
|
|
372
|
-
|
|
603
|
+
// Source-type set changes when html-type exposure flips; the HMR shim's
|
|
604
|
+
// `extracting` branch changes when the emit decision flips. They differ
|
|
605
|
+
// only for `"inline"` (exposes html, but does not emit), so hash both.
|
|
606
|
+
if (this._shouldExposeHtmlType(updateHashContext.module)) {
|
|
607
|
+
hash.update("html-type");
|
|
608
|
+
}
|
|
373
609
|
if (this._shouldExtract(updateHashContext.module)) {
|
|
374
610
|
hash.update("extract");
|
|
375
611
|
}
|
|
612
|
+
// The HMR shim emits additional self-accept / DOM-patch code that
|
|
613
|
+
// isn't emitted in non-HMR builds, so the cached codegen must
|
|
614
|
+
// invalidate when `module.hot` toggles.
|
|
615
|
+
if (updateHashContext.module.hot) {
|
|
616
|
+
hash.update("hot");
|
|
617
|
+
}
|
|
376
618
|
}
|
|
377
619
|
}
|
|
378
620
|
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/*
|
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
"use strict";
|
|
6
|
+
|
|
7
|
+
const NormalModule = require("../NormalModule");
|
|
8
|
+
const makeSerializable = require("../util/makeSerializable");
|
|
9
|
+
|
|
10
|
+
/** @typedef {import("../NormalModule").NormalModuleBuildInfo} NormalModuleBuildInfo */
|
|
11
|
+
/** @typedef {import("../NormalModule").NormalModuleCreateData} NormalModuleCreateData */
|
|
12
|
+
/** @typedef {import("./HtmlModulesPlugin").EntryScriptInfo} EntryScriptInfo */
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Defines the build info properties specific to html modules.
|
|
16
|
+
* @typedef {object} KnownHtmlModuleBuildInfo
|
|
17
|
+
* @property {Record<string, EntryScriptInfo[]>=} htmlEntryScripts entries collected from the document, grouped by kind
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
/** @typedef {NormalModuleBuildInfo & KnownHtmlModuleBuildInfo} HtmlModuleBuildInfo */
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Module class for `html` modules. HTML-specific properties should live here instead of `NormalModule`.
|
|
24
|
+
*/
|
|
25
|
+
class HtmlModule extends NormalModule {
|
|
26
|
+
/**
|
|
27
|
+
* @param {NormalModuleCreateData} options options object
|
|
28
|
+
*/
|
|
29
|
+
constructor(options) {
|
|
30
|
+
super(options);
|
|
31
|
+
|
|
32
|
+
// Redeclared with the html specific shape
|
|
33
|
+
/** @type {HtmlModuleBuildInfo | undefined} */
|
|
34
|
+
this.buildInfo = undefined;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
makeSerializable(HtmlModule, "webpack/lib/html/HtmlModule");
|
|
39
|
+
|
|
40
|
+
module.exports = HtmlModule;
|