@depup/webpack 5.109.0-depup.0 → 5.110.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.
Files changed (641) hide show
  1. package/README.md +7 -7
  2. package/bin/webpack.js +12 -0
  3. package/changes.json +10 -10
  4. package/lib/APIPlugin.js +123 -17
  5. package/lib/AsyncDependenciesBlock.js +10 -7
  6. package/lib/AutomaticPrefetchPlugin.js +1 -1
  7. package/lib/BannerPlugin.js +10 -6
  8. package/lib/CacheFacade.js +6 -6
  9. package/lib/Chunk.js +14 -11
  10. package/lib/ChunkGraph.js +43 -32
  11. package/lib/ChunkGroup.js +7 -7
  12. package/lib/ChunkTemplate.js +35 -44
  13. package/lib/CircularModulesPlugin.js +205 -28
  14. package/lib/CleanPlugin.js +15 -16
  15. package/lib/CodeGenerationResults.js +11 -8
  16. package/lib/CompatibilityPlugin.js +38 -7
  17. package/lib/Compilation.js +709 -414
  18. package/lib/Compiler.js +69 -42
  19. package/lib/ConcatenationScope.js +117 -8
  20. package/lib/ConditionalInitFragment.js +3 -3
  21. package/lib/ConstPlugin.js +13 -11
  22. package/lib/ContextExclusionPlugin.js +1 -1
  23. package/lib/ContextModule.js +146 -54
  24. package/lib/ContextModuleFactory.js +46 -14
  25. package/lib/ContextReplacementPlugin.js +12 -14
  26. package/lib/DefinePlugin.js +168 -57
  27. package/lib/DependenciesBlock.js +9 -6
  28. package/lib/Dependency.js +36 -16
  29. package/lib/DependencyTemplate.js +11 -12
  30. package/lib/DependencyTemplates.js +3 -3
  31. package/lib/DotenvPlugin.js +50 -13
  32. package/lib/DynamicEntryPlugin.js +8 -4
  33. package/lib/EntryOptionPlugin.js +8 -4
  34. package/lib/EntryPlugin.js +2 -2
  35. package/lib/Entrypoint.js +6 -2
  36. package/lib/EnvironmentPlugin.js +2 -2
  37. package/lib/EvalDevToolModulePlugin.js +8 -4
  38. package/lib/EvalSourceMapDevToolPlugin.js +15 -8
  39. package/lib/ExportsInfo.js +123 -19
  40. package/lib/ExportsInfoApiPlugin.js +2 -4
  41. package/lib/ExternalModule.js +242 -84
  42. package/lib/ExternalModuleFactoryPlugin.js +97 -38
  43. package/lib/ExternalsPlugin.js +10 -6
  44. package/lib/FileSystemInfo.js +116 -42
  45. package/lib/FlagAllModulesAsUsedPlugin.js +2 -3
  46. package/lib/FlagDependencyExportsPlugin.js +76 -19
  47. package/lib/FlagDependencyUsagePlugin.js +63 -57
  48. package/lib/FlagEntryExportAsUsedPlugin.js +1 -1
  49. package/lib/Generator.js +36 -15
  50. package/lib/HotModuleReplacementPlugin.js +16 -44
  51. package/lib/IgnorePlugin.js +8 -4
  52. package/lib/IgnoreWarningsPlugin.js +2 -2
  53. package/lib/InitFragment.js +28 -36
  54. package/lib/JavascriptMetaInfoPlugin.js +35 -4
  55. package/lib/LazyBarrel.js +3 -4
  56. package/lib/LibraryTemplatePlugin.js +10 -6
  57. package/lib/LoaderOptionsPlugin.js +7 -3
  58. package/lib/LoaderTargetPlugin.js +1 -1
  59. package/lib/MainTemplate.js +49 -42
  60. package/lib/ManifestPlugin.js +12 -11
  61. package/lib/Module.js +62 -33
  62. package/lib/ModuleFactory.js +3 -3
  63. package/lib/ModuleFilenameHelpers.js +22 -6
  64. package/lib/ModuleGraph.js +195 -21
  65. package/lib/ModuleGraphConnection.js +6 -13
  66. package/lib/ModuleInfoHeaderPlugin.js +8 -10
  67. package/lib/ModuleTemplate.js +62 -63
  68. package/lib/MultiCompiler.js +130 -64
  69. package/lib/MultiStats.js +40 -9
  70. package/lib/MultiWatching.js +3 -3
  71. package/lib/NoEmitOnErrorsPlugin.js +1 -1
  72. package/lib/NodeStuffPlugin.js +29 -19
  73. package/lib/NormalModule.js +221 -156
  74. package/lib/NormalModuleFactory.js +563 -112
  75. package/lib/NormalModuleReplacementPlugin.js +5 -8
  76. package/lib/NullFactory.js +6 -2
  77. package/lib/OptionsApply.js +7 -3
  78. package/lib/Parser.js +7 -3
  79. package/lib/PlatformPlugin.js +2 -2
  80. package/lib/PrefetchPlugin.js +1 -1
  81. package/lib/ProgressPlugin.js +16 -13
  82. package/lib/ProvidePlugin.js +3 -5
  83. package/lib/RawModule.js +25 -17
  84. package/lib/RecordIdsPlugin.js +3 -3
  85. package/lib/RequestShortener.js +1 -1
  86. package/lib/ResolverFactory.js +2 -2
  87. package/lib/RuntimeGlobals.js +22 -10
  88. package/lib/RuntimeModule.js +29 -19
  89. package/lib/RuntimePlugin.js +346 -256
  90. package/lib/RuntimeTemplate.js +2792 -352
  91. package/lib/SelfModuleFactory.js +7 -3
  92. package/lib/SourceMapDevToolModuleOptionsPlugin.js +6 -2
  93. package/lib/SourceMapDevToolPlugin.js +30 -20
  94. package/lib/Stats.js +3 -4
  95. package/lib/Template.js +55 -25
  96. package/lib/TemplatedPathPlugin.js +96 -14
  97. package/lib/UseStrictPlugin.js +4 -6
  98. package/lib/WarnCaseSensitiveModulesPlugin.js +4 -4
  99. package/lib/WarnDeprecatedOptionPlugin.js +1 -1
  100. package/lib/WarnNoModeSetPlugin.js +1 -1
  101. package/lib/WatchIgnorePlugin.js +8 -6
  102. package/lib/Watching.js +8 -8
  103. package/lib/WebpackIsIncludedPlugin.js +2 -4
  104. package/lib/WebpackOptionsApply.js +308 -18
  105. package/lib/WebpackOptionsDefaulter.js +6 -2
  106. package/lib/asset/AssetBytesGenerator.js +12 -10
  107. package/lib/asset/AssetBytesParser.js +2 -4
  108. package/lib/asset/AssetGenerator.js +188 -95
  109. package/lib/asset/AssetModule.js +7 -3
  110. package/lib/asset/AssetModulesPlugin.js +110 -38
  111. package/lib/asset/AssetParser.js +9 -7
  112. package/lib/asset/AssetSourceGenerator.js +60 -13
  113. package/lib/asset/AssetSourceParser.js +2 -4
  114. package/lib/asset/RawDataUrlModule.js +24 -16
  115. package/lib/asset/WebManifestGenerator.js +8 -10
  116. package/lib/asset/WebManifestParser.js +24 -10
  117. package/lib/async-modules/AsyncModuleHelpers.js +2 -2
  118. package/lib/async-modules/AwaitDependenciesInitFragment.js +2 -2
  119. package/lib/async-modules/InferAsyncModulesPlugin.js +2 -2
  120. package/lib/async-modules/isGeneratorLowered.js +4 -4
  121. package/lib/buildChunkGraph.js +36 -27
  122. package/lib/bun/BunTargetPlugin.js +1 -1
  123. package/lib/cache/AddBuildDependenciesPlugin.js +1 -1
  124. package/lib/cache/AddManagedPathsPlugin.js +1 -1
  125. package/lib/cache/IdleFileCachePlugin.js +2 -2
  126. package/lib/cache/MemoryCachePlugin.js +18 -10
  127. package/lib/cache/MemoryWithGcCachePlugin.js +34 -22
  128. package/lib/cache/PackFileCacheStrategy.js +289 -28
  129. package/lib/cache/ResolverCachePlugin.js +38 -18
  130. package/lib/cache/getLazyHashedEtag.js +1 -2
  131. package/lib/cache/mergeEtags.js +1 -1
  132. package/lib/cli.js +1 -3
  133. package/lib/config/browserslistTargetHandler.js +41 -5
  134. package/lib/config/defaults.js +282 -81
  135. package/lib/config/defineConfig.js +10 -2
  136. package/lib/config/getClaimedAssetTypes.js +65 -0
  137. package/lib/config/normalization.js +36 -16
  138. package/lib/config/target.js +46 -3
  139. package/lib/container/ContainerEntryDependency.js +1 -1
  140. package/lib/container/ContainerEntryModule.js +24 -15
  141. package/lib/container/ContainerEntryModuleFactory.js +7 -3
  142. package/lib/container/ContainerPlugin.js +9 -10
  143. package/lib/container/ContainerReferencePlugin.js +6 -2
  144. package/lib/container/FallbackDependency.js +1 -1
  145. package/lib/container/FallbackModule.js +24 -17
  146. package/lib/container/FallbackModuleFactory.js +7 -3
  147. package/lib/container/HoistContainerReferencesPlugin.js +53 -66
  148. package/lib/container/ModuleFederationPlugin.js +7 -18
  149. package/lib/container/RemoteModule.js +27 -19
  150. package/lib/container/RemoteRuntimeModule.js +10 -8
  151. package/lib/container/moduleFederationHooks.js +32 -0
  152. package/lib/css/CssGenerator.js +178 -44
  153. package/lib/css/CssInjectStyleRuntimeModule.js +7 -5
  154. package/lib/css/CssLoadingRuntimeModule.js +82 -36
  155. package/lib/css/CssModule.js +10 -7
  156. package/lib/css/CssModulesPlugin.js +197 -106
  157. package/lib/css/CssParser.js +1248 -618
  158. package/lib/css/CssServerStylesRuntimeModule.js +54 -0
  159. package/lib/css/cssMinify.js +168 -0
  160. package/lib/css/data.js +5324 -0
  161. package/lib/css/syntax.js +10396 -952
  162. package/lib/debug/ProfilingPlugin.js +14 -9
  163. package/lib/deno/DenoTargetPlugin.js +1 -1
  164. package/lib/dependencies/AMDDefineDependency.js +112 -87
  165. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +30 -17
  166. package/lib/dependencies/AMDPlugin.js +9 -7
  167. package/lib/dependencies/AMDRequireArrayDependency.js +5 -5
  168. package/lib/dependencies/AMDRequireContextDependency.js +2 -2
  169. package/lib/dependencies/AMDRequireDependenciesBlock.js +1 -1
  170. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +25 -14
  171. package/lib/dependencies/AMDRequireDependency.js +8 -7
  172. package/lib/dependencies/AMDRequireItemDependency.js +1 -1
  173. package/lib/dependencies/AMDRuntimeModules.js +21 -1
  174. package/lib/dependencies/BuildTimeConstDependency.js +102 -0
  175. package/lib/dependencies/CachedConstDependency.js +11 -8
  176. package/lib/dependencies/CommonJsDependencyHelpers.js +67 -46
  177. package/lib/dependencies/CommonJsExportRequireDependency.js +140 -45
  178. package/lib/dependencies/CommonJsExportsDependency.js +53 -49
  179. package/lib/dependencies/CommonJsExportsParserPlugin.js +207 -25
  180. package/lib/dependencies/CommonJsFullRequireDependency.js +140 -26
  181. package/lib/dependencies/CommonJsImportsParserPlugin.js +100 -48
  182. package/lib/dependencies/CommonJsObjectExportDependency.js +188 -0
  183. package/lib/dependencies/CommonJsPlugin.js +35 -6
  184. package/lib/dependencies/CommonJsRequireContextDependency.js +5 -6
  185. package/lib/dependencies/CommonJsRequireDependency.js +156 -27
  186. package/lib/dependencies/CommonJsSelfReferenceDependency.js +63 -38
  187. package/lib/dependencies/ConstDependency.js +8 -9
  188. package/lib/dependencies/ContextDependency.js +12 -8
  189. package/lib/dependencies/ContextDependencyHelpers.js +14 -9
  190. package/lib/dependencies/ContextDependencyTemplateAsId.js +4 -4
  191. package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +4 -4
  192. package/lib/dependencies/ContextElementDependency.js +31 -12
  193. package/lib/dependencies/CreateRequireParserPlugin.js +12 -7
  194. package/lib/dependencies/CreateScriptUrlDependency.js +4 -4
  195. package/lib/dependencies/CssIcssExportDependency.js +56 -28
  196. package/lib/dependencies/CssIcssImportDependency.js +17 -13
  197. package/lib/dependencies/CssIcssSymbolDependency.js +9 -10
  198. package/lib/dependencies/CssImportDependency.js +18 -9
  199. package/lib/dependencies/CssUrlDependency.js +17 -13
  200. package/lib/dependencies/DllEntryDependency.js +1 -1
  201. package/lib/dependencies/DynamicExports.js +2 -2
  202. package/lib/dependencies/ExportBindingInitFragment.js +36 -9
  203. package/lib/dependencies/ExportsInfoDependency.js +7 -8
  204. package/lib/dependencies/ExternalModuleDependency.js +9 -5
  205. package/lib/dependencies/ExternalModuleInitFragment.js +2 -2
  206. package/lib/dependencies/ExternalModuleInitFragmentDependency.js +8 -5
  207. package/lib/dependencies/HarmonyAcceptDependency.js +5 -5
  208. package/lib/dependencies/HarmonyCompatibilityDependency.js +52 -17
  209. package/lib/dependencies/HarmonyDetectionParserPlugin.js +11 -7
  210. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +15 -11
  211. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +78 -12
  212. package/lib/dependencies/HarmonyExportExpressionDependency.js +23 -18
  213. package/lib/dependencies/HarmonyExportHeaderDependency.js +7 -7
  214. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +159 -71
  215. package/lib/dependencies/HarmonyExportInitFragment.js +18 -6
  216. package/lib/dependencies/HarmonyExportSpecifierDependency.js +51 -14
  217. package/lib/dependencies/HarmonyExports.js +7 -4
  218. package/lib/dependencies/HarmonyImportDependency.js +28 -20
  219. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +31 -24
  220. package/lib/dependencies/HarmonyImportGuard.js +21 -30
  221. package/lib/dependencies/HarmonyImportSideEffectDependency.js +38 -9
  222. package/lib/dependencies/HarmonyImportSpecifierDependency.js +106 -55
  223. package/lib/dependencies/HarmonyModulesPlugin.js +7 -3
  224. package/lib/dependencies/HarmonyTopLevelThisParserPlugin.js +1 -3
  225. package/lib/dependencies/HtmlEntryDependency.js +37 -29
  226. package/lib/dependencies/HtmlInlineHtmlDependency.js +7 -8
  227. package/lib/dependencies/HtmlInlineScriptDependency.js +11 -8
  228. package/lib/dependencies/HtmlInlineStyleDependency.js +7 -10
  229. package/lib/dependencies/HtmlSourceDependency.js +22 -14
  230. package/lib/dependencies/ImportContextDependency.js +2 -2
  231. package/lib/dependencies/ImportDependency.js +24 -20
  232. package/lib/dependencies/ImportEagerDependency.js +6 -9
  233. package/lib/dependencies/ImportMetaContextDependency.js +2 -2
  234. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +14 -13
  235. package/lib/dependencies/ImportMetaContextPlugin.js +7 -3
  236. package/lib/dependencies/ImportMetaGlobDependency.js +2 -2
  237. package/lib/dependencies/ImportMetaGlobDependencyParserPlugin.js +2 -3
  238. package/lib/dependencies/ImportMetaGlobHelpers.js +19 -22
  239. package/lib/dependencies/ImportMetaHotAcceptDependency.js +1 -1
  240. package/lib/dependencies/ImportMetaHotDeclineDependency.js +1 -1
  241. package/lib/dependencies/ImportMetaPlugin.js +154 -71
  242. package/lib/dependencies/ImportMetaResolveDependency.js +3 -4
  243. package/lib/dependencies/ImportParserPlugin.js +49 -35
  244. package/lib/dependencies/ImportPhase.js +12 -5
  245. package/lib/dependencies/ImportPlugin.js +7 -3
  246. package/lib/dependencies/ImportWeakDependency.js +6 -9
  247. package/lib/dependencies/JsonExportsDependency.js +11 -7
  248. package/lib/dependencies/LoaderDependency.js +2 -2
  249. package/lib/dependencies/LoaderImportDependency.js +2 -2
  250. package/lib/dependencies/LoaderPlugin.js +11 -7
  251. package/lib/dependencies/LocalModuleDependency.js +5 -5
  252. package/lib/dependencies/LocalModulesHelpers.js +1 -1
  253. package/lib/dependencies/ModuleDecoratorDependency.js +6 -7
  254. package/lib/dependencies/ModuleDependency.js +9 -6
  255. package/lib/dependencies/ModuleDependencyTemplateAsId.js +4 -4
  256. package/lib/dependencies/ModuleDependencyTemplateAsRequireId.js +3 -3
  257. package/lib/dependencies/ModuleHotAcceptDependency.js +1 -1
  258. package/lib/dependencies/ModuleHotDeclineDependency.js +1 -1
  259. package/lib/dependencies/ModuleInitFragmentDependency.js +24 -10
  260. package/lib/dependencies/NullDependency.js +3 -3
  261. package/lib/dependencies/ProvidedDependency.js +14 -10
  262. package/lib/dependencies/PureExpressionDependency.js +9 -10
  263. package/lib/dependencies/RequireContextDependency.js +2 -2
  264. package/lib/dependencies/RequireContextDependencyParserPlugin.js +2 -4
  265. package/lib/dependencies/RequireContextPlugin.js +8 -4
  266. package/lib/dependencies/RequireEnsureDependenciesBlock.js +2 -2
  267. package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +5 -8
  268. package/lib/dependencies/RequireEnsureDependency.js +8 -7
  269. package/lib/dependencies/RequireEnsurePlugin.js +7 -3
  270. package/lib/dependencies/RequireHeaderDependency.js +51 -12
  271. package/lib/dependencies/RequireIncludeDependency.js +6 -6
  272. package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +2 -3
  273. package/lib/dependencies/RequireIncludePlugin.js +7 -3
  274. package/lib/dependencies/RequireJsStuffPlugin.js +7 -3
  275. package/lib/dependencies/RequireResolveContextDependency.js +2 -2
  276. package/lib/dependencies/RequireResolveDependency.js +4 -4
  277. package/lib/dependencies/RequireResolveHeaderDependency.js +4 -4
  278. package/lib/dependencies/RuntimeRequirementsDependency.js +5 -6
  279. package/lib/dependencies/StaticExportsDependency.js +2 -2
  280. package/lib/dependencies/SystemPlugin.js +10 -6
  281. package/lib/dependencies/SystemRuntimeModule.js +10 -0
  282. package/lib/dependencies/TopLevelAwaitDependency.js +11 -7
  283. package/lib/dependencies/URLContextDependency.js +2 -2
  284. package/lib/dependencies/URLDependency.js +110 -64
  285. package/lib/dependencies/URLPlugin.js +7 -3
  286. package/lib/dependencies/UnsupportedDependency.js +4 -4
  287. package/lib/dependencies/WebAssemblyExportImportedDependency.js +3 -4
  288. package/lib/dependencies/WebAssemblyImportDependency.js +5 -5
  289. package/lib/dependencies/WebpackIsIncludedDependency.js +6 -6
  290. package/lib/dependencies/WorkerAndWorkletPlugin.js +46 -28
  291. package/lib/dependencies/WorkerDependency.js +28 -22
  292. package/lib/dependencies/WorkletDependency.js +15 -14
  293. package/lib/dependencies/getFunctionExpression.js +8 -4
  294. package/lib/dependencies/processExportInfo.js +5 -5
  295. package/lib/dll/DelegatedModule.js +34 -22
  296. package/lib/dll/DelegatedModuleFactoryPlugin.js +15 -7
  297. package/lib/dll/DelegatedPlugin.js +2 -2
  298. package/lib/dll/DllEntryPlugin.js +2 -2
  299. package/lib/dll/DllModule.js +22 -15
  300. package/lib/dll/DllModuleFactory.js +7 -3
  301. package/lib/dll/DllPlugin.js +7 -5
  302. package/lib/dll/DllReferencePlugin.js +10 -7
  303. package/lib/dll/LibManifestPlugin.js +5 -5
  304. package/lib/electron/ElectronTargetPlugin.js +53 -49
  305. package/lib/errors/AsyncChunkWaterfallWarning.js +36 -0
  306. package/lib/errors/AsyncDependencyToInitialChunkError.js +2 -2
  307. package/lib/errors/BroadContextsWarning.js +43 -0
  308. package/lib/errors/BuildCycleError.js +1 -1
  309. package/lib/errors/CacheEffectivenessWarning.js +55 -0
  310. package/lib/errors/ChunkRenderError.js +1 -1
  311. package/lib/errors/CircularDependenciesWarning.js +38 -0
  312. package/lib/errors/CodeGenerationError.js +1 -1
  313. package/lib/errors/CommentCompilationWarning.js +1 -1
  314. package/lib/errors/ConflictingResourceHintsWarning.js +35 -0
  315. package/lib/errors/DuplicateModulesWarning.js +45 -0
  316. package/lib/errors/DynamicExportsWarning.js +30 -0
  317. package/lib/errors/EmbeddedSourceMapsWarning.js +25 -0
  318. package/lib/errors/EntrypointOverlapWarning.js +45 -0
  319. package/lib/errors/EnvironmentNotSupportAsyncWarning.js +2 -2
  320. package/lib/errors/EvalUsageWarning.js +28 -0
  321. package/lib/errors/HookWebpackError.js +5 -5
  322. package/lib/errors/HotspotsWarning.js +57 -0
  323. package/lib/errors/IgnoreErrorModuleFactory.js +7 -3
  324. package/lib/errors/InlinedAssetsWarning.js +36 -0
  325. package/lib/errors/InvalidDependenciesModuleWarning.js +1 -1
  326. package/lib/errors/LargeModulesWarning.js +45 -0
  327. package/lib/errors/LegacyJavascriptWarning.js +48 -0
  328. package/lib/errors/MissingSideEffectsWarning.js +36 -0
  329. package/lib/errors/MixedExportsWarning.js +41 -0
  330. package/lib/errors/ModuleDependencyError.js +13 -16
  331. package/lib/errors/ModuleDependencyWarning.js +5 -15
  332. package/lib/errors/ModuleHashingError.js +1 -1
  333. package/lib/errors/ModuleNotFoundError.js +2 -2
  334. package/lib/errors/ModuleParseError.js +1 -2
  335. package/lib/errors/ModuleRestoreError.js +1 -1
  336. package/lib/errors/ModuleStoreError.js +1 -1
  337. package/lib/errors/NodeStuffInWebError.js +1 -1
  338. package/lib/errors/OsDependentRuleWarning.js +31 -0
  339. package/lib/errors/PureAnnotationsWarning.js +36 -0
  340. package/lib/errors/RedundantDynamicImportWarning.js +31 -0
  341. package/lib/errors/ScopeHoistingBailoutsWarning.js +41 -0
  342. package/lib/errors/SplitChunksCappedWarning.js +41 -0
  343. package/lib/errors/TinyChunksWarning.js +40 -0
  344. package/lib/errors/TopLevelThisWarning.js +34 -0
  345. package/lib/errors/UnsplitVendorsWarning.js +42 -0
  346. package/lib/errors/UnsupportedFeatureWarning.js +1 -1
  347. package/lib/errors/UnusedAliasesWarning.js +29 -0
  348. package/lib/errors/UnusedDefinesWarning.js +29 -0
  349. package/lib/errors/UnusedExternalsWarning.js +29 -0
  350. package/lib/errors/UnusedReexportsWarning.js +42 -0
  351. package/lib/errors/UnusedRuleWarning.js +29 -0
  352. package/lib/errors/WebpackError.js +9 -5
  353. package/lib/errors/deriveStackFromNestedError.js +90 -0
  354. package/lib/esm/ExportWebpackRequireRuntimeModule.js +2 -0
  355. package/lib/esm/ModuleChunkFormatPlugin.js +37 -19
  356. package/lib/esm/ModuleChunkLoadingPlugin.js +89 -51
  357. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +170 -71
  358. package/lib/hmr/HotModuleReplacement.runtime.js +24 -5
  359. package/lib/hmr/HotModuleReplacementRuntimeModule.js +1 -1
  360. package/lib/hmr/LazyCompilationPlugin.js +45 -24
  361. package/lib/hmr/lazyCompilationBackend.js +28 -10
  362. package/lib/hmr/parserHooks.js +56 -0
  363. package/lib/html/HtmlGenerator.js +299 -79
  364. package/lib/html/HtmlModule.js +7 -3
  365. package/lib/html/HtmlModulesPlugin.js +312 -174
  366. package/lib/html/HtmlParser.js +31 -86
  367. package/lib/html/data.js +1928 -0
  368. package/lib/html/htmlMinify.js +288 -0
  369. package/lib/html/syntax.js +7819 -3331
  370. package/lib/ids/ChunkModuleIdRangePlugin.js +3 -3
  371. package/lib/ids/DeterministicChunkIdsPlugin.js +1 -1
  372. package/lib/ids/DeterministicModuleIdsPlugin.js +2 -2
  373. package/lib/ids/HashedModuleIdsPlugin.js +6 -2
  374. package/lib/ids/IdHelpers.js +31 -18
  375. package/lib/ids/NamedChunkIdsPlugin.js +1 -1
  376. package/lib/ids/NamedModuleIdsPlugin.js +1 -1
  377. package/lib/ids/NaturalChunkIdsPlugin.js +2 -2
  378. package/lib/ids/NaturalModuleIdsPlugin.js +1 -1
  379. package/lib/ids/OccurrenceChunkIdsPlugin.js +7 -3
  380. package/lib/ids/OccurrenceModuleIdsPlugin.js +7 -3
  381. package/lib/ids/SyncModuleIdsPlugin.js +4 -4
  382. package/lib/index.js +10 -0
  383. package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +3 -3
  384. package/lib/javascript/BasicEvaluatedExpression.js +18 -14
  385. package/lib/javascript/ChunkFormatHelpers.js +6 -6
  386. package/lib/javascript/ChunkHelpers.js +1 -1
  387. package/lib/javascript/CommonJsChunkFormatPlugin.js +11 -5
  388. package/lib/javascript/EnableChunkLoadingPlugin.js +2 -2
  389. package/lib/javascript/JavascriptGenerator.js +65 -165
  390. package/lib/javascript/JavascriptModule.js +9 -3
  391. package/lib/javascript/JavascriptModulesPlugin.js +181 -162
  392. package/lib/javascript/JavascriptParser.js +291 -112
  393. package/lib/javascript/JavascriptParserHelpers.js +10 -7
  394. package/lib/javascript/ScopeAnalyzer.js +1094 -0
  395. package/lib/javascript/StartupHelpers.js +55 -9
  396. package/lib/javascript/syntax.js +3403 -300
  397. package/lib/json/JsonData.js +8 -4
  398. package/lib/json/JsonGenerator.js +38 -16
  399. package/lib/json/JsonModule.js +7 -3
  400. package/lib/json/JsonModulesPlugin.js +1 -1
  401. package/lib/json/JsonParser.js +5 -6
  402. package/lib/library/AbstractLibraryPlugin.js +20 -14
  403. package/lib/library/AmdLibraryPlugin.js +11 -7
  404. package/lib/library/AssignLibraryPlugin.js +19 -13
  405. package/lib/library/EnableLibraryPlugin.js +2 -2
  406. package/lib/library/ExportPropertyLibraryPlugin.js +15 -8
  407. package/lib/library/JsonpLibraryPlugin.js +11 -7
  408. package/lib/library/ModuleLibraryPlugin.js +256 -64
  409. package/lib/library/SystemLibraryPlugin.js +12 -8
  410. package/lib/library/UmdLibraryPlugin.js +62 -25
  411. package/lib/loaders/LoaderRunner.js +14 -1
  412. package/lib/loaders/loadLoader.js +8 -4
  413. package/lib/logging/createConsoleLogger.js +7 -4
  414. package/lib/node/CommonJsChunkLoadingPlugin.js +36 -22
  415. package/lib/node/NodeEnvironmentPlugin.js +17 -3
  416. package/lib/node/NodeSourcePlugin.js +1 -1
  417. package/lib/node/NodeTargetPlugin.js +4 -3
  418. package/lib/node/NodeTemplatePlugin.js +1 -1
  419. package/lib/node/NodeWatchFileSystem.js +70 -9
  420. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +35 -38
  421. package/lib/node/ReadFileCompileAsyncWasmPlugin.js +81 -20
  422. package/lib/node/ReadFileCompileWasmPlugin.js +37 -17
  423. package/lib/node/RequireChunkLoadingRuntimeModule.js +35 -38
  424. package/lib/node/nodeConsole.js +7 -3
  425. package/lib/optimize/AggressiveMergingPlugin.js +21 -17
  426. package/lib/optimize/AggressiveSplittingPlugin.js +9 -6
  427. package/lib/optimize/ConcatenatedModule.js +996 -477
  428. package/lib/optimize/ConstExportsPlugin.js +11 -7
  429. package/lib/optimize/EnsureChunkConditionsPlugin.js +3 -3
  430. package/lib/optimize/FlagIncludedChunksPlugin.js +3 -4
  431. package/lib/optimize/InlineExports.js +9 -5
  432. package/lib/optimize/InnerGraph.js +28 -12
  433. package/lib/optimize/InnerGraphPlugin.js +23 -18
  434. package/lib/optimize/LimitChunkCountPlugin.js +7 -3
  435. package/lib/optimize/MangleExportsPlugin.js +7 -8
  436. package/lib/optimize/MergeDuplicateChunksPlugin.js +7 -3
  437. package/lib/optimize/MinChunkSizePlugin.js +7 -3
  438. package/lib/optimize/ModuleConcatenationPlugin.js +124 -59
  439. package/lib/optimize/RealContentHashPlugin.js +20 -13
  440. package/lib/optimize/RemoveEmptyChunksPlugin.js +2 -2
  441. package/lib/optimize/RemoveParentModulesPlugin.js +4 -4
  442. package/lib/optimize/RuntimeChunkPlugin.js +2 -2
  443. package/lib/optimize/SideEffectsFlagPlugin.js +262 -39
  444. package/lib/optimize/SplitChunksPlugin.js +232 -68
  445. package/lib/performance/AssetsOverSizeLimitWarning.js +10 -2
  446. package/lib/performance/AsyncChunkWaterfallsPlugin.js +136 -0
  447. package/lib/performance/BroadContextsPlugin.js +142 -0
  448. package/lib/performance/CacheEffectivenessPlugin.js +125 -0
  449. package/lib/performance/ConflictingResourceHintsPlugin.js +99 -0
  450. package/lib/performance/DuplicateModulesPlugin.js +93 -0
  451. package/lib/performance/DuplicatePackagesPlugin.js +119 -0
  452. package/lib/performance/DuplicatePackagesWarning.js +84 -0
  453. package/lib/performance/DynamicExportsPlugin.js +120 -0
  454. package/lib/performance/EmbeddedSourceMapsPlugin.js +71 -0
  455. package/lib/performance/EntrypointOverlapPlugin.js +122 -0
  456. package/lib/performance/EntrypointsOverSizeLimitWarning.js +1 -1
  457. package/lib/performance/EvalUsagePlugin.js +115 -0
  458. package/lib/performance/HotspotsPlugin.js +296 -0
  459. package/lib/performance/InlinedAssetsPlugin.js +99 -0
  460. package/lib/performance/LargeModulesPlugin.js +126 -0
  461. package/lib/performance/LegacyJavascriptPlugin.js +139 -0
  462. package/lib/performance/MissingSideEffectsPlugin.js +138 -0
  463. package/lib/performance/MixedExportsPlugin.js +136 -0
  464. package/lib/performance/OsDependentRuleWarningPlugin.js +178 -0
  465. package/lib/performance/PureAnnotationsPlugin.js +219 -0
  466. package/lib/performance/RedundantDynamicImportsPlugin.js +225 -0
  467. package/lib/performance/RuntimeInLargeChunkWarning.js +27 -0
  468. package/lib/performance/ScopeHoistingBailoutsPlugin.js +164 -0
  469. package/lib/performance/SizeLimitsPlugin.js +139 -7
  470. package/lib/performance/SplitChunksCappedPlugin.js +99 -0
  471. package/lib/performance/TinyChunksPlugin.js +128 -0
  472. package/lib/performance/TopLevelThisPlugin.js +208 -0
  473. package/lib/performance/UnsplitVendorsPlugin.js +112 -0
  474. package/lib/performance/UnusedAliasesPlugin.js +253 -0
  475. package/lib/performance/UnusedDefinesPlugin.js +87 -0
  476. package/lib/performance/UnusedExternalsPlugin.js +110 -0
  477. package/lib/performance/UnusedReexportsPlugin.js +159 -0
  478. package/lib/performance/UnusedRuleWarningPlugin.js +105 -0
  479. package/lib/performance/getModuleSize.js +22 -0
  480. package/lib/performance/getSourceModules.js +22 -0
  481. package/lib/performance/hasOnlyUnusedExports.js +40 -0
  482. package/lib/prefetch/ChunkPrefetchFunctionRuntimeModule.js +24 -10
  483. package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +63 -46
  484. package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +2 -3
  485. package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +2 -2
  486. package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +2 -2
  487. package/lib/prefetch/ResourceHintPlugin.js +377 -136
  488. package/lib/prefetch/ResourceHintRuntimeModule.js +1 -21
  489. package/lib/prefetch/StartupAssetHintRuntimeModule.js +10 -133
  490. package/lib/prefetch/parseResourceHintOptions.js +31 -4
  491. package/lib/rules/BasicEffectRulePlugin.js +2 -2
  492. package/lib/rules/BasicMatcherRulePlugin.js +8 -4
  493. package/lib/rules/GlobMatcherRulePlugin.js +68 -0
  494. package/lib/rules/ObjectMatcherRulePlugin.js +12 -5
  495. package/lib/rules/RuleSetCompiler.js +146 -12
  496. package/lib/rules/UseEffectRulePlugin.js +18 -11
  497. package/lib/runtime/AsyncModuleGeneratorRuntimeModule.js +11 -1
  498. package/lib/runtime/AsyncModuleRuntimeModule.js +1 -1
  499. package/lib/runtime/AutoPublicPathRuntimeModule.js +15 -20
  500. package/lib/runtime/BaseUriRuntimeModule.js +33 -7
  501. package/lib/runtime/ChunkNameRuntimeModule.js +10 -0
  502. package/lib/runtime/CompatGetDefaultExportRuntimeModule.js +11 -1
  503. package/lib/runtime/CompatRuntimeModule.js +5 -3
  504. package/lib/runtime/ConcatenationWrapRuntimeModule.js +90 -0
  505. package/lib/runtime/ConstructRequireRuntimeModule.js +52 -0
  506. package/lib/runtime/CreateFakeNamespaceObjectRuntimeModule.js +8 -6
  507. package/lib/runtime/CreateScriptRuntimeModule.js +11 -1
  508. package/lib/runtime/CreateScriptUrlRuntimeModule.js +11 -1
  509. package/lib/runtime/DefinePropertyGettersRuntimeModule.js +56 -38
  510. package/lib/runtime/EnsureChunkRuntimeModule.js +18 -2
  511. package/lib/runtime/GetChunkFilenameRuntimeModule.js +62 -37
  512. package/lib/runtime/GetFullHashRuntimeModule.js +12 -2
  513. package/lib/runtime/GetMainFilenameRuntimeModule.js +12 -2
  514. package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +2 -2
  515. package/lib/runtime/GetWorkletBootstrapRuntimeModule.js +16 -3
  516. package/lib/runtime/GlobalRuntimeModule.js +18 -0
  517. package/lib/runtime/HasOwnPropertyRuntimeModule.js +12 -2
  518. package/lib/runtime/LoadScriptRuntimeModule.js +2 -2
  519. package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +23 -6
  520. package/lib/runtime/MakeNamespaceObjectRuntimeModule.js +22 -6
  521. package/lib/runtime/NonceRuntimeModule.js +10 -0
  522. package/lib/runtime/OnChunksLoadedRuntimeModule.js +5 -3
  523. package/lib/runtime/PublicPathRuntimeModule.js +12 -2
  524. package/lib/runtime/RelativeUrlRuntimeModule.js +11 -1
  525. package/lib/runtime/RuntimeIdRuntimeModule.js +12 -2
  526. package/lib/runtime/SetAnonymousDefaultNameRuntimeModule.js +11 -1
  527. package/lib/runtime/StartupChunkDependenciesPlugin.js +18 -9
  528. package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +3 -3
  529. package/lib/runtime/StartupEntrypointRuntimeModule.js +21 -4
  530. package/lib/runtime/SystemContextRuntimeModule.js +10 -0
  531. package/lib/runtime/ToBinaryRuntimeModule.js +1 -1
  532. package/lib/runtime/WorkerRuntimeModule.js +11 -1
  533. package/lib/runtime/baseUri.js +63 -0
  534. package/lib/schemes/DataUriPlugin.js +1 -1
  535. package/lib/schemes/FileUriPlugin.js +1 -1
  536. package/lib/schemes/HttpUriPlugin.js +24 -15
  537. package/lib/schemes/VirtualUrlPlugin.js +13 -7
  538. package/lib/serialization/AggregateErrorSerializer.js +1 -1
  539. package/lib/serialization/BinaryMiddleware.js +274 -942
  540. package/lib/serialization/ErrorObjectSerializer.js +1 -1
  541. package/lib/serialization/FileMiddleware.js +305 -66
  542. package/lib/serialization/ObjectMiddleware.js +139 -114
  543. package/lib/serialization/PlainObjectSerializer.js +19 -16
  544. package/lib/sharing/ConsumeSharedModule.js +30 -21
  545. package/lib/sharing/ConsumeSharedPlugin.js +18 -10
  546. package/lib/sharing/ConsumeSharedRuntimeModule.js +6 -9
  547. package/lib/sharing/ProvideSharedModule.js +25 -16
  548. package/lib/sharing/ProvideSharedModuleFactory.js +7 -3
  549. package/lib/sharing/ProvideSharedPlugin.js +8 -4
  550. package/lib/sharing/SharePlugin.js +17 -5
  551. package/lib/sharing/ShareRuntimeModule.js +4 -4
  552. package/lib/sharing/resolveMatchedConfigs.js +9 -6
  553. package/lib/sharing/utils.js +1 -3
  554. package/lib/stats/DefaultStatsFactoryPlugin.js +253 -226
  555. package/lib/stats/DefaultStatsPresetPlugin.js +17 -8
  556. package/lib/stats/DefaultStatsPrinterPlugin.js +60 -192
  557. package/lib/stats/StatsFactory.js +56 -35
  558. package/lib/stats/StatsPrinter.js +16 -12
  559. package/lib/typescript/TypeScriptPlugin.js +12 -14
  560. package/lib/url/URLParserPlugin.js +26 -13
  561. package/lib/util/AsyncQueue.js +4 -3
  562. package/lib/util/Hash.js +5 -1
  563. package/lib/util/LazySet.js +35 -22
  564. package/lib/util/LocConverter.js +36 -13
  565. package/lib/util/SourceProcessor.js +1050 -24
  566. package/lib/util/StringXor.js +1 -1
  567. package/lib/util/chainedImports.js +9 -5
  568. package/lib/util/cleverMerge.js +1 -1
  569. package/lib/util/comparators.js +45 -14
  570. package/lib/util/concatenate.js +203 -77
  571. package/lib/util/conventions.js +5 -1
  572. package/lib/util/createHash.js +2 -2
  573. package/lib/util/createHooksRegistry.js +8 -10
  574. package/lib/util/dataURL.js +225 -1
  575. package/lib/util/extractSourceMap.js +4 -3
  576. package/lib/util/findCaseMismatch.js +139 -0
  577. package/lib/util/formatLocation.js +1 -2
  578. package/lib/util/fs.js +22 -5
  579. package/lib/util/globUtils.js +298 -24
  580. package/lib/util/hash/BatchedHash.js +5 -1
  581. package/lib/util/hash/BulkUpdateHash.js +5 -1
  582. package/lib/util/hash/DebugHash.js +5 -1
  583. package/lib/util/hash/hash-digest.js +6 -2
  584. package/lib/util/identifier.js +25 -1
  585. package/lib/util/implicitTypeLoaderFallback.js +1 -1
  586. package/lib/util/internalSerializables.js +6 -0
  587. package/lib/util/lazyModule.js +56 -0
  588. package/lib/util/makeSerializable.js +7 -3
  589. package/lib/util/matchAlias.js +25 -0
  590. package/lib/util/mimeTypes.js +11 -5
  591. package/lib/util/nonNumericOnlyHash.js +4 -3
  592. package/lib/util/parseJson.js +5 -3
  593. package/lib/util/preloadModuleType.js +32 -0
  594. package/lib/util/registerExternalSerializer.js +7 -5
  595. package/lib/util/runtime.js +2 -2
  596. package/lib/util/semver.js +1 -1
  597. package/lib/util/serialization.js +28 -28
  598. package/lib/util/source.js +2 -2
  599. package/lib/util/traverseDestructuringAssignmentProperties.js +6 -2
  600. package/lib/wasm/EnableWasmLoadingPlugin.js +10 -8
  601. package/lib/wasm/wasmModuleFilename.js +54 -0
  602. package/lib/wasm-async/AsyncWasmCompileRuntimeModule.js +41 -21
  603. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +43 -21
  604. package/lib/wasm-async/AsyncWasmModule.js +3 -3
  605. package/lib/wasm-async/AsyncWebAssemblyGenerator.js +4 -5
  606. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +57 -17
  607. package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +34 -18
  608. package/lib/wasm-async/AsyncWebAssemblyParser.js +9 -8
  609. package/lib/wasm-async/UniversalCompileAsyncWasmPlugin.js +34 -8
  610. package/lib/wasm-sync/SyncWasmModule.js +2 -2
  611. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +18 -13
  612. package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +4 -5
  613. package/lib/wasm-sync/WebAssemblyGenerator.js +18 -17
  614. package/lib/wasm-sync/WebAssemblyInInitialChunkError.js +4 -4
  615. package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +7 -7
  616. package/lib/wasm-sync/WebAssemblyModulesPlugin.js +24 -11
  617. package/lib/wasm-sync/WebAssemblyParser.js +4 -6
  618. package/lib/wasm-sync/WebAssemblyUtils.js +2 -2
  619. package/lib/web/FetchCompileAsyncWasmPlugin.js +101 -19
  620. package/lib/web/FetchCompileWasmPlugin.js +46 -16
  621. package/lib/web/JsonpChunkLoadingPlugin.js +47 -23
  622. package/lib/web/JsonpChunkLoadingRuntimeModule.js +50 -20
  623. package/lib/web/JsonpTemplatePlugin.js +2 -2
  624. package/lib/webpack.js +22 -11
  625. package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +60 -26
  626. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +30 -32
  627. package/lib/webworker/WebWorkerTemplatePlugin.js +1 -1
  628. package/module.d.ts +1 -0
  629. package/package.json +37 -30
  630. package/schemas/WebpackOptions.check.js +1 -1
  631. package/schemas/WebpackOptions.json +780 -91
  632. package/schemas/plugins/HtmlParserOptions.check.js +1 -1
  633. package/schemas/plugins/container/ContainerPlugin.check.js +1 -1
  634. package/schemas/plugins/container/ContainerPlugin.json +10 -0
  635. package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
  636. package/schemas/plugins/container/ModuleFederationPlugin.json +10 -0
  637. package/schemas/plugins/css/CssAutoOrModuleParserOptions.check.js +1 -1
  638. package/schemas/plugins/css/CssModuleParserOptions.check.js +1 -1
  639. package/schemas/plugins/css/CssParserOptions.check.js +1 -1
  640. package/types.d.ts +4013 -738
  641. package/lib/runtime/CommonJsWrapRuntimeModule.js +0 -37
@@ -14,38 +14,29 @@ const {
14
14
  } = require("../ModuleSourceTypeConstants");
15
15
  const RuntimeGlobals = require("../RuntimeGlobals");
16
16
  const Template = require("../Template");
17
+ const CssModulesPlugin = require("../css/CssModulesPlugin");
17
18
  const WebpackError = require("../errors/WebpackError");
18
19
  const { getUndoPath } = require("../util/identifier");
19
20
  const memoize = require("../util/memoize");
20
21
  const { PUBLIC_PATH_AUTO } = require("../util/publicPathPlaceholder");
21
- const { NodeType, SourceProcessor, escapeAttribute } = require("./syntax");
22
+ const { VOID } = require("./data");
22
23
 
24
+ const getCreateNodeHash = memoize(() => require("crypto").createHash);
25
+
26
+ const getCssSyntax = memoize(() => require("../css/syntax"));
27
+
28
+ const getHtmlSyntax = memoize(() => require("./syntax"));
29
+
30
+ // Lazy: the dependency templates need this module's sentinel helpers on every
31
+ // build, but the HTML tokenizer is only reached once HTML is actually emitted.
23
32
  // Lazy so loading the HTML generator doesn't pull in the whole CSS pipeline.
24
- const getCssModulesPlugin = memoize(() => require("../css/CssModulesPlugin"));
33
+
25
34
  // The CSS tokenizer, used to locate `url(...)` when rebasing inlined stylesheets.
26
- const getCssSyntax = memoize(() => require("../css/syntax"));
27
35
  // node's crypto — real SHA hashes for Content-Security-Policy source lists
28
36
  // (the wasm hashes are xxhash, unusable for CSP), loaded only when CSP is on.
29
- const getCreateNodeHash = memoize(() => require("crypto").createHash);
30
37
 
31
38
  // HTML void elements — serialized without a closing tag when a tag descriptor
32
39
  // (`output.html` `injectTags`) doesn't say otherwise.
33
- const VOID_TAGS = new Set([
34
- "area",
35
- "base",
36
- "br",
37
- "col",
38
- "embed",
39
- "hr",
40
- "img",
41
- "input",
42
- "link",
43
- "meta",
44
- "param",
45
- "source",
46
- "track",
47
- "wbr"
48
- ]);
49
40
 
50
41
  /**
51
42
  * Serializes an attribute map: `true` → bare attribute, `false`/`undefined`/
@@ -56,6 +47,7 @@ const VOID_TAGS = new Set([
56
47
  const serializeAttrs = (attrs) => {
57
48
  let out = "";
58
49
  if (attrs) {
50
+ const { escapeAttribute } = getHtmlSyntax();
59
51
  for (const name of Object.keys(attrs)) {
60
52
  const value = attrs[name];
61
53
  if (value === false || value === undefined || value === null) continue;
@@ -77,9 +69,7 @@ const serializeAttrs = (attrs) => {
77
69
  const serializeTag = (tag) => {
78
70
  const attrs = serializeAttrs(tag.attrs);
79
71
  const isVoid =
80
- tag.voidTag !== undefined
81
- ? tag.voidTag
82
- : VOID_TAGS.has(tag.tag.toLowerCase());
72
+ tag.voidTag !== undefined ? tag.voidTag : VOID.has(tag.tag.toLowerCase());
83
73
  return isVoid
84
74
  ? `<${tag.tag}${attrs}>`
85
75
  : `<${tag.tag}${attrs}>${tag.children || ""}</${tag.tag}>`;
@@ -134,11 +124,10 @@ const metaIsCsp = (attrs) => {
134
124
  return false;
135
125
  };
136
126
 
137
- /** @typedef {import("webpack-sources").Source} Source */
138
- /** @typedef {import("../../declarations/WebpackOptions").HtmlGeneratorOptions} HtmlGeneratorOptions */
127
+ /** @import { Source } from "webpack-sources" */
128
+ /** @import { HtmlGeneratorOptions } from "../../declarations/WebpackOptions" */
139
129
  /** @typedef {import("../../declarations/WebpackOptions").OutputHtmlOptions["csp"]} CspOption */
140
- /** @typedef {import("./HtmlModulesPlugin").HtmlTagDescriptor} HtmlTagDescriptor */
141
- /** @typedef {import("./HtmlModulesPlugin").HtmlMutableTag} HtmlMutableTag */
130
+ /** @import { HtmlTagDescriptor, HtmlMutableTag } from "./HtmlModulesPlugin" */
142
131
  /** @typedef {"head" | "body"} HtmlTagLocation */
143
132
  /**
144
133
  * @typedef {object} HtmlTagSpan
@@ -152,24 +141,26 @@ const metaIsCsp = (attrs) => {
152
141
  */
153
142
  /** @typedef {{ headOpen: number, headEnd: number, bodyOpen: number, bodyEnd: number }} HtmlAnchors */
154
143
  /** @typedef {{ tags: HtmlMutableTag[], spans: (HtmlTagSpan | null)[], originals: (string | null)[], descriptors: (HtmlTagDescriptor | null)[], anchors: HtmlAnchors }} HtmlModel */
155
- /** @typedef {import("../Chunk")} Chunk */
156
- /** @typedef {import("../Compilation")} Compilation */
144
+ /** @import Chunk from "../Chunk" */
145
+ /** @import Compilation, { DependencyConstructor } from "../Compilation" */
157
146
  /** @typedef {boolean | string[] | ((asset: { chunk: Chunk, filename: string }) => string[] | false)} HtmlIntegrity */
158
- /** @typedef {import("../Compilation").DependencyConstructor} DependencyConstructor */
159
- /** @typedef {import("../CodeGenerationResults")} CodeGenerationResults */
160
- /** @typedef {import("../Dependency")} Dependency */
161
- /** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
162
- /** @typedef {import("../Generator").GenerateContext} GenerateContext */
163
- /** @typedef {import("../Generator").UpdateHashContext} UpdateHashContext */
164
- /** @typedef {import("../Module").SourceType} SourceType */
165
- /** @typedef {import("../Module").SourceTypes} SourceTypes */
166
- /** @typedef {import("../Module").ConcatenationBailoutReasonContext} ConcatenationBailoutReasonContext */
167
- /** @typedef {import("../ModuleGraph")} ModuleGraph */
168
- /** @typedef {import("../NormalModule")} NormalModule */
169
- /** @typedef {import("./HtmlModule").HtmlModuleBuildInfo} HtmlModuleBuildInfo */
170
- /** @typedef {import("../Module").RuntimeRequirements} RuntimeRequirements */
171
- /** @typedef {import("../RuntimeTemplate")} RuntimeTemplate */
172
- /** @typedef {import("../util/Hash")} Hash */
147
+ /** @import CodeGenerationResults from "../CodeGenerationResults" */
148
+ /** @import Dependency from "../Dependency" */
149
+ /** @import { DependencyTemplateContext } from "../DependencyTemplate" */
150
+ /** @import { GenerateContext, UpdateHashContext } from "../Generator" */
151
+ /**
152
+ * @import Module, {
153
+ * SourceType,
154
+ * SourceTypes,
155
+ * ConcatenationBailoutReasonContext,
156
+ * RuntimeRequirements
157
+ * } from "../Module"
158
+ */
159
+ /** @import ModuleGraph from "../ModuleGraph" */
160
+ /** @import NormalModule from "../NormalModule" */
161
+ /** @import { HtmlModuleBuildInfo } from "./HtmlModule" */
162
+ /** @import RuntimeTemplate from "../RuntimeTemplate" */
163
+ /** @import Hash from "../util/Hash" */
173
164
  /**
174
165
  * @template T
175
166
  * @typedef {import("../InitFragment")<T>} InitFragment
@@ -201,6 +192,27 @@ const getChunksById = (compilation) => {
201
192
  return chunksById;
202
193
  };
203
194
 
195
+ /** @type {WeakMap<Compilation, Map<string, Module>>} */
196
+ const modulesByIdentifierCache = new WeakMap();
197
+
198
+ /**
199
+ * `module.identifier()` → module lookup, memoized per compilation so the asset
200
+ * URL sentinel resolver doesn't re-scan the whole module graph per HTML module.
201
+ * @param {Compilation} compilation compilation
202
+ * @returns {Map<string, Module>} modules keyed by identifier
203
+ */
204
+ const getModulesByIdentifier = (compilation) => {
205
+ let modulesByIdentifier = modulesByIdentifierCache.get(compilation);
206
+ if (modulesByIdentifier === undefined) {
207
+ modulesByIdentifier = new Map();
208
+ for (const module of compilation.modules) {
209
+ modulesByIdentifier.set(module.identifier(), module);
210
+ }
211
+ modulesByIdentifierCache.set(compilation, modulesByIdentifier);
212
+ }
213
+ return modulesByIdentifier;
214
+ };
215
+
204
216
  // Hoisted so `resolveChunkUrlSentinels` (per chunk × module) doesn't allocate a
205
217
  // fresh `RegExp` each call. `String#replace` resets `lastIndex`, so sharing the
206
218
  // global-flag instance is safe under these synchronous, non-reentrant calls.
@@ -222,15 +234,23 @@ const HTML_PAGE_URL_SENTINEL_REGEXP =
222
234
  const ASSET_URL_SENTINEL_REGEXP =
223
235
  /__WEBPACK_HTML_ASSET_URL__([0-9a-f]+)__END__/g;
224
236
 
237
+ // Compilations whose HTML modules must emit SRI sentinels (see
238
+ // `enableIntegritySentinels`).
239
+ /** @type {WeakSet<Compilation>} */
240
+ const integritySentinelCompilations = new WeakSet();
241
+
225
242
  // Matches the whole ` integrity="<sentinel>"` so the attribute can be dropped
226
- // entirely when the per-asset `integrity` function returns `false`.
243
+ // entirely when the per-asset `integrity` function returns `false`. Minification
244
+ // runs first and may have unquoted the value (§13.1.2.3), so the quote is
245
+ // optional and back-referenced to keep the pair matched; the replacement always
246
+ // re-quotes, since an SRI list carries spaces and `=` padding.
227
247
  const INTEGRITY_SENTINEL_REGEXP =
228
- / integrity="__WEBPACK_HTML_INTEGRITY__([0-9a-f]+)__([a-z]+)__END__"/g;
248
+ / integrity=(["']?)__WEBPACK_HTML_INTEGRITY__([0-9a-f]+)__([a-z]+)__END__\1/g;
229
249
 
230
250
  // Same attribute, but tolerant of the `\"` escaping the surrounding quotes get
231
251
  // when the HTML lives inside a JS string literal — used only to strip it there.
232
252
  const INTEGRITY_SENTINEL_STRIP_REGEXP =
233
- / integrity=\\?"__WEBPACK_HTML_INTEGRITY__[0-9a-f]+__[a-z]+__END__\\?"/g;
253
+ / integrity=(\\?["']|)__WEBPACK_HTML_INTEGRITY__[0-9a-f]+__[a-z]+__END__\1/g;
234
254
 
235
255
  // The trailing `(?:__<hash>)?` is the inlined chunk's content hash, embedded by
236
256
  // `embedInlineChunkHashes` so the host HTML's bytes (and its `[contenthash]`,
@@ -331,7 +351,7 @@ class HtmlGenerator extends Generator {
331
351
  // handling included), mirroring the CSS branch.
332
352
  let filenameTemplate;
333
353
  if (contentHashType === "css") {
334
- filenameTemplate = getCssModulesPlugin().getChunkFilenameTemplate(
354
+ filenameTemplate = CssModulesPlugin.getChunkFilenameTemplate(
335
355
  chunk,
336
356
  outputOptions
337
357
  );
@@ -413,9 +433,7 @@ class HtmlGenerator extends Generator {
413
433
  */
414
434
  static resolveAssetUrlSentinels(content, compilation) {
415
435
  if (!content.includes("__WEBPACK_HTML_ASSET_URL__")) return content;
416
- /** @type {Map<string, import("../Module")>} */
417
- const byIdentifier = new Map();
418
- for (const m of compilation.modules) byIdentifier.set(m.identifier(), m);
436
+ const byIdentifier = getModulesByIdentifier(compilation);
419
437
  const codeGenerationResults =
420
438
  /** @type {import("../CodeGenerationResults")} */
421
439
  (compilation.codeGenerationResults);
@@ -443,6 +461,26 @@ class HtmlGenerator extends Generator {
443
461
  });
444
462
  }
445
463
 
464
+ /**
465
+ * Turns SRI sentinel emission on for this compilation. Tags are generated
466
+ * once per HTML module, but one module can back several pages with different
467
+ * `integrity` options, so HtmlModulesPlugin flags the compilation when any
468
+ * page wants SRI and each page resolves or strips the sentinels on emit.
469
+ * @param {Compilation} compilation compilation
470
+ * @returns {void}
471
+ */
472
+ static enableIntegritySentinels(compilation) {
473
+ integritySentinelCompilations.add(compilation);
474
+ }
475
+
476
+ /**
477
+ * @param {Compilation} compilation compilation
478
+ * @returns {boolean} true when SRI sentinels must be emitted
479
+ */
480
+ static hasIntegritySentinels(compilation) {
481
+ return integritySentinelCompilations.has(compilation);
482
+ }
483
+
446
484
  /**
447
485
  * Emit a sentinel for a chunk's SRI hash. Resolved late (after
448
486
  * `RealContentHashPlugin`) by `resolveChunkIntegritySentinels`, since the
@@ -489,7 +527,7 @@ class HtmlGenerator extends Generator {
489
527
  const chunksById = getChunksById(compilation);
490
528
  return content.replace(
491
529
  INTEGRITY_SENTINEL_REGEXP,
492
- (_, hexId, contentHashType) => {
530
+ (_, _quote, hexId, contentHashType) => {
493
531
  const chunkId = Buffer.from(hexId, "hex").toString("utf8");
494
532
  const chunk = chunksById.get(chunkId);
495
533
  if (!chunk) return "";
@@ -640,6 +678,7 @@ class HtmlGenerator extends Generator {
640
678
  // `skip.text` populates `contentEnd` (raw-text body end) without
641
679
  // materializing text nodes; `</script` stays escaped, so CSP hashes match
642
680
  // the exact bytes the browser sees.
681
+ const { NodeType, SourceProcessor } = getHtmlSyntax();
643
682
  new SourceProcessor()
644
683
  .use({
645
684
  [NodeType.Element]: {
@@ -648,11 +687,23 @@ class HtmlGenerator extends Generator {
648
687
  if (name === "head") {
649
688
  if (headOpen < 0) headOpen = headEnd = path.tagEnd();
650
689
  headDepth++;
690
+ } else if (name === "body") {
691
+ if (bodyOpen < 0) bodyOpen = bodyEnd = path.tagEnd();
692
+ bodyDepth++;
693
+ }
694
+ },
695
+ // Collected on exit: an element's `end` is only final once it
696
+ // closes, and the streamed walk enters it while it is still open.
697
+ // `script` / `style` / `link` / `meta` never nest in each other, so
698
+ // exiting keeps them in source order.
699
+ exit: (path) => {
700
+ const name = path.tagName();
701
+ if (name === "head") {
702
+ if (headDepth > 0) headDepth--;
651
703
  return;
652
704
  }
653
705
  if (name === "body") {
654
- if (bodyOpen < 0) bodyOpen = bodyEnd = path.tagEnd();
655
- bodyDepth++;
706
+ if (bodyDepth > 0) bodyDepth--;
656
707
  return;
657
708
  }
658
709
  const end = path.end();
@@ -693,14 +744,6 @@ class HtmlGenerator extends Generator {
693
744
  });
694
745
  originals.push(snapshotAttrs(attrs));
695
746
  descriptors.push(null);
696
- },
697
- exit: (path) => {
698
- const name = path.tagName();
699
- if (name === "head") {
700
- if (headDepth > 0) headDepth--;
701
- } else if (name === "body" && bodyDepth > 0) {
702
- bodyDepth--;
703
- }
704
747
  }
705
748
  }
706
749
  })
@@ -743,14 +786,16 @@ class HtmlGenerator extends Generator {
743
786
  * `*-prepend`), or had its `attrs` changed; and — when `csp` is set and the
744
787
  * page declares no CSP — a strict `<meta http-equiv="Content-Security-Policy">`
745
788
  * is injected with a hash of every inline `<script>`/`<style>` (page's own and
746
- * injected) plus an optional placeholder `nonce` on each. Edits run
747
- * right-to-left; at a shared offset a delete/replace runs before an insert.
789
+ * injected) plus an optional placeholder `nonce` on each. Edits are applied
790
+ * in one ascending pass; at a shared offset an insert is emitted before a
791
+ * delete/replace's text.
748
792
  * @param {string} content the collected HTML (inline content already resolved)
749
793
  * @param {HtmlModel} model the value from `collectHtml` after the hooks
750
794
  * @param {CspOption} csp the `output.html.csp` option
751
795
  * @returns {string} the rendered HTML
752
796
  */
753
797
  static renderHtml(content, model, csp) {
798
+ const { escapeAttribute } = getHtmlSyntax();
754
799
  const { tags, spans, originals, descriptors, anchors } = model;
755
800
  // CSP setup: an author-declared policy (page's own or injected) wins.
756
801
  const options = csp ? (csp === true ? {} : csp) : undefined;
@@ -950,14 +995,20 @@ class HtmlGenerator extends Generator {
950
995
  edits.push({ start: pos, end: pos, text, insert: true });
951
996
  }
952
997
  if (edits.length === 0) return content;
998
+ // Ascending single pass over the (non-overlapping) edits — O(page + edits)
999
+ // instead of two full-page copies per edit; the tie-break reproduces the
1000
+ // former right-to-left order (insert text lands before a replacement's).
953
1001
  edits.sort(
954
- (a, b) => b.start - a.start || Number(a.insert) - Number(b.insert)
1002
+ (a, b) => a.start - b.start || Number(b.insert) - Number(a.insert)
955
1003
  );
956
- let result = content;
1004
+ let result = "";
1005
+ let cursor = 0;
957
1006
  for (const edit of edits) {
958
- result = result.slice(0, edit.start) + edit.text + result.slice(edit.end);
1007
+ result += content.slice(cursor, edit.start);
1008
+ result += edit.text;
1009
+ if (edit.end > cursor) cursor = edit.end;
959
1010
  }
960
- return result;
1011
+ return result + content.slice(cursor);
961
1012
  }
962
1013
 
963
1014
  /**
@@ -1273,8 +1324,18 @@ class HtmlGenerator extends Generator {
1273
1324
  );
1274
1325
  }
1275
1326
 
1276
- // JS export: resolve `[webpack/auto]` to root-relative URLs.
1277
- const generated = this._renderHtml(module, generateContext, "");
1327
+ // JS export: resolve `[webpack/auto]` to root-relative URLs. No `.html`
1328
+ // asset carries this markup, so an asset-level minimizer never sees it.
1329
+ const embedded =
1330
+ generateContext.runtimeTemplate.compilation._resolveEmbeddedSource(
1331
+ new RawSource(this._renderHtml(module, generateContext, "")),
1332
+ { type: HTML_TYPE, hostType: JAVASCRIPT_TYPE, module }
1333
+ );
1334
+ const embeddedSource = embedded.source();
1335
+ const generated =
1336
+ typeof embeddedSource === "string"
1337
+ ? embeddedSource
1338
+ : embeddedSource.toString("utf8");
1278
1339
 
1279
1340
  /** @type {string} */
1280
1341
  let sourceContent;
@@ -1329,13 +1390,21 @@ class HtmlGenerator extends Generator {
1329
1390
  * exactly as a full page reload would render them.
1330
1391
  *
1331
1392
  * `<head>` changes beyond `<title>` (a new `<meta>`, a swapped
1332
- * `<link rel=icon>`, an inline `<style>` block, …) can't be safely
1333
- * DOM-patched: webpack injects its own runtime scripts and stylesheet
1334
- * links into the head on initial load, and blindly replacing
1335
- * `document.head.innerHTML` would tear them down. So the shim falls
1336
- * back to a full reload — fine in a dev-server context because the
1337
- * regular (non-hot-update) `page.html` chunk is re-emitted on every
1338
- * rebuild, so the reloaded page picks up the new head.
1393
+ * `<link rel=icon>`, an inline `<style>` block, …) are applied as a
1394
+ * delta against the previous evaluation's authored head. Replacing
1395
+ * `document.head.innerHTML` wholesale would tear down the runtime
1396
+ * scripts and stylesheet links webpack injects there on initial load;
1397
+ * a delta cannot, since those appear in neither authored head. An
1398
+ * added `<script>` is re-created before it is inserted, so it runs the
1399
+ * way the reload this replaces would have run it, and every addition
1400
+ * lands at its authored position rather than at the end. Two edits are
1401
+ * still worth reloading for: a removed `<script>` the browser *executed*,
1402
+ * since one that has run cannot be un-run (a removed data block such as
1403
+ * `application/ld+json` never ran, so it is patched like any other
1404
+ * element), and a reordering of elements the delta cannot
1405
+ * express — fine in a dev-server context because the regular
1406
+ * (non-hot-update) `page.html` chunk is re-emitted on every rebuild,
1407
+ * so the reloaded page picks up the new head.
1339
1408
  * @param {NormalModule} module module
1340
1409
  * @param {string} html the rewritten HTML content (with placeholders resolved)
1341
1410
  * @param {boolean} extracting whether the HTML module is being extracted as a real `.html` file
@@ -1344,6 +1413,7 @@ class HtmlGenerator extends Generator {
1344
1413
  */
1345
1414
  _renderHmrShim(module, html, extracting, runtimeTemplate) {
1346
1415
  const declare = runtimeTemplate.renderConst();
1416
+ const mutable = runtimeTemplate.renderLet();
1347
1417
  const acceptBlock = extracting
1348
1418
  ? [
1349
1419
  "module.hot.accept();",
@@ -1389,10 +1459,151 @@ class HtmlGenerator extends Generator {
1389
1459
  'return head === null ? "" : __webpack_mask_comments__(head).replace(/<title[^>]*>[\\s\\S]*?<\\/title>/i, "").trim();'
1390
1460
  ]
1391
1461
  )};`,
1462
+ // The authored head's elements, parsed but detached.
1463
+ `${declare} __webpack_head_children__ = ${runtimeTemplate.basicFunction(
1464
+ "html",
1465
+ [
1466
+ `${declare} container = document.createElement("head");`,
1467
+ "container.innerHTML = html;",
1468
+ "return Array.prototype.slice.call(container.children);"
1469
+ ]
1470
+ )};`,
1471
+ // A `<script>` parsed out of a string carries the already-started flag,
1472
+ // so appending that element would never run it. A fresh one with the
1473
+ // same attributes and body does — which is what the reload this
1474
+ // replaces would have done.
1475
+ `${declare} __webpack_revive_script__ = ${runtimeTemplate.basicFunction(
1476
+ "node",
1477
+ [
1478
+ 'if (node.nodeName !== "SCRIPT") return node;',
1479
+ `${declare} script = document.createElement("script");`,
1480
+ `${declare} attributes = node.attributes;`,
1481
+ `for (${mutable} i = 0; i < attributes.length; i++) {`,
1482
+ Template.indent(
1483
+ "script.setAttribute(attributes[i].name, attributes[i].value);"
1484
+ ),
1485
+ "}",
1486
+ "script.textContent = node.textContent;",
1487
+ "return script;"
1488
+ ]
1489
+ )};`,
1490
+ // Apply only the difference between the two authored heads, keyed on
1491
+ // serialized markup: the runtime's own injected `<script>` / `<link>`
1492
+ // are in neither string, so replacing `document.head` wholesale would
1493
+ // tear them down while a delta never touches them. Reports whether it
1494
+ // could — the caller reloads when it could not.
1495
+ `${declare} __webpack_patch_head__ = ${runtimeTemplate.basicFunction(
1496
+ "oldHtml, newHtml",
1497
+ [
1498
+ "if (!document.head) return false;",
1499
+ `${declare} oldChildren = __webpack_head_children__(oldHtml);`,
1500
+ `${declare} newChildren = __webpack_head_children__(newHtml);`,
1501
+ `${declare} count = ${runtimeTemplate.basicFunction("nodes", [
1502
+ `${declare} counts = {};`,
1503
+ `for (${mutable} i = 0; i < nodes.length; i++) {`,
1504
+ Template.indent([
1505
+ `${declare} key = "$" + nodes[i].outerHTML;`,
1506
+ "counts[key] = (counts[key] || 0) + 1;"
1507
+ ]),
1508
+ "}",
1509
+ "return counts;"
1510
+ ])};`,
1511
+ // An element present the same number of times on both sides is
1512
+ // untouched; whatever is left over on one side is the delta.
1513
+ `${declare} surplus = ${runtimeTemplate.basicFunction(
1514
+ "nodes, others",
1515
+ [
1516
+ `${declare} counts = count(others);`,
1517
+ `${declare} out = [];`,
1518
+ `for (${mutable} i = 0; i < nodes.length; i++) {`,
1519
+ Template.indent([
1520
+ `${declare} key = "$" + nodes[i].outerHTML;`,
1521
+ "if (counts[key] > 0) counts[key]--; else out.push(nodes[i]);"
1522
+ ]),
1523
+ "}",
1524
+ "return out;"
1525
+ ]
1526
+ )};`,
1527
+ `${declare} removed = surplus(oldChildren, newChildren);`,
1528
+ `${declare} added = surplus(newChildren, oldChildren);`,
1529
+ "if (removed.length === 0 && added.length === 0) return true;",
1530
+ // A script that has run cannot be un-run, so dropping one is the
1531
+ // one edit still worth a reload — but only a script that ran. A
1532
+ // `type` that is neither a JavaScript MIME type nor `module` /
1533
+ // `importmap` / `speculationrules` makes the element a data block
1534
+ // (`application/ld+json`, `text/template`, …) the browser never
1535
+ // executed, so removing it is as safe as removing a `<meta>`.
1536
+ // Every JavaScript MIME essence ends in `script`, and a type
1537
+ // nothing here recognizes falls back to the reload.
1538
+ `if (removed.some(${runtimeTemplate.basicFunction("node", [
1539
+ 'if (node.nodeName !== "SCRIPT") return false;',
1540
+ `${declare} type = (node.getAttribute("type") || "").trim().toLowerCase();`,
1541
+ 'return type === "" || type.indexOf("script") !== -1 || type === "module" || type === "importmap" || type === "speculationrules";'
1542
+ ])})) return false;`,
1543
+ // Resolve every removal before mutating, so a node the page
1544
+ // dropped on its own leaves the head as it was.
1545
+ `${declare} live = [];`,
1546
+ `for (${mutable} i = 0; i < removed.length; i++) {`,
1547
+ Template.indent([
1548
+ `${declare} key = removed[i].outerHTML;`,
1549
+ `${mutable} match = null;`,
1550
+ `for (${mutable} j = 0; j < document.head.children.length; j++) {`,
1551
+ Template.indent([
1552
+ `${declare} child = document.head.children[j];`,
1553
+ "if (child.outerHTML === key && live.indexOf(child) === -1) { match = child; break; }"
1554
+ ]),
1555
+ "}",
1556
+ "if (match === null) return false;",
1557
+ "live.push(match);"
1558
+ ]),
1559
+ "}",
1560
+ `for (${mutable} i = 0; i < live.length; i++) document.head.removeChild(live[i]);`,
1561
+ // Pair each retained element with its live node, scanning only
1562
+ // forward: an authored element that has moved relative to the
1563
+ // others finds no match from there on, and a reorder the delta
1564
+ // cannot express falls back to the reload. Injected nodes simply
1565
+ // never match, so they neither anchor nor block anything.
1566
+ `${declare} liveByNew = [];`,
1567
+ `${mutable} searchFrom = 0;`,
1568
+ `for (${mutable} i = 0; i < newChildren.length; i++) {`,
1569
+ Template.indent([
1570
+ "if (added.indexOf(newChildren[i]) !== -1) { liveByNew.push(null); continue; }",
1571
+ `${declare} key = newChildren[i].outerHTML;`,
1572
+ `${mutable} match = null;`,
1573
+ `for (${mutable} j = searchFrom; j < document.head.children.length; j++) {`,
1574
+ Template.indent([
1575
+ `${declare} child = document.head.children[j];`,
1576
+ "if (child.outerHTML === key) { match = child; searchFrom = j + 1; break; }"
1577
+ ]),
1578
+ "}",
1579
+ "if (match === null) return false;",
1580
+ "liveByNew.push(match);"
1581
+ ]),
1582
+ "}",
1583
+ // Back to front, so the element an addition must precede is
1584
+ // already placed by the time it is needed.
1585
+ `for (${mutable} i = newChildren.length - 1; i >= 0; i--) {`,
1586
+ Template.indent([
1587
+ "if (liveByNew[i] !== null) continue;",
1588
+ `${mutable} anchor = null;`,
1589
+ `for (${mutable} j = i + 1; j < newChildren.length; j++) {`,
1590
+ Template.indent(
1591
+ "if (liveByNew[j] !== null) { anchor = liveByNew[j]; break; }"
1592
+ ),
1593
+ "}",
1594
+ `${declare} node = __webpack_revive_script__(newChildren[i]);`,
1595
+ "if (anchor === null) document.head.appendChild(node);",
1596
+ "else document.head.insertBefore(node, anchor);",
1597
+ "liveByNew[i] = node;"
1598
+ ]),
1599
+ "}",
1600
+ "return true;"
1601
+ ]
1602
+ )};`,
1392
1603
  "if (module.hot.data && typeof document !== 'undefined') {",
1393
1604
  Template.indent([
1394
1605
  `${declare} __webpack_new_head__ = __webpack_extract_head__();`,
1395
- "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') {",
1606
+ "if (module.hot.data.__webpack_head__ !== undefined && __webpack_new_head__ !== module.hot.data.__webpack_head__ && !__webpack_patch_head__(module.hot.data.__webpack_head__, __webpack_new_head__) && typeof window !== 'undefined' && window.location && typeof window.location.reload === 'function') {",
1396
1607
  Template.indent("window.location.reload();"),
1397
1608
  "} else {",
1398
1609
  Template.indent([
@@ -1437,7 +1648,7 @@ class HtmlGenerator extends Generator {
1437
1648
  .replace(/-{2,}/g, (m) => `${"-".repeat(m.length - 1)} `);
1438
1649
  return new RawSource(`<!-- webpack error: ${safe} -->`);
1439
1650
  }
1440
- return new RawSource(`throw new Error(${JSON.stringify(error.message)});`);
1651
+ return new RawSource(Generator.throwBuildErrorCode(error));
1441
1652
  }
1442
1653
 
1443
1654
  /**
@@ -1464,6 +1675,15 @@ class HtmlGenerator extends Generator {
1464
1675
  if (updateHashContext.module.hot) {
1465
1676
  hash.update("hot");
1466
1677
  }
1678
+ // A `renderEmbeddedSource` tap has to reach the codegen cache key, or a
1679
+ // changed option replays the output from before it.
1680
+ const { runtimeTemplate } = updateHashContext;
1681
+ if (runtimeTemplate) {
1682
+ runtimeTemplate.compilation.hooks.embeddedSourceHash.call(
1683
+ updateHashContext.module,
1684
+ hash
1685
+ );
1686
+ }
1467
1687
  }
1468
1688
  }
1469
1689
 
@@ -7,9 +7,13 @@
7
7
  const NormalModule = require("../NormalModule");
8
8
  const makeSerializable = require("../util/makeSerializable");
9
9
 
10
- /** @typedef {import("../NormalModule").NormalModuleBuildInfo} NormalModuleBuildInfo */
11
- /** @typedef {import("../NormalModule").NormalModuleCreateData} NormalModuleCreateData */
12
- /** @typedef {import("./HtmlModulesPlugin").HtmlEntryInfo} HtmlEntryInfo */
10
+ /**
11
+ * @import {
12
+ * NormalModuleBuildInfo,
13
+ * NormalModuleCreateData
14
+ * } from "../NormalModule"
15
+ */
16
+ /** @import { HtmlEntryInfo } from "./HtmlModulesPlugin" */
13
17
 
14
18
  /**
15
19
  * Defines the build info properties specific to html modules.