@depup/webpack 5.110.3-depup.0 → 5.111.1-depup.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (283) hide show
  1. package/README.md +7 -8
  2. package/changes.json +7 -11
  3. package/lib/APIPlugin.js +26 -11
  4. package/lib/AutomaticPrefetchPlugin.js +1 -1
  5. package/lib/Cache.js +8 -3
  6. package/lib/CacheFacade.js +1 -1
  7. package/lib/CircularModulesPlugin.js +157 -55
  8. package/lib/CleanPlugin.js +2 -2
  9. package/lib/CompatibilityPlugin.js +3 -4
  10. package/lib/Compilation.js +336 -337
  11. package/lib/Compiler.js +213 -51
  12. package/lib/ConstPlugin.js +16 -132
  13. package/lib/CopyPlugin.js +1054 -0
  14. package/lib/DefinePlugin.js +24 -8
  15. package/lib/DependencyTemplate.js +2 -1
  16. package/lib/DotenvPlugin.js +24 -28
  17. package/lib/ErrorHelpers.js +113 -0
  18. package/lib/ExportsInfo.js +20 -16
  19. package/lib/ExternalModule.js +47 -22
  20. package/lib/FileSystemInfo.js +17 -14
  21. package/lib/FlagDependencyExportsPlugin.js +53 -34
  22. package/lib/FlagDependencyUsagePlugin.js +9 -13
  23. package/lib/Generator.js +24 -2
  24. package/lib/HotModuleReplacementPlugin.js +55 -7
  25. package/lib/IgnorePlugin.js +1 -1
  26. package/lib/JavascriptMetaInfoPlugin.js +5 -3
  27. package/lib/LoaderOptionsPlugin.js +1 -1
  28. package/lib/MainTemplate.js +5 -1
  29. package/lib/Module.js +19 -10
  30. package/lib/ModuleGraph.js +6 -9
  31. package/lib/MultiCompiler.js +7 -17
  32. package/lib/MultiWatching.js +1 -1
  33. package/lib/NormalModule.js +135 -50
  34. package/lib/NormalModuleFactory.js +1 -1
  35. package/lib/RuntimeGlobals.js +21 -7
  36. package/lib/RuntimeModule.js +28 -12
  37. package/lib/RuntimePlugin.js +30 -3
  38. package/lib/RuntimeTemplate.js +813 -518
  39. package/lib/SourceMapDevToolPlugin.js +54 -104
  40. package/lib/TemplatedPathPlugin.js +16 -59
  41. package/lib/Watching.js +9 -0
  42. package/lib/WebpackOptionsApply.js +84 -91
  43. package/lib/asset/AssetBytesGenerator.js +7 -1
  44. package/lib/asset/AssetGenerator.js +50 -24
  45. package/lib/asset/AssetModule.js +3 -0
  46. package/lib/asset/AssetSourceGenerator.js +7 -1
  47. package/lib/asset/WebManifestParser.js +7 -5
  48. package/lib/buildChunkGraph.js +11 -15
  49. package/lib/cache/AddBuildDependenciesPlugin.js +33 -4
  50. package/lib/cache/IdleFileCachePlugin.js +2 -2
  51. package/lib/cache/MemoryCachePlugin.js +4 -4
  52. package/lib/cache/MemoryWithGcCachePlugin.js +7 -8
  53. package/lib/cache/PackFileCacheStrategy.js +17 -19
  54. package/lib/cache/getLazyHashedEtag.js +3 -5
  55. package/lib/config/browserslistTargetHandler.js +17 -4
  56. package/lib/config/defaults.js +138 -128
  57. package/lib/config/getClaimedAssetTypes.js +10 -11
  58. package/lib/config/normalization.js +82 -12
  59. package/lib/config/target.js +13 -4
  60. package/lib/container/ContainerReferencePlugin.js +6 -0
  61. package/lib/container/RemoteRuntimeModule.js +9 -0
  62. package/lib/container/declaredRemotes.js +39 -0
  63. package/lib/{ContextExclusionPlugin.js → context/ContextExclusionPlugin.js} +1 -1
  64. package/lib/{ContextModule.js → context/ContextModule.js} +54 -115
  65. package/lib/{ContextModuleFactory.js → context/ContextModuleFactory.js} +19 -21
  66. package/lib/{ContextReplacementPlugin.js → context/ContextReplacementPlugin.js} +4 -4
  67. package/lib/css/CssGenerator.js +27 -11
  68. package/lib/css/CssInjectStyleRuntimeModule.js +9 -0
  69. package/lib/css/CssLoadingRuntimeModule.js +94 -36
  70. package/lib/css/CssModule.js +1 -1
  71. package/lib/css/CssModulesPlugin.js +7 -6
  72. package/lib/css/CssParser.js +162 -31
  73. package/lib/css/CssServerStylesRuntimeModule.js +9 -0
  74. package/lib/css/cssMinify.js +43 -32
  75. package/lib/css/data.js +3514 -869
  76. package/lib/css/syntax.js +6370 -1220
  77. package/lib/debug/ProfilingPlugin.js +7 -4
  78. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +6 -3
  79. package/lib/dependencies/AMDRuntimeModules.js +18 -0
  80. package/lib/dependencies/CommonJsExportRequireDependency.js +13 -12
  81. package/lib/dependencies/CommonJsExportsParserPlugin.js +12 -13
  82. package/lib/dependencies/CommonJsImportsParserPlugin.js +5 -5
  83. package/lib/dependencies/CommonJsPlugin.js +19 -3
  84. package/lib/dependencies/CommonJsRequireDependency.js +14 -5
  85. package/lib/dependencies/CommonJsSelfReferenceDependency.js +2 -4
  86. package/lib/dependencies/ContextDependency.js +1 -1
  87. package/lib/dependencies/ContextDependencyHelpers.js +3 -9
  88. package/lib/dependencies/ContextElementDependency.js +1 -1
  89. package/lib/dependencies/CssIcssExportDependency.js +13 -9
  90. package/lib/dependencies/CssIcssImportDependency.js +3 -6
  91. package/lib/dependencies/CssUrlDependency.js +3 -5
  92. package/lib/dependencies/HarmonyCompatibilityDependency.js +67 -22
  93. package/lib/dependencies/HarmonyDetectionParserPlugin.js +3 -4
  94. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +10 -7
  95. package/lib/dependencies/HarmonyExportExpressionDependency.js +47 -33
  96. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +74 -17
  97. package/lib/dependencies/HarmonyExportInitFragment.js +110 -23
  98. package/lib/dependencies/HarmonyExportSpecifierDependency.js +25 -58
  99. package/lib/dependencies/HarmonyImportBareSideEffectDependency.js +59 -0
  100. package/lib/dependencies/HarmonyImportDependency.js +6 -1
  101. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +111 -17
  102. package/lib/dependencies/HarmonyImportSideEffectDependency.js +3 -4
  103. package/lib/dependencies/HarmonyImportSpecifierDependency.js +40 -3
  104. package/lib/dependencies/HarmonyModulesPlugin.js +20 -0
  105. package/lib/dependencies/HtmlEntryDependency.js +124 -102
  106. package/lib/dependencies/HtmlInlineScriptDependency.js +3 -4
  107. package/lib/dependencies/HtmlInlineStyleDependency.js +3 -4
  108. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +1 -1
  109. package/lib/dependencies/ImportMetaGlobHelpers.js +1 -1
  110. package/lib/dependencies/ImportMetaMainDependency.js +104 -0
  111. package/lib/dependencies/ImportMetaPlugin.js +67 -25
  112. package/lib/dependencies/ImportParserPlugin.js +1 -1
  113. package/lib/dependencies/LoaderPlugin.js +26 -1
  114. package/lib/dependencies/RequireContextDependencyParserPlugin.js +1 -1
  115. package/lib/dependencies/SystemRuntimeModule.js +9 -0
  116. package/lib/dependencies/URLContextDependency.js +1 -1
  117. package/lib/dependencies/URLDependency.js +6 -5
  118. package/lib/dependencies/WorkerAndWorkletPlugin.js +15 -21
  119. package/lib/dependencies/WorkerDependency.js +7 -7
  120. package/lib/dependencies/WorkletDependency.js +7 -11
  121. package/lib/dll/DelegatedModule.js +18 -1
  122. package/lib/dll/DllReferencePlugin.js +11 -8
  123. package/lib/dll/LibManifestPlugin.js +1 -1
  124. package/lib/errors/AnalyzableBailoutsWarning.js +41 -0
  125. package/lib/errors/DuplicateModulesWarning.js +12 -7
  126. package/lib/errors/EmptyCopyPatternWarning.js +26 -0
  127. package/lib/errors/ExternalStarReexportError.js +44 -0
  128. package/lib/errors/HookWebpackError.js +3 -2
  129. package/lib/errors/MissingSourceMapsWarning.js +36 -0
  130. package/lib/errors/ModuleParseError.js +2 -1
  131. package/lib/errors/UnusedAssetsWarning.js +36 -0
  132. package/lib/errors/UnusedFederationWarning.js +35 -0
  133. package/lib/errors/UnusedModulesWarning.js +38 -0
  134. package/lib/esm/ExportWebpackRequireRuntimeModule.js +9 -0
  135. package/lib/esm/ModuleChunkFormatPlugin.js +28 -3
  136. package/lib/esm/ModuleChunkLoadingPlugin.js +30 -11
  137. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +92 -60
  138. package/lib/hmr/HotModuleReplacement.runtime.js +8 -2
  139. package/lib/hmr/HotModuleReplacementRuntimeModule.js +9 -0
  140. package/lib/hmr/LazyCompilationPlugin.js +3 -5
  141. package/lib/html/HtmlGenerator.js +72 -87
  142. package/lib/html/HtmlModulesPlugin.js +418 -200
  143. package/lib/html/HtmlParser.js +110 -147
  144. package/lib/html/builtinEmbeddedRenderer.js +107 -0
  145. package/lib/html/data.js +142 -7
  146. package/lib/html/htmlMinify.js +92 -122
  147. package/lib/html/syntax.js +1618 -1391
  148. package/lib/ids/HashedModuleIdsPlugin.js +2 -1
  149. package/lib/index.js +49 -3
  150. package/lib/javascript/ChunkFormatHelpers.js +4 -3
  151. package/lib/javascript/JavascriptGenerator.js +8 -1
  152. package/lib/javascript/JavascriptModule.js +1 -0
  153. package/lib/javascript/JavascriptModulesPlugin.js +73 -72
  154. package/lib/javascript/JavascriptParser.js +1970 -900
  155. package/lib/javascript/StartupHelpers.js +27 -3
  156. package/lib/javascript/data.js +172 -0
  157. package/lib/javascript/grammar.js +5546 -0
  158. package/lib/javascript/parser.js +1500 -0
  159. package/lib/javascript/regexp.js +1762 -0
  160. package/lib/javascript/regexpData.js +51 -0
  161. package/lib/javascript/syntax.js +9061 -5262
  162. package/lib/json/JsonGenerator.js +7 -1
  163. package/lib/library/ModuleLibraryPlugin.js +171 -132
  164. package/lib/loaders/LoaderRunner.js +137 -9
  165. package/lib/node/NodeWatchFileSystem.js +3 -9
  166. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +22 -0
  167. package/lib/node/RequireChunkLoadingRuntimeModule.js +22 -0
  168. package/lib/optimize/AggressiveMergingPlugin.js +3 -5
  169. package/lib/optimize/ConcatenatedModule.js +178 -120
  170. package/lib/optimize/ConstExportsPlugin.js +50 -39
  171. package/lib/optimize/FlagIncludedChunksPlugin.js +3 -11
  172. package/lib/optimize/InlineExports.js +20 -123
  173. package/lib/optimize/InnerGraphPlugin.js +7 -13
  174. package/lib/optimize/LimitChunkCountPlugin.js +5 -8
  175. package/lib/optimize/MangleExportsPlugin.js +13 -4
  176. package/lib/optimize/ModuleConcatenationPlugin.js +27 -5
  177. package/lib/optimize/RealContentHashPlugin.js +68 -9
  178. package/lib/optimize/SideEffectsFlagPlugin.js +24 -28
  179. package/lib/optimize/SplitChunksPlugin.js +2 -4
  180. package/lib/performance/AnalyzableBailoutsPlugin.js +115 -0
  181. package/lib/performance/BroadContextsPlugin.js +1 -1
  182. package/lib/performance/CacheEffectivenessPlugin.js +7 -7
  183. package/lib/performance/DuplicateModulesPlugin.js +57 -13
  184. package/lib/performance/EvalUsagePlugin.js +5 -2
  185. package/lib/performance/MissingSourceMapsPlugin.js +115 -0
  186. package/lib/performance/PureAnnotationsPlugin.js +6 -3
  187. package/lib/performance/SizeLimitsPlugin.js +2 -4
  188. package/lib/performance/TopLevelThisPlugin.js +5 -4
  189. package/lib/performance/UnusedAssetsPlugin.js +109 -0
  190. package/lib/performance/UnusedFederationPlugin.js +147 -0
  191. package/lib/performance/UnusedModulesPlugin.js +141 -0
  192. package/lib/performance/UnusedReexportsPlugin.js +1 -55
  193. package/lib/performance/isOnlyReexported.js +65 -0
  194. package/lib/prefetch/ChunkPrefetchFunctionRuntimeModule.js +25 -5
  195. package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +8 -8
  196. package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +9 -0
  197. package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +9 -0
  198. package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +9 -0
  199. package/lib/prefetch/ResourceHintPlugin.js +18 -23
  200. package/lib/prefetch/ResourceHintRuntimeModule.js +9 -0
  201. package/lib/prefetch/StartupAssetHintRuntimeModule.js +16 -10
  202. package/lib/rules/RuleSetCompiler.js +211 -4
  203. package/lib/runtime/AsyncModuleRuntimeModule.js +98 -66
  204. package/lib/runtime/AutoPublicPathRuntimeModule.js +9 -0
  205. package/lib/runtime/BaseUriRuntimeModule.js +9 -0
  206. package/lib/runtime/ChunkNameRuntimeModule.js +9 -0
  207. package/lib/runtime/EnsureChunkRuntimeModule.js +35 -16
  208. package/lib/runtime/GetChunkFilenameRuntimeModule.js +12 -4
  209. package/lib/runtime/GetFullHashRuntimeModule.js +9 -0
  210. package/lib/runtime/GetMainFilenameRuntimeModule.js +9 -0
  211. package/lib/runtime/GetWorkletBootstrapRuntimeModule.js +9 -0
  212. package/lib/runtime/GlobalRuntimeModule.js +11 -4
  213. package/lib/runtime/HasOwnPropertyRuntimeModule.js +9 -0
  214. package/lib/runtime/HelperRuntimeModule.js +10 -0
  215. package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +305 -224
  216. package/lib/runtime/NonceRuntimeModule.js +9 -0
  217. package/lib/runtime/OnChunksLoadedRuntimeModule.js +67 -20
  218. package/lib/runtime/PublicPathRuntimeModule.js +9 -0
  219. package/lib/runtime/RuntimeIdRuntimeModule.js +9 -0
  220. package/lib/runtime/SpecNamespaceObjectRuntimeModule.js +90 -0
  221. package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +9 -0
  222. package/lib/runtime/StartupEntrypointRuntimeModule.js +9 -0
  223. package/lib/runtime/SystemContextRuntimeModule.js +9 -0
  224. package/lib/runtime/ToBinaryRuntimeModule.js +9 -0
  225. package/lib/schemes/DataUriPlugin.js +3 -6
  226. package/lib/schemes/VirtualUrlPlugin.js +1 -1
  227. package/lib/serialization/BinaryMiddleware.js +9 -9
  228. package/lib/serialization/FileMiddleware.js +16 -16
  229. package/lib/serialization/ObjectMiddleware.js +168 -139
  230. package/lib/sharing/ConsumeSharedPlugin.js +12 -0
  231. package/lib/sharing/ConsumeSharedRuntimeModule.js +11 -0
  232. package/lib/sharing/ShareRuntimeModule.js +9 -0
  233. package/lib/sharing/declaredShared.js +47 -0
  234. package/lib/stats/DefaultStatsFactoryPlugin.js +6 -5
  235. package/lib/stats/DefaultStatsPrinterPlugin.js +3 -0
  236. package/lib/typescript/TypeScriptPlugin.js +2 -3
  237. package/lib/url/URLParserPlugin.js +6 -8
  238. package/lib/util/LocConverter.js +4 -7
  239. package/lib/util/SourceProcessor.js +91 -91
  240. package/lib/util/async.js +292 -0
  241. package/lib/util/buildDiagnostics.js +69 -0
  242. package/lib/util/chainedImports.js +3 -4
  243. package/lib/util/concatenate.js +4 -4
  244. package/lib/util/createHooksRegistry.js +1 -2
  245. package/lib/util/dataURL.js +2 -3
  246. package/lib/util/deterministicGrouping.js +8 -13
  247. package/lib/util/findGraphRoots.js +6 -13
  248. package/lib/util/fs.js +27 -1
  249. package/lib/util/globUtils.js +1 -1
  250. package/lib/util/handlerKeys.js +40 -0
  251. package/lib/util/hash/wasm-hash.js +3 -4
  252. package/lib/util/identifier.js +20 -0
  253. package/lib/util/internalSerializables.js +5 -1
  254. package/lib/util/registerExternalSerializer.js +6 -45
  255. package/lib/util/semver.js +5 -3
  256. package/lib/wasm-async/AsyncWasmCompileRuntimeModule.js +9 -0
  257. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +9 -0
  258. package/lib/wasm-async/AsyncWebAssemblyGenerator.js +6 -1
  259. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +5 -1
  260. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +12 -4
  261. package/lib/wasm-sync/WebAssemblyGenerator.js +6 -1
  262. package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +5 -1
  263. package/lib/wasm-sync/WebAssemblyUtils.js +2 -4
  264. package/lib/web/JsonpChunkLoadingRuntimeModule.js +36 -0
  265. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +19 -0
  266. package/package.json +55 -46
  267. package/schemas/WebpackOptions.check.js +1 -1
  268. package/schemas/WebpackOptions.json +379 -66
  269. package/schemas/plugins/LoaderOptionsPlugin.check.js +1 -1
  270. package/schemas/plugins/ManifestPlugin.check.js +1 -1
  271. package/schemas/plugins/SourceMapDevToolPlugin.check.js +1 -1
  272. package/schemas/plugins/asset/AssetGeneratorOptions.check.js +1 -1
  273. package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.js +1 -1
  274. package/schemas/plugins/container/ContainerPlugin.check.js +1 -1
  275. package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
  276. package/schemas/plugins/debug/ProfilingPlugin.check.js +1 -1
  277. package/schemas/plugins/dll/DllReferencePlugin.check.js +1 -1
  278. package/schemas/plugins/ids/HashedModuleIdsPlugin.check.js +1 -1
  279. package/schemas/plugins/schemes/HttpUriPlugin.check.js +1 -1
  280. package/types.d.ts +1723 -604
  281. package/lib/dependencies/ExportBindingInitFragment.js +0 -191
  282. package/lib/errors/EntrypointOverlapWarning.js +0 -45
  283. package/lib/performance/EntrypointOverlapPlugin.js +0 -122
@@ -335,11 +335,9 @@ class LazyCompilationProxyModule extends Module {
335
335
  block.addDependency(dep);
336
336
  this.addBlock(block);
337
337
  } else if (hasClosureLibrary(compilation.options.output)) {
338
- // Reserve statically-declared externals as dependencies of the inactive
339
- // proxy so the initial entry chunk's library wrapper already exposes
340
- // their closure identifiers (e.g. `__WEBPACK_EXTERNAL_MODULE_react__`).
341
- // Once the proxy activates and the lazily-built module references those
342
- // externals, the identifiers resolve normally instead of throwing.
338
+ // Reserve the statically declared externals on the inactive proxy, so the
339
+ // entry chunk's library wrapper already exposes their closure identifiers
340
+ // and they resolve rather than throw once the proxy activates.
343
341
  const requests = collectStaticExternalRequests(
344
342
  options.externals,
345
343
  this.layer
@@ -9,6 +9,7 @@ const ConcatenationScope = require("../ConcatenationScope");
9
9
  const Generator = require("../Generator");
10
10
  const {
11
11
  HTML_TYPE,
12
+ HTML_TYPES,
12
13
  JAVASCRIPT_TYPE,
13
14
  JAVASCRIPT_TYPES
14
15
  } = require("../ModuleSourceTypeConstants");
@@ -225,12 +226,9 @@ const CHUNK_URL_SENTINEL_REGEXP =
225
226
  const HTML_PAGE_URL_SENTINEL_REGEXP =
226
227
  /__WEBPACK_HTML_PAGE_URL__([0-9a-f]+)__END__/g;
227
228
 
228
- // Sentinel for a URL-referenced asset (font/image/…) emitted into a resource-hint
229
- // `<link>` tag by `HtmlEntryDependency`; resolved to the asset's real emitted
230
- // URL from its codegen data during `HtmlModulesPlugin` render. Deferred because
231
- // HtmlEntry deps run *while* the HTML module is being codegen'd — the asset
232
- // module's own codegen might not have completed yet. Keyed by the asset
233
- // module's identifier, hex-encoded so any character in it is safe in a URL.
229
+ // Sentinel for a URL-referenced asset in a resource-hint `<link>`, resolved at
230
+ // `HtmlModulesPlugin` render because HtmlEntry deps run while the HTML module
231
+ // is codegen'd, before the asset's own. Keyed by hex-encoded identifier.
234
232
  const ASSET_URL_SENTINEL_REGEXP =
235
233
  /__WEBPACK_HTML_ASSET_URL__([0-9a-f]+)__END__/g;
236
234
 
@@ -239,11 +237,9 @@ const ASSET_URL_SENTINEL_REGEXP =
239
237
  /** @type {WeakSet<Compilation>} */
240
238
  const integritySentinelCompilations = new WeakSet();
241
239
 
242
- // Matches the whole ` integrity="<sentinel>"` so the attribute can be dropped
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.
240
+ // Matches the whole ` integrity="<sentinel>"`, so the attribute can be dropped
241
+ // when the per-asset `integrity` returns `false`. Minification runs first and
242
+ // may have unquoted it, hence the optional back-referenced quote.
247
243
  const INTEGRITY_SENTINEL_REGEXP =
248
244
  / integrity=(["']?)__WEBPACK_HTML_INTEGRITY__([0-9a-f]+)__([a-z]+)__END__\1/g;
249
245
 
@@ -252,10 +248,9 @@ const INTEGRITY_SENTINEL_REGEXP =
252
248
  const INTEGRITY_SENTINEL_STRIP_REGEXP =
253
249
  / integrity=(\\?["']|)__WEBPACK_HTML_INTEGRITY__[0-9a-f]+__[a-z]+__END__\1/g;
254
250
 
255
- // The trailing `(?:__<hash>)?` is the inlined chunk's content hash, embedded by
256
- // `embedInlineChunkHashes` so the host HTML's bytes (and its `[contenthash]`,
257
- // incl. RealContentHashPlugin's recompute) change with the inlined content; the
258
- // resolver ignores it.
251
+ // The trailing `(?:__<hash>)?` is the inlined chunk's content hash, embedded so
252
+ // the host page's bytes and `[contenthash]` change with the inlined content.
253
+ // The resolver ignores it.
259
254
  const INLINE_SENTINEL_REGEXP =
260
255
  /__WEBPACK_HTML_INLINE__([0-9a-f]+)__([a-z]+)(?:__[0-9a-f]+)?__END__/g;
261
256
 
@@ -448,12 +443,9 @@ class HtmlGenerator extends Generator {
448
443
  const url =
449
444
  /** @type {Record<string, string | undefined> | undefined} */
450
445
  (data.get("url"));
451
- // Prefer the `asset-url` channel — it's the actual URL string
452
- // (publicPath + filename). Also handled: assets reached only from JS
453
- // have no `asset-url` channel (their only URL is the JS expression
454
- // `__webpack_require__.p + "…"`); for those we reconstruct the URL
455
- // from the emitted `filename` + `PUBLIC_PATH_AUTO` so the same
456
- // undo-path substitution runs at asset render.
446
+ // Prefer the `asset-url` channel, which is the real URL string. An asset
447
+ // reached only from JS has none — its URL is a JS expression — so rebuild
448
+ // one from `filename` and let the undo-path substitution run.
457
449
  if (url && url["asset-url"]) return url["asset-url"];
458
450
  const filename = /** @type {string | undefined} */ (data.get("filename"));
459
451
  if (filename) return `${PUBLIC_PATH_AUTO}${filename}`;
@@ -692,10 +684,9 @@ class HtmlGenerator extends Generator {
692
684
  bodyDepth++;
693
685
  }
694
686
  },
695
- // Collected on exit: 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.
687
+ // Collected on exit, since an element's `end` is final only once it
688
+ // closes. `script`, `style`, `link` and `meta` never nest in each
689
+ // other, so exiting keeps them in source order.
699
690
  exit: (path) => {
700
691
  const name = path.tagName();
701
692
  if (name === "head") {
@@ -1047,19 +1038,19 @@ class HtmlGenerator extends Generator {
1047
1038
  * Creates an instance of HtmlGenerator.
1048
1039
  * @param {HtmlGeneratorOptions=} options generator options
1049
1040
  * @param {ModuleGraph=} moduleGraph the module graph; used to detect when an HTML module is reached as a compilation entry so `extract` can default to `true` for it
1041
+ * @param {((module: NormalModule) => boolean)=} isPageOnly tells whether the module's only output is its emitted page, so it exposes no JavaScript
1050
1042
  */
1051
- constructor(options, moduleGraph) {
1043
+ constructor(options, moduleGraph, isPageOnly) {
1052
1044
  super();
1053
1045
  /** @type {HtmlGeneratorOptions} */
1054
1046
  this.options = options || {};
1055
1047
  /** @type {ModuleGraph | undefined} */
1056
1048
  this._moduleGraph = moduleGraph;
1057
- // Raw dependency-template render (before `[webpack/auto]` resolution),
1058
- // shared between the JS and HTML type passes of a single
1059
- // `codeGeneration()` call. Keyed by that call's `runtimeRequirements`
1060
- // Set — created once per call and passed to every type's `generate()`,
1061
- // so it uniquely scopes the cache to one module's one code generation
1062
- // and releases with it. The two passes differ only in `undoPath`.
1049
+ /** @type {((module: NormalModule) => boolean) | undefined} */
1050
+ this._isPageOnly = isPageOnly;
1051
+ // Raw render shared between the JS and HTML passes of one `codeGeneration()`
1052
+ // call, which differ only in `undoPath`. Keyed by that call's
1053
+ // `runtimeRequirements` Set, so the entry is scoped to it and releases with it.
1063
1054
  /** @type {WeakMap<RuntimeRequirements, string>} */
1064
1055
  this._rawRenderCache = new WeakMap();
1065
1056
  }
@@ -1071,11 +1062,9 @@ class HtmlGenerator extends Generator {
1071
1062
  * @returns {string | undefined} reason why this module can't be concatenated, undefined when it can be concatenated
1072
1063
  */
1073
1064
  getConcatenationBailoutReason(module, context) {
1074
- // The HMR shim references the per-module `module.hot` object — when an
1075
- // HTML module is concatenated, that scope is gone (the merged file
1076
- // shares a single `module`), so the self-accept / DOM-patch wiring
1077
- // would target the wrong module id. Bail out of concatenation so the
1078
- // HMR-aware HTML module keeps its own module scope.
1065
+ // The HMR shim references the per-module `module.hot`, and a concatenated
1066
+ // file shares one `module`, so the self-accept wiring would target the wrong
1067
+ // id. Bail out, keeping the module's own scope.
1079
1068
  if (module.hot) {
1080
1069
  return "HTML module needs its own module scope for HMR";
1081
1070
  }
@@ -1134,6 +1123,9 @@ class HtmlGenerator extends Generator {
1134
1123
  */
1135
1124
  getTypes(module) {
1136
1125
  if (this._shouldExposeHtmlType(module)) {
1126
+ // A page nothing else reads has no JavaScript side: that chunk would
1127
+ // only re-export the markup already emitted as the `.html` asset.
1128
+ if (this._isPageOnly && this._isPageOnly(module)) return HTML_TYPES;
1137
1129
  return JAVASCRIPT_AND_HTML_TYPES;
1138
1130
  }
1139
1131
  return JAVASCRIPT_TYPES;
@@ -1143,10 +1135,9 @@ class HtmlGenerator extends Generator {
1143
1135
  * @returns {boolean} whether getTypes() depends on the module's incoming connections
1144
1136
  */
1145
1137
  getTypesDependOnIncomingConnections() {
1146
- // A fixed extract (`true` / `false` / `"inline"`) gives a stable type set;
1147
- // only the unset default reads `_isEntryModule` (incoming connections).
1148
- const { extract } = this.options;
1149
- return extract !== true && extract !== false && extract !== "inline";
1138
+ // Every page that can expose the html type reads incoming connections —
1139
+ // for the `extract` default, and for the page-only JavaScript drop.
1140
+ return this.options.extract !== false;
1150
1141
  }
1151
1142
 
1152
1143
  /**
@@ -1272,10 +1263,9 @@ class HtmlGenerator extends Generator {
1272
1263
  * @returns {string} the rewritten HTML
1273
1264
  */
1274
1265
  _renderHtml(module, generateContext, undoPath) {
1275
- // The dependency-template pass is identical for both type passes (no
1276
- // template branches on `type` or writes `runtimeRequirements`), so
1277
- // compute the raw render once per `codeGeneration()` and reuse it; the
1278
- // passes diverge only in the `[webpack/auto]` substitution below.
1266
+ // No dependency template branches on `type` or writes
1267
+ // `runtimeRequirements`, so the raw render is computed once per
1268
+ // `codeGeneration()`; the passes diverge only in the substitution below.
1279
1269
  const cacheKey = generateContext.runtimeRequirements;
1280
1270
  let rawContent = this._rawRenderCache.get(cacheKey);
1281
1271
  if (rawContent === undefined) {
@@ -1339,11 +1329,9 @@ class HtmlGenerator extends Generator {
1339
1329
 
1340
1330
  /** @type {string} */
1341
1331
  let sourceContent;
1342
- // `module.hot` is set by `HotModuleReplacementPlugin` on every module
1343
- // when HMR is enabled. When set, we cannot use the concatenation path
1344
- // (it merges into a parent's module scope, where `module.hot.accept`
1345
- // would target the wrong id) — `getConcatenationBailoutReason` keeps
1346
- // us out of concatenation in that case.
1332
+ // `module.hot` marks HMR being enabled, and concatenation merges into a
1333
+ // parent's scope where `module.hot.accept` would target the wrong id.
1334
+ // `getConcatenationBailoutReason` keeps such a module out of it.
1347
1335
  if (generateContext.concatenationScope && !module.hot) {
1348
1336
  generateContext.concatenationScope.registerNamespaceExport(
1349
1337
  ConcatenationScope.NAMESPACE_OBJECT_EXPORT
@@ -1417,15 +1405,11 @@ class HtmlGenerator extends Generator {
1417
1405
  const acceptBlock = extracting
1418
1406
  ? [
1419
1407
  "module.hot.accept();",
1420
- // Mask `<!-- … -->` comments — replace their characters
1421
- // with spaces, preserving length — before any tag regex
1422
- // runs. Masking (rather than deleting) keeps string offsets
1423
- // stable, so the body/title content can be sliced back out
1424
- // of the original HTML with comments intact, while a
1425
- // `<body>`/`</body>`/`<title>` inside a comment can no
1426
- // longer fool the tag regexes (the non-greedy `*?` would
1427
- // otherwise stop at the FIRST `</body>` it sees, even one
1428
- // inside a comment).
1408
+ // WHY: a `</body>` inside a comment stops the non-greedy `*?` at the
1409
+ // wrong place, so comments are masked before any tag regex runs.
1410
+ // Masking rather than deleting keeps offsets stable, so the body and
1411
+ // title can still be sliced out of the original HTML with their
1412
+ // comments intact.
1429
1413
  `${declare} __webpack_mask_comments__ = ${runtimeTemplate.returningFunction(
1430
1414
  `h.replace(/<!--[\\s\\S]*?-->/g, ${runtimeTemplate.returningFunction(
1431
1415
  'c.replace(/[^\\n]/g, " ")',
@@ -1469,9 +1453,8 @@ class HtmlGenerator extends Generator {
1469
1453
  ]
1470
1454
  )};`,
1471
1455
  // A `<script>` parsed out of a string carries the already-started flag,
1472
- // so appending 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.
1456
+ // so appending it would never run. A fresh one with the same attributes
1457
+ // and body does, as the reload this replaces would have.
1475
1458
  `${declare} __webpack_revive_script__ = ${runtimeTemplate.basicFunction(
1476
1459
  "node",
1477
1460
  [
@@ -1487,11 +1470,9 @@ class HtmlGenerator extends Generator {
1487
1470
  "return script;"
1488
1471
  ]
1489
1472
  )};`,
1490
- // Apply only the difference between the two authored heads, 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.
1473
+ // Apply only the difference between the two authored heads: the
1474
+ // runtime's own injected tags are in neither string, so replacing
1475
+ // `document.head` wholesale would tear them down where a delta cannot.
1495
1476
  `${declare} __webpack_patch_head__ = ${runtimeTemplate.basicFunction(
1496
1477
  "oldHtml, newHtml",
1497
1478
  [
@@ -1527,14 +1508,12 @@ class HtmlGenerator extends Generator {
1527
1508
  `${declare} removed = surplus(oldChildren, newChildren);`,
1528
1509
  `${declare} added = surplus(newChildren, oldChildren);`,
1529
1510
  "if (removed.length === 0 && added.length === 0) return true;",
1530
- // 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.
1511
+ // WHY: a script that has run cannot be un-run, so dropping one is the
1512
+ // single edit still worth a reload — but only a script that ran. A
1513
+ // `type` that is neither a JavaScript MIME essence, all of which end
1514
+ // in `script`, nor `module`, `importmap` or `speculationrules` is a
1515
+ // data block the browser never executed, as safe to remove as a
1516
+ // `<meta>`. An unrecognized type falls back to the reload.
1538
1517
  `if (removed.some(${runtimeTemplate.basicFunction("node", [
1539
1518
  'if (node.nodeName !== "SCRIPT") return false;',
1540
1519
  `${declare} type = (node.getAttribute("type") || "").trim().toLowerCase();`,
@@ -1558,11 +1537,9 @@ class HtmlGenerator extends Generator {
1558
1537
  ]),
1559
1538
  "}",
1560
1539
  `for (${mutable} i = 0; i < live.length; i++) document.head.removeChild(live[i]);`,
1561
- // Pair each retained element with its live node, scanning 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.
1540
+ // Pair each retained element with its live node, scanning forward
1541
+ // only: a moved element then finds no match and falls back to the
1542
+ // reload, while an injected node never matches either way.
1566
1543
  `${declare} liveByNew = [];`,
1567
1544
  `${mutable} searchFrom = 0;`,
1568
1545
  `for (${mutable} i = 0; i < newChildren.length; i++) {`,
@@ -1642,13 +1619,22 @@ class HtmlGenerator extends Generator {
1642
1619
  */
1643
1620
  generateError(error, module, generateContext) {
1644
1621
  if (generateContext.type === HTML_TYPE) {
1645
- // Strip `<`, `>`, `--` runs from `error.message` so it can't escape the comment.
1646
- const safe = String(error.message)
1622
+ // Strip `<`, `>`, `--` runs from the message so it can't escape the comment.
1623
+ const safe = Generator.buildErrorMessage(
1624
+ error,
1625
+ generateContext.runtimeTemplate.requestShortener
1626
+ )
1647
1627
  .replace(/[<>]/g, "")
1648
1628
  .replace(/-{2,}/g, (m) => `${"-".repeat(m.length - 1)} `);
1649
1629
  return new RawSource(`<!-- webpack error: ${safe} -->`);
1650
1630
  }
1651
- return new RawSource(Generator.throwBuildErrorCode(error));
1631
+ return new RawSource(
1632
+ Generator.throwBuildErrorCode(
1633
+ error,
1634
+ undefined,
1635
+ generateContext.runtimeTemplate.requestShortener
1636
+ )
1637
+ );
1652
1638
  }
1653
1639
 
1654
1640
  /**
@@ -1658,10 +1644,9 @@ class HtmlGenerator extends Generator {
1658
1644
  */
1659
1645
  updateHash(hash, updateHashContext) {
1660
1646
  hash.update("html");
1661
- // Source-type set changes when html-type exposure flips; the HMR shim's
1662
- // `extracting` branch changes when the emit decision flips. They differ
1663
- // only for `"inline"` (exposes html, but does not emit), so hash both.
1664
- // One `_shouldExtract` walk covers both checks (expose = extract ∪ inline).
1647
+ // The source-type set turns on html-type exposure and the HMR shim's
1648
+ // `extracting` branch on the emit decision. They differ only for
1649
+ // `"inline"`, which exposes html without emitting, so hash both.
1665
1650
  const extract = this._shouldExtract(updateHashContext.module);
1666
1651
  if (extract || this.options.extract === "inline") {
1667
1652
  hash.update("html-type");