@depup/webpack 5.109.2-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 (640) hide show
  1. package/README.md +5 -5
  2. package/changes.json +7 -7
  3. package/lib/APIPlugin.js +123 -17
  4. package/lib/AsyncDependenciesBlock.js +10 -7
  5. package/lib/AutomaticPrefetchPlugin.js +1 -1
  6. package/lib/BannerPlugin.js +10 -6
  7. package/lib/CacheFacade.js +6 -6
  8. package/lib/Chunk.js +14 -11
  9. package/lib/ChunkGraph.js +26 -17
  10. package/lib/ChunkGroup.js +7 -7
  11. package/lib/ChunkTemplate.js +35 -44
  12. package/lib/CircularModulesPlugin.js +205 -28
  13. package/lib/CleanPlugin.js +4 -7
  14. package/lib/CodeGenerationResults.js +11 -8
  15. package/lib/CompatibilityPlugin.js +7 -7
  16. package/lib/Compilation.js +688 -409
  17. package/lib/Compiler.js +53 -38
  18. package/lib/ConcatenationScope.js +117 -8
  19. package/lib/ConditionalInitFragment.js +3 -3
  20. package/lib/ConstPlugin.js +13 -11
  21. package/lib/ContextExclusionPlugin.js +1 -1
  22. package/lib/ContextModule.js +146 -54
  23. package/lib/ContextModuleFactory.js +46 -14
  24. package/lib/ContextReplacementPlugin.js +12 -14
  25. package/lib/DefinePlugin.js +121 -37
  26. package/lib/DependenciesBlock.js +9 -6
  27. package/lib/Dependency.js +36 -16
  28. package/lib/DependencyTemplate.js +11 -12
  29. package/lib/DependencyTemplates.js +3 -3
  30. package/lib/DotenvPlugin.js +50 -13
  31. package/lib/DynamicEntryPlugin.js +8 -4
  32. package/lib/EntryOptionPlugin.js +8 -4
  33. package/lib/EntryPlugin.js +2 -2
  34. package/lib/Entrypoint.js +6 -2
  35. package/lib/EnvironmentPlugin.js +2 -2
  36. package/lib/EvalDevToolModulePlugin.js +8 -4
  37. package/lib/EvalSourceMapDevToolPlugin.js +15 -8
  38. package/lib/ExportsInfo.js +101 -14
  39. package/lib/ExportsInfoApiPlugin.js +2 -4
  40. package/lib/ExternalModule.js +232 -77
  41. package/lib/ExternalModuleFactoryPlugin.js +97 -38
  42. package/lib/ExternalsPlugin.js +10 -6
  43. package/lib/FileSystemInfo.js +44 -70
  44. package/lib/FlagAllModulesAsUsedPlugin.js +2 -3
  45. package/lib/FlagDependencyExportsPlugin.js +76 -19
  46. package/lib/FlagDependencyUsagePlugin.js +32 -47
  47. package/lib/FlagEntryExportAsUsedPlugin.js +1 -1
  48. package/lib/Generator.js +36 -15
  49. package/lib/HotModuleReplacementPlugin.js +16 -44
  50. package/lib/IgnorePlugin.js +8 -4
  51. package/lib/IgnoreWarningsPlugin.js +2 -2
  52. package/lib/InitFragment.js +8 -4
  53. package/lib/JavascriptMetaInfoPlugin.js +35 -4
  54. package/lib/LazyBarrel.js +3 -4
  55. package/lib/LibraryTemplatePlugin.js +10 -6
  56. package/lib/LoaderOptionsPlugin.js +7 -3
  57. package/lib/LoaderTargetPlugin.js +1 -1
  58. package/lib/MainTemplate.js +49 -42
  59. package/lib/ManifestPlugin.js +12 -11
  60. package/lib/Module.js +62 -33
  61. package/lib/ModuleFactory.js +3 -3
  62. package/lib/ModuleFilenameHelpers.js +9 -4
  63. package/lib/ModuleGraph.js +195 -21
  64. package/lib/ModuleGraphConnection.js +6 -13
  65. package/lib/ModuleInfoHeaderPlugin.js +8 -10
  66. package/lib/ModuleTemplate.js +62 -63
  67. package/lib/MultiCompiler.js +130 -64
  68. package/lib/MultiStats.js +40 -9
  69. package/lib/MultiWatching.js +3 -3
  70. package/lib/NoEmitOnErrorsPlugin.js +1 -1
  71. package/lib/NodeStuffPlugin.js +29 -19
  72. package/lib/NormalModule.js +141 -85
  73. package/lib/NormalModuleFactory.js +555 -110
  74. package/lib/NormalModuleReplacementPlugin.js +5 -8
  75. package/lib/NullFactory.js +6 -2
  76. package/lib/OptionsApply.js +7 -3
  77. package/lib/Parser.js +7 -3
  78. package/lib/PlatformPlugin.js +2 -2
  79. package/lib/PrefetchPlugin.js +1 -1
  80. package/lib/ProgressPlugin.js +16 -13
  81. package/lib/ProvidePlugin.js +3 -5
  82. package/lib/RawModule.js +25 -17
  83. package/lib/RecordIdsPlugin.js +3 -3
  84. package/lib/RequestShortener.js +1 -1
  85. package/lib/ResolverFactory.js +2 -2
  86. package/lib/RuntimeGlobals.js +22 -10
  87. package/lib/RuntimeModule.js +29 -19
  88. package/lib/RuntimePlugin.js +332 -169
  89. package/lib/RuntimeTemplate.js +2792 -352
  90. package/lib/SelfModuleFactory.js +7 -3
  91. package/lib/SourceMapDevToolModuleOptionsPlugin.js +6 -2
  92. package/lib/SourceMapDevToolPlugin.js +30 -20
  93. package/lib/Stats.js +3 -4
  94. package/lib/Template.js +32 -22
  95. package/lib/TemplatedPathPlugin.js +96 -14
  96. package/lib/UseStrictPlugin.js +4 -6
  97. package/lib/WarnCaseSensitiveModulesPlugin.js +4 -4
  98. package/lib/WarnDeprecatedOptionPlugin.js +1 -1
  99. package/lib/WarnNoModeSetPlugin.js +1 -1
  100. package/lib/WatchIgnorePlugin.js +8 -6
  101. package/lib/Watching.js +8 -8
  102. package/lib/WebpackIsIncludedPlugin.js +2 -4
  103. package/lib/WebpackOptionsApply.js +308 -18
  104. package/lib/WebpackOptionsDefaulter.js +6 -2
  105. package/lib/asset/AssetBytesGenerator.js +12 -10
  106. package/lib/asset/AssetBytesParser.js +2 -4
  107. package/lib/asset/AssetGenerator.js +188 -95
  108. package/lib/asset/AssetModule.js +7 -3
  109. package/lib/asset/AssetModulesPlugin.js +110 -38
  110. package/lib/asset/AssetParser.js +9 -7
  111. package/lib/asset/AssetSourceGenerator.js +60 -13
  112. package/lib/asset/AssetSourceParser.js +2 -4
  113. package/lib/asset/RawDataUrlModule.js +24 -16
  114. package/lib/asset/WebManifestGenerator.js +8 -10
  115. package/lib/asset/WebManifestParser.js +24 -10
  116. package/lib/async-modules/AsyncModuleHelpers.js +2 -2
  117. package/lib/async-modules/AwaitDependenciesInitFragment.js +2 -2
  118. package/lib/async-modules/InferAsyncModulesPlugin.js +2 -2
  119. package/lib/async-modules/isGeneratorLowered.js +4 -4
  120. package/lib/buildChunkGraph.js +36 -27
  121. package/lib/bun/BunTargetPlugin.js +1 -1
  122. package/lib/cache/AddBuildDependenciesPlugin.js +1 -1
  123. package/lib/cache/AddManagedPathsPlugin.js +1 -1
  124. package/lib/cache/IdleFileCachePlugin.js +2 -2
  125. package/lib/cache/MemoryCachePlugin.js +18 -10
  126. package/lib/cache/MemoryWithGcCachePlugin.js +34 -22
  127. package/lib/cache/PackFileCacheStrategy.js +30 -23
  128. package/lib/cache/ResolverCachePlugin.js +38 -18
  129. package/lib/cache/getLazyHashedEtag.js +1 -2
  130. package/lib/cache/mergeEtags.js +1 -1
  131. package/lib/cli.js +1 -3
  132. package/lib/config/browserslistTargetHandler.js +41 -5
  133. package/lib/config/defaults.js +261 -79
  134. package/lib/config/defineConfig.js +10 -2
  135. package/lib/config/getClaimedAssetTypes.js +65 -0
  136. package/lib/config/normalization.js +36 -16
  137. package/lib/config/target.js +46 -3
  138. package/lib/container/ContainerEntryDependency.js +1 -1
  139. package/lib/container/ContainerEntryModule.js +24 -15
  140. package/lib/container/ContainerEntryModuleFactory.js +7 -3
  141. package/lib/container/ContainerPlugin.js +9 -10
  142. package/lib/container/ContainerReferencePlugin.js +6 -2
  143. package/lib/container/FallbackDependency.js +1 -1
  144. package/lib/container/FallbackModule.js +24 -17
  145. package/lib/container/FallbackModuleFactory.js +7 -3
  146. package/lib/container/HoistContainerReferencesPlugin.js +6 -11
  147. package/lib/container/ModuleFederationPlugin.js +7 -24
  148. package/lib/container/RemoteModule.js +27 -19
  149. package/lib/container/RemoteRuntimeModule.js +10 -8
  150. package/lib/container/moduleFederationHooks.js +32 -0
  151. package/lib/css/CssGenerator.js +171 -43
  152. package/lib/css/CssInjectStyleRuntimeModule.js +7 -5
  153. package/lib/css/CssLoadingRuntimeModule.js +57 -24
  154. package/lib/css/CssModule.js +10 -7
  155. package/lib/css/CssModulesPlugin.js +168 -88
  156. package/lib/css/CssParser.js +1113 -568
  157. package/lib/css/CssServerStylesRuntimeModule.js +54 -0
  158. package/lib/css/cssMinify.js +168 -0
  159. package/lib/css/data.js +5324 -0
  160. package/lib/css/syntax.js +9579 -232
  161. package/lib/debug/ProfilingPlugin.js +14 -9
  162. package/lib/deno/DenoTargetPlugin.js +1 -1
  163. package/lib/dependencies/AMDDefineDependency.js +112 -87
  164. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +30 -17
  165. package/lib/dependencies/AMDPlugin.js +9 -7
  166. package/lib/dependencies/AMDRequireArrayDependency.js +5 -5
  167. package/lib/dependencies/AMDRequireContextDependency.js +2 -2
  168. package/lib/dependencies/AMDRequireDependenciesBlock.js +1 -1
  169. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +25 -14
  170. package/lib/dependencies/AMDRequireDependency.js +8 -7
  171. package/lib/dependencies/AMDRequireItemDependency.js +1 -1
  172. package/lib/dependencies/AMDRuntimeModules.js +21 -1
  173. package/lib/dependencies/BuildTimeConstDependency.js +102 -0
  174. package/lib/dependencies/CachedConstDependency.js +11 -8
  175. package/lib/dependencies/CommonJsDependencyHelpers.js +67 -46
  176. package/lib/dependencies/CommonJsExportRequireDependency.js +121 -45
  177. package/lib/dependencies/CommonJsExportsDependency.js +53 -49
  178. package/lib/dependencies/CommonJsExportsParserPlugin.js +207 -25
  179. package/lib/dependencies/CommonJsFullRequireDependency.js +119 -34
  180. package/lib/dependencies/CommonJsImportsParserPlugin.js +100 -50
  181. package/lib/dependencies/CommonJsObjectExportDependency.js +188 -0
  182. package/lib/dependencies/CommonJsPlugin.js +35 -6
  183. package/lib/dependencies/CommonJsRequireContextDependency.js +5 -6
  184. package/lib/dependencies/CommonJsRequireDependency.js +156 -27
  185. package/lib/dependencies/CommonJsSelfReferenceDependency.js +63 -38
  186. package/lib/dependencies/ConstDependency.js +8 -9
  187. package/lib/dependencies/ContextDependency.js +12 -8
  188. package/lib/dependencies/ContextDependencyHelpers.js +14 -9
  189. package/lib/dependencies/ContextDependencyTemplateAsId.js +4 -4
  190. package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +4 -4
  191. package/lib/dependencies/ContextElementDependency.js +31 -12
  192. package/lib/dependencies/CreateRequireParserPlugin.js +12 -7
  193. package/lib/dependencies/CreateScriptUrlDependency.js +4 -4
  194. package/lib/dependencies/CssIcssExportDependency.js +56 -28
  195. package/lib/dependencies/CssIcssImportDependency.js +17 -13
  196. package/lib/dependencies/CssIcssSymbolDependency.js +9 -10
  197. package/lib/dependencies/CssImportDependency.js +18 -9
  198. package/lib/dependencies/CssUrlDependency.js +17 -13
  199. package/lib/dependencies/DllEntryDependency.js +1 -1
  200. package/lib/dependencies/DynamicExports.js +2 -2
  201. package/lib/dependencies/ExportBindingInitFragment.js +36 -9
  202. package/lib/dependencies/ExportsInfoDependency.js +7 -8
  203. package/lib/dependencies/ExternalModuleDependency.js +9 -5
  204. package/lib/dependencies/ExternalModuleInitFragment.js +2 -2
  205. package/lib/dependencies/ExternalModuleInitFragmentDependency.js +8 -5
  206. package/lib/dependencies/HarmonyAcceptDependency.js +5 -5
  207. package/lib/dependencies/HarmonyCompatibilityDependency.js +52 -17
  208. package/lib/dependencies/HarmonyDetectionParserPlugin.js +11 -7
  209. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +13 -10
  210. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +78 -12
  211. package/lib/dependencies/HarmonyExportExpressionDependency.js +23 -18
  212. package/lib/dependencies/HarmonyExportHeaderDependency.js +7 -7
  213. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +143 -63
  214. package/lib/dependencies/HarmonyExportInitFragment.js +18 -6
  215. package/lib/dependencies/HarmonyExportSpecifierDependency.js +51 -14
  216. package/lib/dependencies/HarmonyExports.js +7 -4
  217. package/lib/dependencies/HarmonyImportDependency.js +27 -19
  218. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +31 -24
  219. package/lib/dependencies/HarmonyImportGuard.js +20 -30
  220. package/lib/dependencies/HarmonyImportSideEffectDependency.js +38 -9
  221. package/lib/dependencies/HarmonyImportSpecifierDependency.js +97 -49
  222. package/lib/dependencies/HarmonyModulesPlugin.js +7 -3
  223. package/lib/dependencies/HarmonyTopLevelThisParserPlugin.js +1 -3
  224. package/lib/dependencies/HtmlEntryDependency.js +37 -29
  225. package/lib/dependencies/HtmlInlineHtmlDependency.js +7 -8
  226. package/lib/dependencies/HtmlInlineScriptDependency.js +11 -8
  227. package/lib/dependencies/HtmlInlineStyleDependency.js +7 -10
  228. package/lib/dependencies/HtmlSourceDependency.js +22 -14
  229. package/lib/dependencies/ImportContextDependency.js +2 -2
  230. package/lib/dependencies/ImportDependency.js +24 -20
  231. package/lib/dependencies/ImportEagerDependency.js +6 -9
  232. package/lib/dependencies/ImportMetaContextDependency.js +2 -2
  233. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +14 -13
  234. package/lib/dependencies/ImportMetaContextPlugin.js +7 -3
  235. package/lib/dependencies/ImportMetaGlobDependency.js +2 -2
  236. package/lib/dependencies/ImportMetaGlobDependencyParserPlugin.js +2 -3
  237. package/lib/dependencies/ImportMetaGlobHelpers.js +19 -22
  238. package/lib/dependencies/ImportMetaHotAcceptDependency.js +1 -1
  239. package/lib/dependencies/ImportMetaHotDeclineDependency.js +1 -1
  240. package/lib/dependencies/ImportMetaPlugin.js +154 -71
  241. package/lib/dependencies/ImportMetaResolveDependency.js +3 -4
  242. package/lib/dependencies/ImportParserPlugin.js +49 -35
  243. package/lib/dependencies/ImportPhase.js +12 -5
  244. package/lib/dependencies/ImportPlugin.js +7 -3
  245. package/lib/dependencies/ImportWeakDependency.js +6 -9
  246. package/lib/dependencies/JsonExportsDependency.js +11 -7
  247. package/lib/dependencies/LoaderDependency.js +2 -2
  248. package/lib/dependencies/LoaderImportDependency.js +2 -2
  249. package/lib/dependencies/LoaderPlugin.js +11 -7
  250. package/lib/dependencies/LocalModuleDependency.js +5 -5
  251. package/lib/dependencies/LocalModulesHelpers.js +1 -1
  252. package/lib/dependencies/ModuleDecoratorDependency.js +6 -7
  253. package/lib/dependencies/ModuleDependency.js +9 -6
  254. package/lib/dependencies/ModuleDependencyTemplateAsId.js +4 -4
  255. package/lib/dependencies/ModuleDependencyTemplateAsRequireId.js +3 -3
  256. package/lib/dependencies/ModuleHotAcceptDependency.js +1 -1
  257. package/lib/dependencies/ModuleHotDeclineDependency.js +1 -1
  258. package/lib/dependencies/ModuleInitFragmentDependency.js +24 -10
  259. package/lib/dependencies/NullDependency.js +3 -3
  260. package/lib/dependencies/ProvidedDependency.js +14 -10
  261. package/lib/dependencies/PureExpressionDependency.js +9 -10
  262. package/lib/dependencies/RequireContextDependency.js +2 -2
  263. package/lib/dependencies/RequireContextDependencyParserPlugin.js +2 -4
  264. package/lib/dependencies/RequireContextPlugin.js +8 -4
  265. package/lib/dependencies/RequireEnsureDependenciesBlock.js +2 -2
  266. package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +5 -8
  267. package/lib/dependencies/RequireEnsureDependency.js +8 -7
  268. package/lib/dependencies/RequireEnsurePlugin.js +7 -3
  269. package/lib/dependencies/RequireHeaderDependency.js +51 -12
  270. package/lib/dependencies/RequireIncludeDependency.js +6 -6
  271. package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +2 -3
  272. package/lib/dependencies/RequireIncludePlugin.js +7 -3
  273. package/lib/dependencies/RequireJsStuffPlugin.js +7 -3
  274. package/lib/dependencies/RequireResolveContextDependency.js +2 -2
  275. package/lib/dependencies/RequireResolveDependency.js +4 -4
  276. package/lib/dependencies/RequireResolveHeaderDependency.js +4 -4
  277. package/lib/dependencies/RuntimeRequirementsDependency.js +5 -6
  278. package/lib/dependencies/StaticExportsDependency.js +2 -2
  279. package/lib/dependencies/SystemPlugin.js +10 -6
  280. package/lib/dependencies/SystemRuntimeModule.js +10 -0
  281. package/lib/dependencies/TopLevelAwaitDependency.js +11 -7
  282. package/lib/dependencies/URLContextDependency.js +2 -2
  283. package/lib/dependencies/URLDependency.js +110 -64
  284. package/lib/dependencies/URLPlugin.js +7 -3
  285. package/lib/dependencies/UnsupportedDependency.js +4 -4
  286. package/lib/dependencies/WebAssemblyExportImportedDependency.js +3 -4
  287. package/lib/dependencies/WebAssemblyImportDependency.js +5 -5
  288. package/lib/dependencies/WebpackIsIncludedDependency.js +6 -6
  289. package/lib/dependencies/WorkerAndWorkletPlugin.js +46 -28
  290. package/lib/dependencies/WorkerDependency.js +28 -22
  291. package/lib/dependencies/WorkletDependency.js +15 -14
  292. package/lib/dependencies/getFunctionExpression.js +8 -4
  293. package/lib/dependencies/processExportInfo.js +5 -5
  294. package/lib/dll/DelegatedModule.js +34 -22
  295. package/lib/dll/DelegatedModuleFactoryPlugin.js +15 -7
  296. package/lib/dll/DelegatedPlugin.js +2 -2
  297. package/lib/dll/DllEntryPlugin.js +2 -2
  298. package/lib/dll/DllModule.js +22 -15
  299. package/lib/dll/DllModuleFactory.js +7 -3
  300. package/lib/dll/DllPlugin.js +7 -5
  301. package/lib/dll/DllReferencePlugin.js +10 -7
  302. package/lib/dll/LibManifestPlugin.js +5 -5
  303. package/lib/electron/ElectronTargetPlugin.js +53 -49
  304. package/lib/errors/AsyncChunkWaterfallWarning.js +36 -0
  305. package/lib/errors/AsyncDependencyToInitialChunkError.js +2 -2
  306. package/lib/errors/BroadContextsWarning.js +43 -0
  307. package/lib/errors/BuildCycleError.js +1 -1
  308. package/lib/errors/CacheEffectivenessWarning.js +55 -0
  309. package/lib/errors/ChunkRenderError.js +1 -1
  310. package/lib/errors/CircularDependenciesWarning.js +38 -0
  311. package/lib/errors/CodeGenerationError.js +1 -1
  312. package/lib/errors/CommentCompilationWarning.js +1 -1
  313. package/lib/errors/ConflictingResourceHintsWarning.js +35 -0
  314. package/lib/errors/DuplicateModulesWarning.js +45 -0
  315. package/lib/errors/DynamicExportsWarning.js +30 -0
  316. package/lib/errors/EmbeddedSourceMapsWarning.js +25 -0
  317. package/lib/errors/EntrypointOverlapWarning.js +45 -0
  318. package/lib/errors/EnvironmentNotSupportAsyncWarning.js +2 -2
  319. package/lib/errors/EvalUsageWarning.js +28 -0
  320. package/lib/errors/HookWebpackError.js +5 -5
  321. package/lib/errors/HotspotsWarning.js +57 -0
  322. package/lib/errors/IgnoreErrorModuleFactory.js +7 -3
  323. package/lib/errors/InlinedAssetsWarning.js +36 -0
  324. package/lib/errors/InvalidDependenciesModuleWarning.js +1 -1
  325. package/lib/errors/LargeModulesWarning.js +45 -0
  326. package/lib/errors/LegacyJavascriptWarning.js +48 -0
  327. package/lib/errors/MissingSideEffectsWarning.js +36 -0
  328. package/lib/errors/MixedExportsWarning.js +41 -0
  329. package/lib/errors/ModuleDependencyError.js +13 -16
  330. package/lib/errors/ModuleDependencyWarning.js +5 -15
  331. package/lib/errors/ModuleHashingError.js +1 -1
  332. package/lib/errors/ModuleNotFoundError.js +2 -2
  333. package/lib/errors/ModuleParseError.js +1 -2
  334. package/lib/errors/ModuleRestoreError.js +1 -1
  335. package/lib/errors/ModuleStoreError.js +1 -1
  336. package/lib/errors/NodeStuffInWebError.js +1 -1
  337. package/lib/errors/OsDependentRuleWarning.js +31 -0
  338. package/lib/errors/PureAnnotationsWarning.js +36 -0
  339. package/lib/errors/RedundantDynamicImportWarning.js +31 -0
  340. package/lib/errors/ScopeHoistingBailoutsWarning.js +41 -0
  341. package/lib/errors/SplitChunksCappedWarning.js +41 -0
  342. package/lib/errors/TinyChunksWarning.js +40 -0
  343. package/lib/errors/TopLevelThisWarning.js +34 -0
  344. package/lib/errors/UnsplitVendorsWarning.js +42 -0
  345. package/lib/errors/UnsupportedFeatureWarning.js +1 -1
  346. package/lib/errors/UnusedAliasesWarning.js +29 -0
  347. package/lib/errors/UnusedDefinesWarning.js +29 -0
  348. package/lib/errors/UnusedExternalsWarning.js +29 -0
  349. package/lib/errors/UnusedReexportsWarning.js +42 -0
  350. package/lib/errors/UnusedRuleWarning.js +29 -0
  351. package/lib/errors/WebpackError.js +9 -5
  352. package/lib/errors/deriveStackFromNestedError.js +90 -0
  353. package/lib/esm/ExportWebpackRequireRuntimeModule.js +2 -0
  354. package/lib/esm/ModuleChunkFormatPlugin.js +37 -19
  355. package/lib/esm/ModuleChunkLoadingPlugin.js +89 -51
  356. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +155 -62
  357. package/lib/hmr/HotModuleReplacement.runtime.js +24 -5
  358. package/lib/hmr/HotModuleReplacementRuntimeModule.js +1 -1
  359. package/lib/hmr/LazyCompilationPlugin.js +45 -24
  360. package/lib/hmr/lazyCompilationBackend.js +9 -6
  361. package/lib/hmr/parserHooks.js +56 -0
  362. package/lib/html/HtmlGenerator.js +277 -77
  363. package/lib/html/HtmlModule.js +7 -3
  364. package/lib/html/HtmlModulesPlugin.js +282 -162
  365. package/lib/html/HtmlParser.js +31 -86
  366. package/lib/html/data.js +1928 -0
  367. package/lib/html/htmlMinify.js +288 -0
  368. package/lib/html/syntax.js +5557 -1155
  369. package/lib/ids/ChunkModuleIdRangePlugin.js +3 -3
  370. package/lib/ids/DeterministicChunkIdsPlugin.js +1 -1
  371. package/lib/ids/DeterministicModuleIdsPlugin.js +2 -2
  372. package/lib/ids/HashedModuleIdsPlugin.js +6 -2
  373. package/lib/ids/IdHelpers.js +7 -8
  374. package/lib/ids/NamedChunkIdsPlugin.js +1 -1
  375. package/lib/ids/NamedModuleIdsPlugin.js +1 -1
  376. package/lib/ids/NaturalChunkIdsPlugin.js +2 -2
  377. package/lib/ids/NaturalModuleIdsPlugin.js +1 -1
  378. package/lib/ids/OccurrenceChunkIdsPlugin.js +7 -3
  379. package/lib/ids/OccurrenceModuleIdsPlugin.js +7 -3
  380. package/lib/ids/SyncModuleIdsPlugin.js +4 -4
  381. package/lib/index.js +10 -0
  382. package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +3 -3
  383. package/lib/javascript/BasicEvaluatedExpression.js +18 -14
  384. package/lib/javascript/ChunkFormatHelpers.js +6 -6
  385. package/lib/javascript/ChunkHelpers.js +1 -1
  386. package/lib/javascript/CommonJsChunkFormatPlugin.js +11 -5
  387. package/lib/javascript/EnableChunkLoadingPlugin.js +2 -2
  388. package/lib/javascript/JavascriptGenerator.js +65 -165
  389. package/lib/javascript/JavascriptModule.js +9 -3
  390. package/lib/javascript/JavascriptModulesPlugin.js +98 -113
  391. package/lib/javascript/JavascriptParser.js +242 -99
  392. package/lib/javascript/JavascriptParserHelpers.js +10 -7
  393. package/lib/javascript/ScopeAnalyzer.js +1094 -0
  394. package/lib/javascript/StartupHelpers.js +55 -9
  395. package/lib/javascript/syntax.js +2678 -232
  396. package/lib/json/JsonData.js +8 -4
  397. package/lib/json/JsonGenerator.js +38 -16
  398. package/lib/json/JsonModule.js +7 -3
  399. package/lib/json/JsonModulesPlugin.js +1 -1
  400. package/lib/json/JsonParser.js +5 -6
  401. package/lib/library/AbstractLibraryPlugin.js +20 -14
  402. package/lib/library/AmdLibraryPlugin.js +11 -7
  403. package/lib/library/AssignLibraryPlugin.js +19 -13
  404. package/lib/library/EnableLibraryPlugin.js +2 -2
  405. package/lib/library/ExportPropertyLibraryPlugin.js +15 -8
  406. package/lib/library/JsonpLibraryPlugin.js +11 -7
  407. package/lib/library/ModuleLibraryPlugin.js +256 -64
  408. package/lib/library/SystemLibraryPlugin.js +12 -8
  409. package/lib/library/UmdLibraryPlugin.js +62 -25
  410. package/lib/loaders/LoaderRunner.js +14 -1
  411. package/lib/loaders/loadLoader.js +8 -4
  412. package/lib/logging/createConsoleLogger.js +7 -4
  413. package/lib/node/CommonJsChunkLoadingPlugin.js +36 -22
  414. package/lib/node/NodeEnvironmentPlugin.js +17 -3
  415. package/lib/node/NodeSourcePlugin.js +1 -1
  416. package/lib/node/NodeTargetPlugin.js +4 -3
  417. package/lib/node/NodeTemplatePlugin.js +1 -1
  418. package/lib/node/NodeWatchFileSystem.js +70 -9
  419. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +35 -38
  420. package/lib/node/ReadFileCompileAsyncWasmPlugin.js +72 -19
  421. package/lib/node/ReadFileCompileWasmPlugin.js +28 -16
  422. package/lib/node/RequireChunkLoadingRuntimeModule.js +35 -38
  423. package/lib/node/nodeConsole.js +7 -3
  424. package/lib/optimize/AggressiveMergingPlugin.js +2 -2
  425. package/lib/optimize/AggressiveSplittingPlugin.js +9 -6
  426. package/lib/optimize/ConcatenatedModule.js +985 -470
  427. package/lib/optimize/ConstExportsPlugin.js +11 -7
  428. package/lib/optimize/EnsureChunkConditionsPlugin.js +3 -3
  429. package/lib/optimize/FlagIncludedChunksPlugin.js +3 -4
  430. package/lib/optimize/InlineExports.js +9 -5
  431. package/lib/optimize/InnerGraph.js +28 -12
  432. package/lib/optimize/InnerGraphPlugin.js +23 -18
  433. package/lib/optimize/LimitChunkCountPlugin.js +7 -3
  434. package/lib/optimize/MangleExportsPlugin.js +7 -8
  435. package/lib/optimize/MergeDuplicateChunksPlugin.js +7 -3
  436. package/lib/optimize/MinChunkSizePlugin.js +7 -3
  437. package/lib/optimize/ModuleConcatenationPlugin.js +51 -35
  438. package/lib/optimize/RealContentHashPlugin.js +10 -6
  439. package/lib/optimize/RemoveEmptyChunksPlugin.js +2 -2
  440. package/lib/optimize/RemoveParentModulesPlugin.js +4 -4
  441. package/lib/optimize/RuntimeChunkPlugin.js +2 -2
  442. package/lib/optimize/SideEffectsFlagPlugin.js +262 -39
  443. package/lib/optimize/SplitChunksPlugin.js +86 -24
  444. package/lib/performance/AssetsOverSizeLimitWarning.js +10 -2
  445. package/lib/performance/AsyncChunkWaterfallsPlugin.js +136 -0
  446. package/lib/performance/BroadContextsPlugin.js +142 -0
  447. package/lib/performance/CacheEffectivenessPlugin.js +125 -0
  448. package/lib/performance/ConflictingResourceHintsPlugin.js +99 -0
  449. package/lib/performance/DuplicateModulesPlugin.js +93 -0
  450. package/lib/performance/DuplicatePackagesPlugin.js +119 -0
  451. package/lib/performance/DuplicatePackagesWarning.js +84 -0
  452. package/lib/performance/DynamicExportsPlugin.js +120 -0
  453. package/lib/performance/EmbeddedSourceMapsPlugin.js +71 -0
  454. package/lib/performance/EntrypointOverlapPlugin.js +122 -0
  455. package/lib/performance/EntrypointsOverSizeLimitWarning.js +1 -1
  456. package/lib/performance/EvalUsagePlugin.js +115 -0
  457. package/lib/performance/HotspotsPlugin.js +296 -0
  458. package/lib/performance/InlinedAssetsPlugin.js +99 -0
  459. package/lib/performance/LargeModulesPlugin.js +126 -0
  460. package/lib/performance/LegacyJavascriptPlugin.js +139 -0
  461. package/lib/performance/MissingSideEffectsPlugin.js +138 -0
  462. package/lib/performance/MixedExportsPlugin.js +136 -0
  463. package/lib/performance/OsDependentRuleWarningPlugin.js +178 -0
  464. package/lib/performance/PureAnnotationsPlugin.js +219 -0
  465. package/lib/performance/RedundantDynamicImportsPlugin.js +225 -0
  466. package/lib/performance/RuntimeInLargeChunkWarning.js +27 -0
  467. package/lib/performance/ScopeHoistingBailoutsPlugin.js +164 -0
  468. package/lib/performance/SizeLimitsPlugin.js +139 -7
  469. package/lib/performance/SplitChunksCappedPlugin.js +99 -0
  470. package/lib/performance/TinyChunksPlugin.js +128 -0
  471. package/lib/performance/TopLevelThisPlugin.js +208 -0
  472. package/lib/performance/UnsplitVendorsPlugin.js +112 -0
  473. package/lib/performance/UnusedAliasesPlugin.js +253 -0
  474. package/lib/performance/UnusedDefinesPlugin.js +87 -0
  475. package/lib/performance/UnusedExternalsPlugin.js +110 -0
  476. package/lib/performance/UnusedReexportsPlugin.js +159 -0
  477. package/lib/performance/UnusedRuleWarningPlugin.js +105 -0
  478. package/lib/performance/getModuleSize.js +22 -0
  479. package/lib/performance/getSourceModules.js +22 -0
  480. package/lib/performance/hasOnlyUnusedExports.js +40 -0
  481. package/lib/prefetch/ChunkPrefetchFunctionRuntimeModule.js +24 -10
  482. package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +63 -46
  483. package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +2 -3
  484. package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +2 -2
  485. package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +2 -2
  486. package/lib/prefetch/ResourceHintPlugin.js +295 -78
  487. package/lib/prefetch/ResourceHintRuntimeModule.js +1 -21
  488. package/lib/prefetch/StartupAssetHintRuntimeModule.js +10 -133
  489. package/lib/prefetch/parseResourceHintOptions.js +31 -4
  490. package/lib/rules/BasicEffectRulePlugin.js +2 -2
  491. package/lib/rules/BasicMatcherRulePlugin.js +8 -4
  492. package/lib/rules/GlobMatcherRulePlugin.js +68 -0
  493. package/lib/rules/ObjectMatcherRulePlugin.js +12 -5
  494. package/lib/rules/RuleSetCompiler.js +146 -12
  495. package/lib/rules/UseEffectRulePlugin.js +18 -11
  496. package/lib/runtime/AsyncModuleGeneratorRuntimeModule.js +11 -1
  497. package/lib/runtime/AsyncModuleRuntimeModule.js +1 -1
  498. package/lib/runtime/AutoPublicPathRuntimeModule.js +15 -20
  499. package/lib/runtime/BaseUriRuntimeModule.js +33 -7
  500. package/lib/runtime/ChunkNameRuntimeModule.js +10 -0
  501. package/lib/runtime/CompatGetDefaultExportRuntimeModule.js +11 -1
  502. package/lib/runtime/CompatRuntimeModule.js +5 -3
  503. package/lib/runtime/ConcatenationWrapRuntimeModule.js +90 -0
  504. package/lib/runtime/ConstructRequireRuntimeModule.js +52 -0
  505. package/lib/runtime/CreateFakeNamespaceObjectRuntimeModule.js +8 -6
  506. package/lib/runtime/CreateScriptRuntimeModule.js +11 -1
  507. package/lib/runtime/CreateScriptUrlRuntimeModule.js +11 -1
  508. package/lib/runtime/DefinePropertyGettersRuntimeModule.js +56 -38
  509. package/lib/runtime/EnsureChunkRuntimeModule.js +18 -2
  510. package/lib/runtime/GetChunkFilenameRuntimeModule.js +62 -37
  511. package/lib/runtime/GetFullHashRuntimeModule.js +12 -2
  512. package/lib/runtime/GetMainFilenameRuntimeModule.js +12 -2
  513. package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +2 -2
  514. package/lib/runtime/GetWorkletBootstrapRuntimeModule.js +16 -3
  515. package/lib/runtime/GlobalRuntimeModule.js +18 -0
  516. package/lib/runtime/HasOwnPropertyRuntimeModule.js +12 -2
  517. package/lib/runtime/LoadScriptRuntimeModule.js +2 -2
  518. package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +23 -6
  519. package/lib/runtime/MakeNamespaceObjectRuntimeModule.js +22 -6
  520. package/lib/runtime/NonceRuntimeModule.js +10 -0
  521. package/lib/runtime/OnChunksLoadedRuntimeModule.js +5 -3
  522. package/lib/runtime/PublicPathRuntimeModule.js +12 -2
  523. package/lib/runtime/RelativeUrlRuntimeModule.js +11 -1
  524. package/lib/runtime/RuntimeIdRuntimeModule.js +12 -2
  525. package/lib/runtime/SetAnonymousDefaultNameRuntimeModule.js +11 -1
  526. package/lib/runtime/StartupChunkDependenciesPlugin.js +18 -9
  527. package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +3 -3
  528. package/lib/runtime/StartupEntrypointRuntimeModule.js +21 -4
  529. package/lib/runtime/SystemContextRuntimeModule.js +10 -0
  530. package/lib/runtime/ToBinaryRuntimeModule.js +1 -1
  531. package/lib/runtime/WorkerRuntimeModule.js +11 -1
  532. package/lib/runtime/baseUri.js +63 -0
  533. package/lib/schemes/DataUriPlugin.js +1 -1
  534. package/lib/schemes/FileUriPlugin.js +1 -1
  535. package/lib/schemes/HttpUriPlugin.js +24 -15
  536. package/lib/schemes/VirtualUrlPlugin.js +13 -7
  537. package/lib/serialization/AggregateErrorSerializer.js +1 -1
  538. package/lib/serialization/BinaryMiddleware.js +4 -4
  539. package/lib/serialization/ErrorObjectSerializer.js +1 -1
  540. package/lib/serialization/FileMiddleware.js +7 -7
  541. package/lib/serialization/ObjectMiddleware.js +139 -114
  542. package/lib/serialization/PlainObjectSerializer.js +19 -16
  543. package/lib/sharing/ConsumeSharedModule.js +30 -21
  544. package/lib/sharing/ConsumeSharedPlugin.js +18 -10
  545. package/lib/sharing/ConsumeSharedRuntimeModule.js +6 -9
  546. package/lib/sharing/ProvideSharedModule.js +25 -16
  547. package/lib/sharing/ProvideSharedModuleFactory.js +7 -3
  548. package/lib/sharing/ProvideSharedPlugin.js +8 -4
  549. package/lib/sharing/SharePlugin.js +17 -5
  550. package/lib/sharing/ShareRuntimeModule.js +4 -4
  551. package/lib/sharing/resolveMatchedConfigs.js +9 -6
  552. package/lib/sharing/utils.js +1 -3
  553. package/lib/stats/DefaultStatsFactoryPlugin.js +50 -29
  554. package/lib/stats/DefaultStatsPresetPlugin.js +17 -8
  555. package/lib/stats/DefaultStatsPrinterPlugin.js +36 -26
  556. package/lib/stats/StatsFactory.js +25 -26
  557. package/lib/stats/StatsPrinter.js +16 -12
  558. package/lib/typescript/TypeScriptPlugin.js +12 -14
  559. package/lib/url/URLParserPlugin.js +26 -13
  560. package/lib/util/AsyncQueue.js +4 -3
  561. package/lib/util/Hash.js +5 -1
  562. package/lib/util/LazySet.js +35 -22
  563. package/lib/util/LocConverter.js +36 -13
  564. package/lib/util/SourceProcessor.js +1050 -24
  565. package/lib/util/StringXor.js +1 -1
  566. package/lib/util/chainedImports.js +9 -5
  567. package/lib/util/cleverMerge.js +1 -1
  568. package/lib/util/comparators.js +45 -14
  569. package/lib/util/concatenate.js +203 -77
  570. package/lib/util/conventions.js +5 -1
  571. package/lib/util/createHash.js +2 -2
  572. package/lib/util/createHooksRegistry.js +8 -10
  573. package/lib/util/dataURL.js +225 -1
  574. package/lib/util/extractSourceMap.js +4 -3
  575. package/lib/util/findCaseMismatch.js +139 -0
  576. package/lib/util/formatLocation.js +1 -2
  577. package/lib/util/fs.js +22 -5
  578. package/lib/util/globUtils.js +298 -24
  579. package/lib/util/hash/BatchedHash.js +5 -1
  580. package/lib/util/hash/BulkUpdateHash.js +5 -1
  581. package/lib/util/hash/DebugHash.js +5 -1
  582. package/lib/util/hash/hash-digest.js +6 -2
  583. package/lib/util/identifier.js +4 -0
  584. package/lib/util/implicitTypeLoaderFallback.js +1 -1
  585. package/lib/util/internalSerializables.js +6 -0
  586. package/lib/util/lazyModule.js +56 -0
  587. package/lib/util/makeSerializable.js +7 -3
  588. package/lib/util/matchAlias.js +25 -0
  589. package/lib/util/mimeTypes.js +11 -5
  590. package/lib/util/nonNumericOnlyHash.js +4 -3
  591. package/lib/util/parseJson.js +5 -3
  592. package/lib/util/preloadModuleType.js +32 -0
  593. package/lib/util/registerExternalSerializer.js +7 -5
  594. package/lib/util/runtime.js +2 -2
  595. package/lib/util/semver.js +1 -1
  596. package/lib/util/serialization.js +28 -28
  597. package/lib/util/source.js +2 -2
  598. package/lib/util/traverseDestructuringAssignmentProperties.js +6 -2
  599. package/lib/wasm/EnableWasmLoadingPlugin.js +10 -8
  600. package/lib/wasm/wasmModuleFilename.js +54 -0
  601. package/lib/wasm-async/AsyncWasmCompileRuntimeModule.js +41 -21
  602. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +43 -21
  603. package/lib/wasm-async/AsyncWasmModule.js +3 -3
  604. package/lib/wasm-async/AsyncWebAssemblyGenerator.js +4 -5
  605. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +57 -17
  606. package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +34 -18
  607. package/lib/wasm-async/AsyncWebAssemblyParser.js +9 -8
  608. package/lib/wasm-async/UniversalCompileAsyncWasmPlugin.js +34 -8
  609. package/lib/wasm-sync/SyncWasmModule.js +2 -2
  610. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +18 -13
  611. package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +4 -5
  612. package/lib/wasm-sync/WebAssemblyGenerator.js +18 -17
  613. package/lib/wasm-sync/WebAssemblyInInitialChunkError.js +4 -4
  614. package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +7 -7
  615. package/lib/wasm-sync/WebAssemblyModulesPlugin.js +24 -11
  616. package/lib/wasm-sync/WebAssemblyParser.js +4 -6
  617. package/lib/wasm-sync/WebAssemblyUtils.js +2 -2
  618. package/lib/web/FetchCompileAsyncWasmPlugin.js +101 -19
  619. package/lib/web/FetchCompileWasmPlugin.js +46 -16
  620. package/lib/web/JsonpChunkLoadingPlugin.js +47 -23
  621. package/lib/web/JsonpChunkLoadingRuntimeModule.js +50 -20
  622. package/lib/web/JsonpTemplatePlugin.js +2 -2
  623. package/lib/webpack.js +22 -11
  624. package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +60 -26
  625. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +30 -32
  626. package/lib/webworker/WebWorkerTemplatePlugin.js +1 -1
  627. package/module.d.ts +1 -0
  628. package/package.json +32 -25
  629. package/schemas/WebpackOptions.check.js +1 -1
  630. package/schemas/WebpackOptions.json +670 -36
  631. package/schemas/plugins/HtmlParserOptions.check.js +1 -1
  632. package/schemas/plugins/container/ContainerPlugin.check.js +1 -1
  633. package/schemas/plugins/container/ContainerPlugin.json +10 -0
  634. package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
  635. package/schemas/plugins/container/ModuleFederationPlugin.json +10 -0
  636. package/schemas/plugins/css/CssAutoOrModuleParserOptions.check.js +1 -1
  637. package/schemas/plugins/css/CssModuleParserOptions.check.js +1 -1
  638. package/schemas/plugins/css/CssParserOptions.check.js +1 -1
  639. package/types.d.ts +3144 -454
  640. package/lib/runtime/CommonJsWrapRuntimeModule.js +0 -37
@@ -5,14 +5,17 @@
5
5
 
6
6
  "use strict";
7
7
 
8
- /** @typedef {import("http").RequestListener} RequestListener */
9
8
  /** @typedef {import("http").ServerOptions} HttpServerOptions */
10
- /** @typedef {import("http").Server} HttpServer */
11
9
  /** @typedef {import("https").ServerOptions} HttpsServerOptions */
12
- /** @typedef {import("https").Server} HttpsServer */
13
- /** @typedef {import("net").AddressInfo} AddressInfo */
14
- /** @typedef {import("./LazyCompilationPlugin").BackendHandler} BackendHandler */
15
- /** @typedef {import("../../declarations/WebpackOptions").LazyCompilationDefaultBackendOptions} LazyCompilationDefaultBackendOptions */
10
+ /** @import { RequestListener, Server as HttpServer } from "http" */
11
+ /** @import { Server as HttpsServer } from "https" */
12
+ /** @import { AddressInfo } from "net" */
13
+ /** @import { BackendHandler } from "./LazyCompilationPlugin" */
14
+ /**
15
+ * @import {
16
+ * LazyCompilationDefaultBackendOptions
17
+ * } from "../../declarations/WebpackOptions"
18
+ */
16
19
 
17
20
  /** @typedef {HttpServer | HttpsServer} Server */
18
21
  /** @typedef {(server: Server) => void} Listen */
@@ -0,0 +1,56 @@
1
+ /*
2
+ MIT License http://www.opensource.org/licenses/mit-license.php
3
+ Author Alexander Akait @alexander-akait
4
+ */
5
+
6
+ "use strict";
7
+
8
+ const { SyncBailHook } = require("tapable");
9
+
10
+ /** @import JavascriptParser from "../javascript/JavascriptParser" */
11
+ /** @import { CallExpression, Expression, SpreadElement } from "estree" */
12
+
13
+ /** @typedef {string[]} Requests */
14
+
15
+ /**
16
+ * Defines the hmr javascript parser hooks type used by this module.
17
+ * @typedef {object} HMRJavascriptParserHooks
18
+ * @property {SyncBailHook<[Expression | SpreadElement, Requests], void>} hotAcceptCallback
19
+ * @property {SyncBailHook<[CallExpression, Requests], void>} hotAcceptWithoutCallback
20
+ */
21
+
22
+ /** @type {WeakMap<JavascriptParser, HMRJavascriptParserHooks>} */
23
+ const parserHooksMap = new WeakMap();
24
+
25
+ /**
26
+ * Returns the attached hooks.
27
+ * @param {JavascriptParser} parser the parser
28
+ * @returns {HMRJavascriptParserHooks} the attached hooks
29
+ */
30
+ const getParserHooks = (parser) => {
31
+ // matched by class name, as `createHooksRegistry` does: a parser from another
32
+ // webpack copy has to pass, and requiring the parser here loads it eagerly
33
+ const candidate = /** @type {{ constructor?: { name: string } } | null} */ (
34
+ parser
35
+ );
36
+ if (
37
+ !candidate ||
38
+ !candidate.constructor ||
39
+ candidate.constructor.name !== "JavascriptParser"
40
+ ) {
41
+ throw new TypeError(
42
+ "The 'parser' argument must be an instance of JavascriptParser"
43
+ );
44
+ }
45
+ let hooks = parserHooksMap.get(parser);
46
+ if (hooks === undefined) {
47
+ hooks = {
48
+ hotAcceptCallback: new SyncBailHook(["expression", "requests"]),
49
+ hotAcceptWithoutCallback: new SyncBailHook(["expression", "requests"])
50
+ };
51
+ parserHooksMap.set(parser, hooks);
52
+ }
53
+ return hooks;
54
+ };
55
+
56
+ module.exports = getParserHooks;
@@ -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,25 +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")} Module */
165
- /** @typedef {import("../Module").SourceType} SourceType */
166
- /** @typedef {import("../Module").SourceTypes} SourceTypes */
167
- /** @typedef {import("../Module").ConcatenationBailoutReasonContext} ConcatenationBailoutReasonContext */
168
- /** @typedef {import("../ModuleGraph")} ModuleGraph */
169
- /** @typedef {import("../NormalModule")} NormalModule */
170
- /** @typedef {import("./HtmlModule").HtmlModuleBuildInfo} HtmlModuleBuildInfo */
171
- /** @typedef {import("../Module").RuntimeRequirements} RuntimeRequirements */
172
- /** @typedef {import("../RuntimeTemplate")} RuntimeTemplate */
173
- /** @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" */
174
164
  /**
175
165
  * @template T
176
166
  * @typedef {import("../InitFragment")<T>} InitFragment
@@ -244,15 +234,23 @@ const HTML_PAGE_URL_SENTINEL_REGEXP =
244
234
  const ASSET_URL_SENTINEL_REGEXP =
245
235
  /__WEBPACK_HTML_ASSET_URL__([0-9a-f]+)__END__/g;
246
236
 
237
+ // Compilations whose HTML modules must emit SRI sentinels (see
238
+ // `enableIntegritySentinels`).
239
+ /** @type {WeakSet<Compilation>} */
240
+ const integritySentinelCompilations = new WeakSet();
241
+
247
242
  // Matches the whole ` integrity="<sentinel>"` so the attribute can be dropped
248
- // 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.
249
247
  const INTEGRITY_SENTINEL_REGEXP =
250
- / integrity="__WEBPACK_HTML_INTEGRITY__([0-9a-f]+)__([a-z]+)__END__"/g;
248
+ / integrity=(["']?)__WEBPACK_HTML_INTEGRITY__([0-9a-f]+)__([a-z]+)__END__\1/g;
251
249
 
252
250
  // Same attribute, but tolerant of the `\"` escaping the surrounding quotes get
253
251
  // when the HTML lives inside a JS string literal — used only to strip it there.
254
252
  const INTEGRITY_SENTINEL_STRIP_REGEXP =
255
- / integrity=\\?"__WEBPACK_HTML_INTEGRITY__[0-9a-f]+__[a-z]+__END__\\?"/g;
253
+ / integrity=(\\?["']|)__WEBPACK_HTML_INTEGRITY__[0-9a-f]+__[a-z]+__END__\1/g;
256
254
 
257
255
  // The trailing `(?:__<hash>)?` is the inlined chunk's content hash, embedded by
258
256
  // `embedInlineChunkHashes` so the host HTML's bytes (and its `[contenthash]`,
@@ -353,7 +351,7 @@ class HtmlGenerator extends Generator {
353
351
  // handling included), mirroring the CSS branch.
354
352
  let filenameTemplate;
355
353
  if (contentHashType === "css") {
356
- filenameTemplate = getCssModulesPlugin().getChunkFilenameTemplate(
354
+ filenameTemplate = CssModulesPlugin.getChunkFilenameTemplate(
357
355
  chunk,
358
356
  outputOptions
359
357
  );
@@ -463,6 +461,26 @@ class HtmlGenerator extends Generator {
463
461
  });
464
462
  }
465
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
+
466
484
  /**
467
485
  * Emit a sentinel for a chunk's SRI hash. Resolved late (after
468
486
  * `RealContentHashPlugin`) by `resolveChunkIntegritySentinels`, since the
@@ -509,7 +527,7 @@ class HtmlGenerator extends Generator {
509
527
  const chunksById = getChunksById(compilation);
510
528
  return content.replace(
511
529
  INTEGRITY_SENTINEL_REGEXP,
512
- (_, hexId, contentHashType) => {
530
+ (_, _quote, hexId, contentHashType) => {
513
531
  const chunkId = Buffer.from(hexId, "hex").toString("utf8");
514
532
  const chunk = chunksById.get(chunkId);
515
533
  if (!chunk) return "";
@@ -660,6 +678,7 @@ class HtmlGenerator extends Generator {
660
678
  // `skip.text` populates `contentEnd` (raw-text body end) without
661
679
  // materializing text nodes; `</script` stays escaped, so CSP hashes match
662
680
  // the exact bytes the browser sees.
681
+ const { NodeType, SourceProcessor } = getHtmlSyntax();
663
682
  new SourceProcessor()
664
683
  .use({
665
684
  [NodeType.Element]: {
@@ -668,11 +687,23 @@ class HtmlGenerator extends Generator {
668
687
  if (name === "head") {
669
688
  if (headOpen < 0) headOpen = headEnd = path.tagEnd();
670
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--;
671
703
  return;
672
704
  }
673
705
  if (name === "body") {
674
- if (bodyOpen < 0) bodyOpen = bodyEnd = path.tagEnd();
675
- bodyDepth++;
706
+ if (bodyDepth > 0) bodyDepth--;
676
707
  return;
677
708
  }
678
709
  const end = path.end();
@@ -713,14 +744,6 @@ class HtmlGenerator extends Generator {
713
744
  });
714
745
  originals.push(snapshotAttrs(attrs));
715
746
  descriptors.push(null);
716
- },
717
- exit: (path) => {
718
- const name = path.tagName();
719
- if (name === "head") {
720
- if (headDepth > 0) headDepth--;
721
- } else if (name === "body" && bodyDepth > 0) {
722
- bodyDepth--;
723
- }
724
747
  }
725
748
  }
726
749
  })
@@ -763,14 +786,16 @@ class HtmlGenerator extends Generator {
763
786
  * `*-prepend`), or had its `attrs` changed; and — when `csp` is set and the
764
787
  * page declares no CSP — a strict `<meta http-equiv="Content-Security-Policy">`
765
788
  * is injected with a hash of every inline `<script>`/`<style>` (page's own and
766
- * injected) plus an optional placeholder `nonce` on each. Edits run
767
- * 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.
768
792
  * @param {string} content the collected HTML (inline content already resolved)
769
793
  * @param {HtmlModel} model the value from `collectHtml` after the hooks
770
794
  * @param {CspOption} csp the `output.html.csp` option
771
795
  * @returns {string} the rendered HTML
772
796
  */
773
797
  static renderHtml(content, model, csp) {
798
+ const { escapeAttribute } = getHtmlSyntax();
774
799
  const { tags, spans, originals, descriptors, anchors } = model;
775
800
  // CSP setup: an author-declared policy (page's own or injected) wins.
776
801
  const options = csp ? (csp === true ? {} : csp) : undefined;
@@ -970,14 +995,20 @@ class HtmlGenerator extends Generator {
970
995
  edits.push({ start: pos, end: pos, text, insert: true });
971
996
  }
972
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).
973
1001
  edits.sort(
974
- (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)
975
1003
  );
976
- let result = content;
1004
+ let result = "";
1005
+ let cursor = 0;
977
1006
  for (const edit of edits) {
978
- 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;
979
1010
  }
980
- return result;
1011
+ return result + content.slice(cursor);
981
1012
  }
982
1013
 
983
1014
  /**
@@ -1293,8 +1324,18 @@ class HtmlGenerator extends Generator {
1293
1324
  );
1294
1325
  }
1295
1326
 
1296
- // JS export: resolve `[webpack/auto]` to root-relative URLs.
1297
- 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");
1298
1339
 
1299
1340
  /** @type {string} */
1300
1341
  let sourceContent;
@@ -1349,13 +1390,21 @@ class HtmlGenerator extends Generator {
1349
1390
  * exactly as a full page reload would render them.
1350
1391
  *
1351
1392
  * `<head>` changes beyond `<title>` (a new `<meta>`, a swapped
1352
- * `<link rel=icon>`, an inline `<style>` block, …) can't be safely
1353
- * DOM-patched: webpack injects its own runtime scripts and stylesheet
1354
- * links into the head on initial load, and blindly replacing
1355
- * `document.head.innerHTML` would tear them down. So the shim falls
1356
- * back to a full reload — fine in a dev-server context because the
1357
- * regular (non-hot-update) `page.html` chunk is re-emitted on every
1358
- * 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.
1359
1408
  * @param {NormalModule} module module
1360
1409
  * @param {string} html the rewritten HTML content (with placeholders resolved)
1361
1410
  * @param {boolean} extracting whether the HTML module is being extracted as a real `.html` file
@@ -1364,6 +1413,7 @@ class HtmlGenerator extends Generator {
1364
1413
  */
1365
1414
  _renderHmrShim(module, html, extracting, runtimeTemplate) {
1366
1415
  const declare = runtimeTemplate.renderConst();
1416
+ const mutable = runtimeTemplate.renderLet();
1367
1417
  const acceptBlock = extracting
1368
1418
  ? [
1369
1419
  "module.hot.accept();",
@@ -1409,10 +1459,151 @@ class HtmlGenerator extends Generator {
1409
1459
  'return head === null ? "" : __webpack_mask_comments__(head).replace(/<title[^>]*>[\\s\\S]*?<\\/title>/i, "").trim();'
1410
1460
  ]
1411
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
+ )};`,
1412
1603
  "if (module.hot.data && typeof document !== 'undefined') {",
1413
1604
  Template.indent([
1414
1605
  `${declare} __webpack_new_head__ = __webpack_extract_head__();`,
1415
- "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') {",
1416
1607
  Template.indent("window.location.reload();"),
1417
1608
  "} else {",
1418
1609
  Template.indent([
@@ -1457,7 +1648,7 @@ class HtmlGenerator extends Generator {
1457
1648
  .replace(/-{2,}/g, (m) => `${"-".repeat(m.length - 1)} `);
1458
1649
  return new RawSource(`<!-- webpack error: ${safe} -->`);
1459
1650
  }
1460
- return new RawSource(`throw new Error(${JSON.stringify(error.message)});`);
1651
+ return new RawSource(Generator.throwBuildErrorCode(error));
1461
1652
  }
1462
1653
 
1463
1654
  /**
@@ -1484,6 +1675,15 @@ class HtmlGenerator extends Generator {
1484
1675
  if (updateHashContext.module.hot) {
1485
1676
  hash.update("hot");
1486
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
+ }
1487
1687
  }
1488
1688
  }
1489
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.