webpack 5.111.0 → 5.111.1

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 (144) hide show
  1. package/lib/APIPlugin.js +3 -4
  2. package/lib/CompatibilityPlugin.js +3 -4
  3. package/lib/Compilation.js +16 -35
  4. package/lib/Compiler.js +4 -5
  5. package/lib/ConstPlugin.js +16 -132
  6. package/lib/DependencyTemplate.js +2 -1
  7. package/lib/DotenvPlugin.js +24 -28
  8. package/lib/ErrorHelpers.js +113 -0
  9. package/lib/ExportsInfo.js +20 -16
  10. package/lib/ExternalModule.js +6 -8
  11. package/lib/FlagDependencyExportsPlugin.js +8 -13
  12. package/lib/FlagDependencyUsagePlugin.js +9 -13
  13. package/lib/Generator.js +24 -2
  14. package/lib/HotModuleReplacementPlugin.js +2 -0
  15. package/lib/IgnorePlugin.js +1 -1
  16. package/lib/LoaderOptionsPlugin.js +1 -1
  17. package/lib/Module.js +3 -3
  18. package/lib/ModuleGraph.js +6 -9
  19. package/lib/MultiCompiler.js +6 -16
  20. package/lib/NormalModule.js +96 -44
  21. package/lib/RuntimeTemplate.js +33 -43
  22. package/lib/SourceMapDevToolPlugin.js +53 -103
  23. package/lib/TemplatedPathPlugin.js +16 -59
  24. package/lib/asset/AssetBytesGenerator.js +7 -1
  25. package/lib/asset/AssetGenerator.js +25 -16
  26. package/lib/asset/AssetSourceGenerator.js +7 -1
  27. package/lib/buildChunkGraph.js +11 -15
  28. package/lib/cache/MemoryCachePlugin.js +4 -4
  29. package/lib/cache/MemoryWithGcCachePlugin.js +7 -8
  30. package/lib/cache/PackFileCacheStrategy.js +3 -18
  31. package/lib/cache/getLazyHashedEtag.js +3 -5
  32. package/lib/config/browserslistTargetHandler.js +2 -8
  33. package/lib/config/defaults.js +52 -78
  34. package/lib/config/getClaimedAssetTypes.js +10 -11
  35. package/lib/config/target.js +3 -4
  36. package/lib/{ContextExclusionPlugin.js → context/ContextExclusionPlugin.js} +1 -1
  37. package/lib/{ContextModule.js → context/ContextModule.js} +37 -34
  38. package/lib/{ContextModuleFactory.js → context/ContextModuleFactory.js} +19 -21
  39. package/lib/{ContextReplacementPlugin.js → context/ContextReplacementPlugin.js} +4 -4
  40. package/lib/css/CssGenerator.js +19 -11
  41. package/lib/css/CssParser.js +18 -20
  42. package/lib/css/cssMinify.js +32 -29
  43. package/lib/css/data.js +797 -288
  44. package/lib/css/syntax.js +2250 -934
  45. package/lib/debug/ProfilingPlugin.js +3 -4
  46. package/lib/dependencies/CommonJsExportRequireDependency.js +10 -11
  47. package/lib/dependencies/CommonJsImportsParserPlugin.js +4 -5
  48. package/lib/dependencies/CommonJsSelfReferenceDependency.js +2 -4
  49. package/lib/dependencies/ContextDependency.js +1 -1
  50. package/lib/dependencies/ContextDependencyHelpers.js +3 -9
  51. package/lib/dependencies/ContextElementDependency.js +1 -1
  52. package/lib/dependencies/CssIcssExportDependency.js +6 -8
  53. package/lib/dependencies/CssIcssImportDependency.js +3 -6
  54. package/lib/dependencies/CssUrlDependency.js +3 -5
  55. package/lib/dependencies/HarmonyCompatibilityDependency.js +11 -20
  56. package/lib/dependencies/HarmonyDetectionParserPlugin.js +3 -4
  57. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +2 -4
  58. package/lib/dependencies/HarmonyExportExpressionDependency.js +3 -4
  59. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +3 -4
  60. package/lib/dependencies/HarmonyExportInitFragment.js +26 -19
  61. package/lib/dependencies/HarmonyExportSpecifierDependency.js +7 -28
  62. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +103 -16
  63. package/lib/dependencies/HarmonyImportSideEffectDependency.js +3 -4
  64. package/lib/dependencies/HarmonyImportSpecifierDependency.js +16 -2
  65. package/lib/dependencies/HtmlEntryDependency.js +74 -102
  66. package/lib/dependencies/HtmlInlineScriptDependency.js +3 -4
  67. package/lib/dependencies/HtmlInlineStyleDependency.js +3 -4
  68. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +1 -1
  69. package/lib/dependencies/ImportMetaGlobHelpers.js +1 -1
  70. package/lib/dependencies/ImportMetaPlugin.js +8 -10
  71. package/lib/dependencies/ImportParserPlugin.js +1 -1
  72. package/lib/dependencies/LoaderPlugin.js +26 -1
  73. package/lib/dependencies/RequireContextDependencyParserPlugin.js +1 -1
  74. package/lib/dependencies/URLContextDependency.js +1 -1
  75. package/lib/dependencies/URLDependency.js +6 -5
  76. package/lib/dependencies/WorkerAndWorkletPlugin.js +15 -21
  77. package/lib/dependencies/WorkerDependency.js +6 -5
  78. package/lib/dependencies/WorkletDependency.js +6 -9
  79. package/lib/errors/HookWebpackError.js +3 -2
  80. package/lib/hmr/LazyCompilationPlugin.js +3 -5
  81. package/lib/html/HtmlGenerator.js +61 -82
  82. package/lib/html/HtmlModulesPlugin.js +88 -139
  83. package/lib/html/HtmlParser.js +97 -141
  84. package/lib/html/data.js +21 -0
  85. package/lib/html/htmlMinify.js +10 -11
  86. package/lib/html/syntax.js +883 -993
  87. package/lib/index.js +46 -3
  88. package/lib/javascript/ChunkFormatHelpers.js +4 -3
  89. package/lib/javascript/JavascriptGenerator.js +8 -1
  90. package/lib/javascript/JavascriptModulesPlugin.js +21 -48
  91. package/lib/javascript/JavascriptParser.js +721 -178
  92. package/lib/javascript/parser.js +6 -0
  93. package/lib/javascript/syntax.js +420 -92
  94. package/lib/json/JsonGenerator.js +7 -1
  95. package/lib/library/ModuleLibraryPlugin.js +64 -136
  96. package/lib/loaders/LoaderRunner.js +137 -9
  97. package/lib/node/NodeWatchFileSystem.js +3 -9
  98. package/lib/optimize/AggressiveMergingPlugin.js +3 -5
  99. package/lib/optimize/ConcatenatedModule.js +81 -100
  100. package/lib/optimize/FlagIncludedChunksPlugin.js +3 -11
  101. package/lib/optimize/InnerGraphPlugin.js +7 -13
  102. package/lib/optimize/LimitChunkCountPlugin.js +5 -8
  103. package/lib/optimize/MangleExportsPlugin.js +3 -4
  104. package/lib/optimize/ModuleConcatenationPlugin.js +3 -4
  105. package/lib/optimize/SideEffectsFlagPlugin.js +7 -19
  106. package/lib/optimize/SplitChunksPlugin.js +2 -4
  107. package/lib/performance/BroadContextsPlugin.js +1 -1
  108. package/lib/performance/CacheEffectivenessPlugin.js +3 -4
  109. package/lib/performance/SizeLimitsPlugin.js +2 -4
  110. package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +6 -8
  111. package/lib/prefetch/ResourceHintPlugin.js +17 -21
  112. package/lib/prefetch/StartupAssetHintRuntimeModule.js +7 -10
  113. package/lib/runtime/AsyncModuleRuntimeModule.js +3 -5
  114. package/lib/runtime/GetChunkFilenameRuntimeModule.js +3 -4
  115. package/lib/runtime/GlobalRuntimeModule.js +2 -4
  116. package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +55 -85
  117. package/lib/schemes/DataUriPlugin.js +3 -6
  118. package/lib/schemes/VirtualUrlPlugin.js +1 -1
  119. package/lib/serialization/BinaryMiddleware.js +9 -9
  120. package/lib/serialization/FileMiddleware.js +16 -16
  121. package/lib/serialization/ObjectMiddleware.js +30 -33
  122. package/lib/stats/DefaultStatsFactoryPlugin.js +3 -4
  123. package/lib/typescript/TypeScriptPlugin.js +2 -3
  124. package/lib/url/URLParserPlugin.js +6 -8
  125. package/lib/util/LocConverter.js +4 -7
  126. package/lib/util/SourceProcessor.js +15 -22
  127. package/lib/util/chainedImports.js +3 -4
  128. package/lib/util/concatenate.js +4 -4
  129. package/lib/util/createHooksRegistry.js +1 -2
  130. package/lib/util/dataURL.js +2 -3
  131. package/lib/util/deterministicGrouping.js +8 -13
  132. package/lib/util/findGraphRoots.js +6 -13
  133. package/lib/util/globUtils.js +1 -1
  134. package/lib/util/hash/wasm-hash.js +3 -4
  135. package/lib/util/internalSerializables.js +1 -1
  136. package/lib/util/semver.js +5 -3
  137. package/lib/wasm-async/AsyncWebAssemblyGenerator.js +6 -1
  138. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +5 -1
  139. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +3 -4
  140. package/lib/wasm-sync/WebAssemblyGenerator.js +6 -1
  141. package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +5 -1
  142. package/lib/wasm-sync/WebAssemblyUtils.js +2 -4
  143. package/package.json +30 -23
  144. package/types.d.ts +299 -280
@@ -45,7 +45,7 @@ const getCommentCompilationWarning = memoize(() =>
45
45
  * } from "../../declarations/WebpackOptions"
46
46
  */
47
47
  /** @import { RawChunkGroupOptions } from "../ChunkGroup" */
48
- /** @import { ContextMode } from "../ContextModule" */
48
+ /** @import { ContextMode } from "../context/ContextModule" */
49
49
  /** @import { RawReferencedExports } from "../Dependency" */
50
50
  /** @import { BuildMeta } from "../Module" */
51
51
  /**
@@ -21,7 +21,7 @@ const LoaderImportDependency = require("./LoaderImportDependency");
21
21
  * } from "../Compilation"
22
22
  */
23
23
  /** @import Compiler from "../Compiler" */
24
- /** @import { BuildInfo } from "../Module" */
24
+ /** @import Module, { BuildInfo } from "../Module" */
25
25
 
26
26
  /**
27
27
  * Defines the import module callback callback.
@@ -39,6 +39,31 @@ const LoaderImportDependency = require("./LoaderImportDependency");
39
39
  * @property {string=} baseUri target base uri
40
40
  */
41
41
 
42
+ /**
43
+ * @callback LoadModuleCallback
44
+ * @param {Error | null} err error object
45
+ * @param {(string | Buffer)=} source source of the loaded module
46
+ * @param {(object | null)=} sourceMap source map of the loaded module
47
+ * @param {Module=} module the loaded module
48
+ * @returns {void}
49
+ */
50
+
51
+ /**
52
+ * `importModule` takes a callback or, given none, answers with a promise, and
53
+ * TypeScript reads an intersection of call signatures as an overload set
54
+ * @typedef {{ (request: string, options: ImportModuleOptions | undefined, callback: ImportModuleCallback): void } & { (request: string, options?: ImportModuleOptions): Promise<ExecuteModuleExports> }} ImportModuleMethod
55
+ */
56
+
57
+ /**
58
+ * These properties are added by the LoaderPlugin
59
+ * @typedef {object} LoaderPluginLoaderContext
60
+ * @property {(request: string, callback: LoadModuleCallback) => void} loadModule Resolves the given request to a module, applies all configured loaders and calls
61
+ * back with the generated source, the sourceMap and the module instance (usually an
62
+ * instance of NormalModule). Use this function if you need to know the source code
63
+ * of another module to generate the result.
64
+ * @property {ImportModuleMethod} importModule
65
+ */
66
+
42
67
  const PLUGIN_NAME = "LoaderPlugin";
43
68
 
44
69
  class LoaderPlugin {
@@ -7,7 +7,7 @@
7
7
 
8
8
  const RequireContextDependency = require("./RequireContextDependency");
9
9
 
10
- /** @import { ContextMode } from "../ContextModule" */
10
+ /** @import { ContextMode } from "../context/ContextModule" */
11
11
  /** @import JavascriptParser, { Range } from "../javascript/JavascriptParser" */
12
12
 
13
13
  const PLUGIN_NAME = "RequireContextDependencyParserPlugin";
@@ -9,7 +9,7 @@ const makeSerializable = require("../util/makeSerializable");
9
9
  const ContextDependency = require("./ContextDependency");
10
10
  const ContextDependencyTemplateAsRequireCall = require("./ContextDependencyTemplateAsRequireCall");
11
11
 
12
- /** @import { ContextOptions } from "../ContextModule" */
12
+ /** @import { ContextOptions } from "../context/ContextModule" */
13
13
  /** @import { Range } from "../javascript/JavascriptParser" */
14
14
  /** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext<[Range]>} ObjectDeserializerContext */
15
15
  /** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext<[Range]>} ObjectSerializerContext */
@@ -263,11 +263,12 @@ URLDependency.Template = class URLDependencyTemplate extends (
263
263
  return;
264
264
  }
265
265
 
266
- // For ESM module output, emit the analyzable `new URL("./asset", import.meta.url)`
267
- // form (literal specifier, no runtime helpers) so other bundlers and webpack itself
268
- // can statically follow the asset. `url: "relative"` keeps the runtime form.
269
- // A prefetch/preload hint doesn't force it: the `<link>` is emitted separately at
270
- // chunk startup (`StartupAssetHintRuntimeModule`), independent of the call site.
266
+ // WHY: ESM module output emits the analyzable
267
+ // `new URL("./asset", import.meta.url)` form — a literal specifier, no runtime
268
+ // helpers — so other bundlers and webpack itself can statically follow the
269
+ // asset, while `url: "relative"` keeps the runtime form. A prefetch or preload
270
+ // hint does not force it: the `<link>` is emitted separately at chunk startup
271
+ // (`StartupAssetHintRuntimeModule`), independent of the call site.
271
272
  if (
272
273
  !dep.relative &&
273
274
  runtimeTemplate.supportsAnalyzable(
@@ -86,10 +86,9 @@ const WORKER_DEFAULT_SYNTAX = [
86
86
  "Worker from worker_threads"
87
87
  ];
88
88
 
89
- // Worklets are always module scripts loaded through `addModule` and — unlike Web
90
- // Workers — cannot load additional chunks at runtime (no `importScripts`, no
91
- // dynamic `import()`). The WorkletDependency wraps the call so every chunk is
92
- // pre-added via `addModule` from the calling scope (see WorkletDependency).
89
+ // A worklet is always a module script loaded through `addModule`, and unlike a
90
+ // Web Worker cannot load further chunks at runtime, so WorkletDependency wraps
91
+ // the call and pre-adds every chunk from the calling scope.
93
92
  const WORKLET_DEFAULT_SYNTAX = [
94
93
  "*context.audioWorklet.addModule()",
95
94
  "*audioWorklet.addModule()",
@@ -406,10 +405,9 @@ class WorkerAndWorkletPlugin {
406
405
  )
407
406
  );
408
407
  } else {
409
- // `webpackEntryOptions` is user input from a magic
410
- // comment, so copy only safe own keys to avoid
411
- // prototype pollution via `__proto__`/`constructor`/
412
- // `prototype`.
408
+ // `webpackEntryOptions` is user input from a magic comment, so
409
+ // only safe own keys are copied, against prototype pollution
410
+ // through `__proto__` or `constructor`.
413
411
  const userEntryOptions = importOptions.webpackEntryOptions;
414
412
  for (const key of Object.keys(userEntryOptions)) {
415
413
  if (
@@ -502,11 +500,9 @@ class WorkerAndWorkletPlugin {
502
500
 
503
501
  /** @type {ResourceHint | undefined} */
504
502
  let resourceHint;
505
- // Resource-hint comments belong to the asset expression — read
506
- // them from the inner `new URL(...)` range only, never from
507
- // elsewhere inside `new Worker(...)`. When `arg1` is bare
508
- // `import.meta.url` there is no `new URL` and no place for
509
- // the comments to go, so resource hints are skipped.
503
+ // Resource-hint comments belong to the asset expression, so they are
504
+ // read from the inner `new URL(...)` range alone. A bare
505
+ // `import.meta.url` has none, so its hints are skipped.
510
506
  if (arg1.type === "NewExpression") {
511
507
  const { options: urlImportOptions } = parser.parseCommentOptions(
512
508
  /** @type {Range} */ (arg1.range)
@@ -652,10 +648,9 @@ class WorkerAndWorkletPlugin {
652
648
  name: entryOptions.name,
653
649
  circular: false,
654
650
  entryOptions: {
655
- // A module worklet links its split chunks via native `import`
656
- // (resolved by `addModule`), so it keeps the module chunk
657
- // loading. A script worklet can't load chunks at runtime, so its
658
- // chunks use import-scripts and are pre-added from the calling scope.
651
+ // A module worklet links its split chunks through native `import`
652
+ // and keeps module chunk loading. A script worklet loads none at
653
+ // runtime, so its chunks are pre-added from the calling scope.
659
654
  chunkLoading: this._module
660
655
  ? this._chunkLoading
661
656
  : "import-scripts",
@@ -800,10 +795,9 @@ class WorkerAndWorkletPlugin {
800
795
  );
801
796
  }
802
797
 
803
- // Worklet parsing is opt-in: unset falls back to the `futureDefaults`
804
- // default, `false` disables it. It is not defaulted in
805
- // `config/defaults.js` because that would splice into the `"..."`
806
- // merge sentinel of a user-provided list.
798
+ // Worklet parsing is opt-in: unset falls back to `futureDefaults` and
799
+ // `false` disables it. Not defaulted in `config/defaults.js`, which
800
+ // would splice into a user list's `"..."` sentinel.
807
801
  const workletOption =
808
802
  parserOptions.worklet === undefined
809
803
  ? this._workletDefault
@@ -131,11 +131,12 @@ WorkerDependency.Template = class WorkerDependencyTemplate extends (
131
131
  );
132
132
  const chunk = entrypoint.getEntrypointChunk();
133
133
 
134
- // For ESM module output emit the analyzable `new URL("./worker.<name>.js",
135
- // import.meta.url)` form (literal specifier, no runtime helpers) so other bundlers
136
- // and webpack itself can statically follow the worker. A resource hint doesn't
137
- // block it: the `<link>` is emitted at chunk startup instead of wrapping the href,
138
- // which would turn the specifier into a non-analyzable expression.
134
+ // WHY: ESM module output emits the analyzable
135
+ // `new URL("./worker.<name>.js", import.meta.url)` form — a literal specifier,
136
+ // no runtime helpers — so other bundlers and webpack itself can statically
137
+ // follow the worker. A resource hint does not block it: the `<link>` is
138
+ // emitted at chunk startup instead of wrapping the href, which would turn the
139
+ // specifier into a non-analyzable expression.
139
140
  const analyzableSpecifier = runtimeTemplate.getAnalyzableWorkerUrl(
140
141
  dep.options.publicPath,
141
142
  chunk,
@@ -136,10 +136,9 @@ WorkletDependency.Template = class WorkletDependencyTemplate extends (
136
136
  const runtimeChunkId =
137
137
  runtimeChunk && runtimeChunk.id !== null ? runtimeChunk.id : null;
138
138
 
139
- // For ESM module output emit the analyzable `new URL("./worklet.<name>.js",
140
- // import.meta.url)` form (literal specifier, no runtime helpers) so other bundlers
141
- // and webpack itself can statically follow the worklet. The worklet chunk links its
142
- // splits via native `import`, so only the entry chunk is referenced.
139
+ // ESM output emits the analyzable `new URL("./worklet.<name>.js",
140
+ // import.meta.url)`, which another bundler can follow statically. Only the
141
+ // entry chunk is named, its splits being linked by native `import`.
143
142
  const analyzableSpecifier = runtimeTemplate.getAnalyzableWorkerUrl(
144
143
  dep.options.publicPath,
145
144
  entryChunk,
@@ -196,11 +195,9 @@ WorkletDependency.Template = class WorkletDependencyTemplate extends (
196
195
  return;
197
196
  }
198
197
 
199
- // A worklet can't load chunks at runtime, so every reachable chunk (initial
200
- // splits and async `import()` targets alike) is pre-added via `addModule`
201
- // from the calling scope. The runtime chunk is added last so it installs the
202
- // chunks pushed before it and runs entry startup with every module present
203
- // (see ImportScriptsChunkLoadingRuntimeModule).
198
+ // A worklet loads no chunks at runtime, so every reachable one is pre-added
199
+ // from the calling scope. The runtime chunk goes last, installing what came
200
+ // before it and running startup with every module present.
204
201
  /** @type {(string | number)[]} */
205
202
  const restChunkIds = [];
206
203
  for (const chunk of referencedChunks) {
@@ -5,6 +5,7 @@
5
5
 
6
6
  "use strict";
7
7
 
8
+ const { toError } = require("../ErrorHelpers");
8
9
  const makeSerializable = require("../util/makeSerializable");
9
10
  const WebpackError = require("./WebpackError");
10
11
 
@@ -67,13 +68,13 @@ makeSerializable(HookWebpackError, "webpack/lib/errors/HookWebpackError");
67
68
 
68
69
  /**
69
70
  * Creates webpack error.
70
- * @param {Error} error an error
71
+ * @param {EXPECTED_ANY} error what a plugin failed with
71
72
  * @param {string} hook name of the hook
72
73
  * @returns {WebpackError} a webpack error
73
74
  */
74
75
  const makeWebpackError = (error, hook) => {
75
76
  if (error instanceof WebpackError) return error;
76
- return new HookWebpackError(error, hook);
77
+ return new HookWebpackError(toError(error), hook);
77
78
  };
78
79
 
79
80
  HookWebpackError.makeWebpackError = makeWebpackError;
@@ -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
@@ -226,12 +226,9 @@ const CHUNK_URL_SENTINEL_REGEXP =
226
226
  const HTML_PAGE_URL_SENTINEL_REGEXP =
227
227
  /__WEBPACK_HTML_PAGE_URL__([0-9a-f]+)__END__/g;
228
228
 
229
- // Sentinel for a URL-referenced asset (font/image/…) emitted into a resource-hint
230
- // `<link>` tag by `HtmlEntryDependency`; resolved to the asset's real emitted
231
- // URL from its codegen data during `HtmlModulesPlugin` render. Deferred because
232
- // HtmlEntry deps run *while* the HTML module is being codegen'd — the asset
233
- // module's own codegen might not have completed yet. Keyed by the asset
234
- // 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.
235
232
  const ASSET_URL_SENTINEL_REGEXP =
236
233
  /__WEBPACK_HTML_ASSET_URL__([0-9a-f]+)__END__/g;
237
234
 
@@ -240,11 +237,9 @@ const ASSET_URL_SENTINEL_REGEXP =
240
237
  /** @type {WeakSet<Compilation>} */
241
238
  const integritySentinelCompilations = new WeakSet();
242
239
 
243
- // Matches the whole ` integrity="<sentinel>"` so the attribute can be dropped
244
- // entirely when the per-asset `integrity` function returns `false`. Minification
245
- // runs first and may have unquoted the value (§13.1.2.3), so the quote is
246
- // optional and back-referenced to keep the pair matched; the replacement always
247
- // 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.
248
243
  const INTEGRITY_SENTINEL_REGEXP =
249
244
  / integrity=(["']?)__WEBPACK_HTML_INTEGRITY__([0-9a-f]+)__([a-z]+)__END__\1/g;
250
245
 
@@ -253,10 +248,9 @@ const INTEGRITY_SENTINEL_REGEXP =
253
248
  const INTEGRITY_SENTINEL_STRIP_REGEXP =
254
249
  / integrity=(\\?["']|)__WEBPACK_HTML_INTEGRITY__[0-9a-f]+__[a-z]+__END__\1/g;
255
250
 
256
- // The trailing `(?:__<hash>)?` is the inlined chunk's content hash, embedded by
257
- // `embedInlineChunkHashes` so the host HTML's bytes (and its `[contenthash]`,
258
- // incl. RealContentHashPlugin's recompute) change with the inlined content; the
259
- // 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.
260
254
  const INLINE_SENTINEL_REGEXP =
261
255
  /__WEBPACK_HTML_INLINE__([0-9a-f]+)__([a-z]+)(?:__[0-9a-f]+)?__END__/g;
262
256
 
@@ -449,12 +443,9 @@ class HtmlGenerator extends Generator {
449
443
  const url =
450
444
  /** @type {Record<string, string | undefined> | undefined} */
451
445
  (data.get("url"));
452
- // Prefer the `asset-url` channel — it's the actual URL string
453
- // (publicPath + filename). Also handled: assets reached only from JS
454
- // have no `asset-url` channel (their only URL is the JS expression
455
- // `__webpack_require__.p + "…"`); for those we reconstruct the URL
456
- // from the emitted `filename` + `PUBLIC_PATH_AUTO` so the same
457
- // 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.
458
449
  if (url && url["asset-url"]) return url["asset-url"];
459
450
  const filename = /** @type {string | undefined} */ (data.get("filename"));
460
451
  if (filename) return `${PUBLIC_PATH_AUTO}${filename}`;
@@ -693,10 +684,9 @@ class HtmlGenerator extends Generator {
693
684
  bodyDepth++;
694
685
  }
695
686
  },
696
- // Collected on exit: an element's `end` is only final once it
697
- // closes, and the streamed walk enters it while it is still open.
698
- // `script` / `style` / `link` / `meta` never nest in each other, so
699
- // 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.
700
690
  exit: (path) => {
701
691
  const name = path.tagName();
702
692
  if (name === "head") {
@@ -1058,12 +1048,9 @@ class HtmlGenerator extends Generator {
1058
1048
  this._moduleGraph = moduleGraph;
1059
1049
  /** @type {((module: NormalModule) => boolean) | undefined} */
1060
1050
  this._isPageOnly = isPageOnly;
1061
- // Raw dependency-template render (before `[webpack/auto]` resolution),
1062
- // shared between the JS and HTML type passes of a single
1063
- // `codeGeneration()` call. Keyed by that call's `runtimeRequirements`
1064
- // Set — created once per call and passed to every type's `generate()`,
1065
- // so it uniquely scopes the cache to one module's one code generation
1066
- // and releases with it. The two passes differ only in `undoPath`.
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.
1067
1054
  /** @type {WeakMap<RuntimeRequirements, string>} */
1068
1055
  this._rawRenderCache = new WeakMap();
1069
1056
  }
@@ -1075,11 +1062,9 @@ class HtmlGenerator extends Generator {
1075
1062
  * @returns {string | undefined} reason why this module can't be concatenated, undefined when it can be concatenated
1076
1063
  */
1077
1064
  getConcatenationBailoutReason(module, context) {
1078
- // The HMR shim references the per-module `module.hot` object — when an
1079
- // HTML module is concatenated, that scope is gone (the merged file
1080
- // shares a single `module`), so the self-accept / DOM-patch wiring
1081
- // would target the wrong module id. Bail out of concatenation so the
1082
- // 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.
1083
1068
  if (module.hot) {
1084
1069
  return "HTML module needs its own module scope for HMR";
1085
1070
  }
@@ -1278,10 +1263,9 @@ class HtmlGenerator extends Generator {
1278
1263
  * @returns {string} the rewritten HTML
1279
1264
  */
1280
1265
  _renderHtml(module, generateContext, undoPath) {
1281
- // The dependency-template pass is identical for both type passes (no
1282
- // template branches on `type` or writes `runtimeRequirements`), so
1283
- // compute the raw render once per `codeGeneration()` and reuse it; the
1284
- // 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.
1285
1269
  const cacheKey = generateContext.runtimeRequirements;
1286
1270
  let rawContent = this._rawRenderCache.get(cacheKey);
1287
1271
  if (rawContent === undefined) {
@@ -1345,11 +1329,9 @@ class HtmlGenerator extends Generator {
1345
1329
 
1346
1330
  /** @type {string} */
1347
1331
  let sourceContent;
1348
- // `module.hot` is set by `HotModuleReplacementPlugin` on every module
1349
- // when HMR is enabled. When set, we cannot use the concatenation path
1350
- // (it merges into a parent's module scope, where `module.hot.accept`
1351
- // would target the wrong id) — `getConcatenationBailoutReason` keeps
1352
- // 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.
1353
1335
  if (generateContext.concatenationScope && !module.hot) {
1354
1336
  generateContext.concatenationScope.registerNamespaceExport(
1355
1337
  ConcatenationScope.NAMESPACE_OBJECT_EXPORT
@@ -1423,15 +1405,11 @@ class HtmlGenerator extends Generator {
1423
1405
  const acceptBlock = extracting
1424
1406
  ? [
1425
1407
  "module.hot.accept();",
1426
- // Mask `<!-- … -->` comments — replace their characters
1427
- // with spaces, preserving length — before any tag regex
1428
- // runs. Masking (rather than deleting) keeps string offsets
1429
- // stable, so the body/title content can be sliced back out
1430
- // of the original HTML with comments intact, while a
1431
- // `<body>`/`</body>`/`<title>` inside a comment can no
1432
- // longer fool the tag regexes (the non-greedy `*?` would
1433
- // otherwise stop at the FIRST `</body>` it sees, even one
1434
- // 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.
1435
1413
  `${declare} __webpack_mask_comments__ = ${runtimeTemplate.returningFunction(
1436
1414
  `h.replace(/<!--[\\s\\S]*?-->/g, ${runtimeTemplate.returningFunction(
1437
1415
  'c.replace(/[^\\n]/g, " ")',
@@ -1475,9 +1453,8 @@ class HtmlGenerator extends Generator {
1475
1453
  ]
1476
1454
  )};`,
1477
1455
  // A `<script>` parsed out of a string carries the already-started flag,
1478
- // so appending that element would never run it. A fresh one with the
1479
- // same attributes and body does — which is what the reload this
1480
- // 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.
1481
1458
  `${declare} __webpack_revive_script__ = ${runtimeTemplate.basicFunction(
1482
1459
  "node",
1483
1460
  [
@@ -1493,11 +1470,9 @@ class HtmlGenerator extends Generator {
1493
1470
  "return script;"
1494
1471
  ]
1495
1472
  )};`,
1496
- // Apply only the difference between the two authored heads, keyed on
1497
- // serialized markup: the runtime's own injected `<script>` / `<link>`
1498
- // are in neither string, so replacing `document.head` wholesale would
1499
- // tear them down while a delta never touches them. Reports whether it
1500
- // 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.
1501
1476
  `${declare} __webpack_patch_head__ = ${runtimeTemplate.basicFunction(
1502
1477
  "oldHtml, newHtml",
1503
1478
  [
@@ -1533,14 +1508,12 @@ class HtmlGenerator extends Generator {
1533
1508
  `${declare} removed = surplus(oldChildren, newChildren);`,
1534
1509
  `${declare} added = surplus(newChildren, oldChildren);`,
1535
1510
  "if (removed.length === 0 && added.length === 0) return true;",
1536
- // A script that has run cannot be un-run, so dropping one is the
1537
- // one edit still worth a reload — but only a script that ran. A
1538
- // `type` that is neither a JavaScript MIME type nor `module` /
1539
- // `importmap` / `speculationrules` makes the element a data block
1540
- // (`application/ld+json`, `text/template`, …) the browser never
1541
- // executed, so removing it is as safe as removing a `<meta>`.
1542
- // Every JavaScript MIME essence ends in `script`, and a type
1543
- // 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.
1544
1517
  `if (removed.some(${runtimeTemplate.basicFunction("node", [
1545
1518
  'if (node.nodeName !== "SCRIPT") return false;',
1546
1519
  `${declare} type = (node.getAttribute("type") || "").trim().toLowerCase();`,
@@ -1564,11 +1537,9 @@ class HtmlGenerator extends Generator {
1564
1537
  ]),
1565
1538
  "}",
1566
1539
  `for (${mutable} i = 0; i < live.length; i++) document.head.removeChild(live[i]);`,
1567
- // Pair each retained element with its live node, scanning only
1568
- // forward: an authored element that has moved relative to the
1569
- // others finds no match from there on, and a reorder the delta
1570
- // cannot express falls back to the reload. Injected nodes simply
1571
- // 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.
1572
1543
  `${declare} liveByNew = [];`,
1573
1544
  `${mutable} searchFrom = 0;`,
1574
1545
  `for (${mutable} i = 0; i < newChildren.length; i++) {`,
@@ -1648,13 +1619,22 @@ class HtmlGenerator extends Generator {
1648
1619
  */
1649
1620
  generateError(error, module, generateContext) {
1650
1621
  if (generateContext.type === HTML_TYPE) {
1651
- // Strip `<`, `>`, `--` runs from `error.message` so it can't escape the comment.
1652
- 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
+ )
1653
1627
  .replace(/[<>]/g, "")
1654
1628
  .replace(/-{2,}/g, (m) => `${"-".repeat(m.length - 1)} `);
1655
1629
  return new RawSource(`<!-- webpack error: ${safe} -->`);
1656
1630
  }
1657
- return new RawSource(Generator.throwBuildErrorCode(error));
1631
+ return new RawSource(
1632
+ Generator.throwBuildErrorCode(
1633
+ error,
1634
+ undefined,
1635
+ generateContext.runtimeTemplate.requestShortener
1636
+ )
1637
+ );
1658
1638
  }
1659
1639
 
1660
1640
  /**
@@ -1664,10 +1644,9 @@ class HtmlGenerator extends Generator {
1664
1644
  */
1665
1645
  updateHash(hash, updateHashContext) {
1666
1646
  hash.update("html");
1667
- // Source-type set changes when html-type exposure flips; the HMR shim's
1668
- // `extracting` branch changes when the emit decision flips. They differ
1669
- // only for `"inline"` (exposes html, but does not emit), so hash both.
1670
- // 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.
1671
1650
  const extract = this._shouldExtract(updateHashContext.module);
1672
1651
  if (extract || this.options.extract === "inline") {
1673
1652
  hash.update("html-type");