@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
@@ -90,10 +90,9 @@ const STYLE_ATTR_URL_REGEXP = /url\(|src\(|image\(|image-set\(/i;
90
90
  // hold a `url(...)` FuncIRI. Most are plain colors/keywords (`#fff`, `red`).
91
91
  const FUNC_IRI_URL_REGEXP = /url\(/i;
92
92
 
93
- // Cheap pre-filter for `<iframe srcdoc>` markup: only spin up a nested HTML
94
- // module when the document can reference an asset — via any attribute (`src=`,
95
- // `href=`, `style=`, …), a CSS `url(...)`, or a CSS `@import`. Pure
96
- // formatting/text markup (`<p>hi</p>`) rewrites to itself, so skip it.
93
+ // Cheap pre-filter for `<iframe srcdoc>`: a nested HTML module is only worth
94
+ // building when the markup can reference an asset — any attribute, a CSS
95
+ // `url(...)` or an `@import`. Pure text markup rewrites to itself.
97
96
  const SRCDOC_ASSET_REGEXP = /[=]|url\(|@import/i;
98
97
 
99
98
  // A URL carrying its own scheme (`https:`, `data:`, …) ignores the document
@@ -370,10 +369,9 @@ const isLinkStylesheet = (attributes) => {
370
369
  */
371
370
  const dict = (...bags) => Object.assign(Object.create(null), ...bags);
372
371
 
373
- // Shared `SourceItem` singletons used by the built-in defaults —
374
- // keeping one instance per kind stabilizes V8's hidden classes across
375
- // lookups in the walk. `srcset` is its own type; the walk picks the
376
- // `parseSrcset` parser for it and otherwise treats it like `src`.
372
+ // One shared `SourceItem` per kind, so the walk's lookups stay on a single V8
373
+ // hidden class. `srcset` is its own type: the walk picks `parseSrcset` for it
374
+ // and otherwise treats it like `src`.
377
375
  /** @type {SourceItem} */
378
376
  const PLAIN_SRC = { type: "src", filter: undefined };
379
377
  /** @type {SourceItem} */
@@ -389,10 +387,9 @@ const LINK_HREF = {
389
387
  type: (attrs, css) => {
390
388
  if (isLinkModulePreload(attrs)) return "modulepreload";
391
389
  if (css && isLinkStylesheet(attrs)) return "stylesheet";
392
- // `rel="preload"/"prefetch"` with `as="script"` (or `as="style"` when
393
- // `experiments.css` is on) becomes a bundled, non-executing entry whose
394
- // `href` is rewritten to the built chunk; other `as` targets (image,
395
- // font, fetch, …) stay plain asset URLs.
390
+ // `rel="preload"/"prefetch"` with `as="script"` — or `as="style"` under
391
+ // `experiments.css` — becomes a non-executing entry pointing at the built
392
+ // chunk; every other `as` target stays a plain asset URL.
396
393
  const rel = getAttributeValue(attrs, "rel");
397
394
  if (rel) {
398
395
  const rels = rel.trim().toLowerCase().split(/\s+/);
@@ -446,11 +443,9 @@ const META_CONTENT = {
446
443
  filter: filterMetaContent
447
444
  };
448
445
 
449
- // Built-in lookup table, written directly in its final resolved shape:
450
- // `DEFAULT_SOURCES_BY_TAG[tag][attribute] = item`. No module-load
451
- // loop, no separate array representation — every parser created with
452
- // the default `sources` config just references this table and pays
453
- // zero per-parser work.
446
+ // Written in its final resolved shape, `[tag][attribute] = item`, rather than
447
+ // built from an array at module load: a parser on the default `sources` config
448
+ // references this table and pays nothing per instance.
454
449
  /** @type {Record<string, Record<string, SourceItem>>} */
455
450
  const DEFAULT_SOURCES_BY_TAG = dict({
456
451
  // Obsolete Java-applet element; `code`/`object` are single class/object URLs.
@@ -489,13 +484,14 @@ const DEFAULT_SOURCES_BY_TAG = dict({
489
484
  th: dict({ background: PLAIN_SRC }),
490
485
  track: dict({ src: PLAIN_SRC }),
491
486
  video: dict({ poster: PLAIN_SRC, src: PLAIN_SRC }),
492
- // SVG. Tag names match the tree builder's adjusted camelCase
493
- // (`feImage`/`textPath`/`linearGradient`/`radialGradient`). `href`/
494
- // `xlink:href` reference another element/resource; fragment-only `#id`
495
- // values are left untouched, so only external `file.svg#id` is rewritten.
496
- // `color-profile`'s `xlink:href` points at an external ICC profile file.
497
- // `cursor`/`font-face-uri` point at an external image/font file; `altGlyph`/
498
- // `glyphRef`/`tref` are legacy element references (removed in SVG 2).
487
+ // WHY: SVG. Tag names match the tree builder's adjusted camelCase
488
+ // (`feImage`/`textPath`/`linearGradient`/`radialGradient`). `href` and
489
+ // `xlink:href` reference another element or resource, and a fragment-only
490
+ // `#id` value is left untouched, so only an external `file.svg#id` is
491
+ // rewritten. `color-profile`'s `xlink:href` points at an external ICC profile
492
+ // file; `cursor` and `font-face-uri` at an external image or font file; and
493
+ // `altGlyph`, `glyphRef` and `tref` are legacy element references, removed in
494
+ // SVG 2.
499
495
  altGlyph: dict({ "xlink:href": PLAIN_SRC, href: PLAIN_SRC }),
500
496
  "color-profile": dict({ "xlink:href": PLAIN_SRC, href: PLAIN_SRC }),
501
497
  cursor: dict({ "xlink:href": PLAIN_SRC, href: PLAIN_SRC }),
@@ -515,11 +511,11 @@ const DEFAULT_SOURCES_BY_TAG = dict({
515
511
  // clip-path, …) are handled separately during the walk (`parseCssUrls`).
516
512
  });
517
513
 
518
- // SVG presentation attributes (`fill`, `stroke`, …) carry CSS `url(...)`
519
- // FuncIRIs; `parseCssUrls` extracts external refs as assets (internal
520
- // `url(#id)` is left untouched). They apply to every SVG-namespace element, so
521
- // the item is `namespace`-gated rather than placed in a tag bucket. The filter
522
- // is a cheap pre-check skipping the common plain values (`red`, `none`, `#fff`).
514
+ // WHY: SVG presentation attributes (`fill`, `stroke`, …) carry CSS `url(...)`
515
+ // FuncIRIs, whose external refs `parseCssUrls` extracts as assets, leaving an
516
+ // internal `url(#id)` untouched. They apply to every SVG-namespace element, so
517
+ // the item is `namespace`-gated rather than placed in a tag bucket, and the
518
+ // filter is a cheap pre-check skipping the common plain values (`red`, `none`).
523
519
  /** @type {SourceItem} */
524
520
  const SVG_CSS_URL = {
525
521
  type: "css-url",
@@ -527,21 +523,18 @@ const SVG_CSS_URL = {
527
523
  namespace: NS_SVG
528
524
  };
529
525
 
530
- // The global `style=""` attribute (a CSS declaration list), available on every
531
- // tag and even with `sources: false`. Like every `stylesheet-style*` source it
532
- // only emits when `experiments.css` is on (checked where the dependency is
533
- // created); the filter is a cheap pre-check skipping declarations without a
534
- // `url()`/`src()`/… .
526
+ // The global `style=""` attribute, available on every tag and even under
527
+ // `sources: false`. Like every `stylesheet-style*` source it only emits when
528
+ // `experiments.css` is on, checked where the dependency is created.
535
529
  /** @type {SourceItem} */
536
530
  const STYLE_ATTRIBUTE = {
537
531
  type: "stylesheet-style-attribute",
538
532
  filter: (attributes, value) => STYLE_ATTR_URL_REGEXP.test(value)
539
533
  };
540
534
 
541
- // Any-tag sources — applied to every element as a fallback and folded into
542
- // each tag bucket, so the walk resolves one object per element and reads one
543
- // property per attribute. `DEFAULT` (svg presentation + style) is active
544
- // unless `sources: false`; only the always-on style attribute survives `false`.
535
+ // Any-tag sources, folded into each tag bucket so the walk resolves one object
536
+ // per element and one property per attribute. `sources: false` leaves only the
537
+ // always-on style attribute.
545
538
  /** @type {Record<string, SourceItem>} */
546
539
  const DEFAULT_ANY_SOURCES = dict({ style: STYLE_ATTRIBUTE });
547
540
  for (const name of [
@@ -625,10 +618,9 @@ const styleContentFilter = (attrs) => {
625
618
  return t === "" || t === "text/css";
626
619
  };
627
620
 
628
- // Element-body sources, independent of the `sources` option (even `sources:
629
- // false`): inline `<script>` bodies are always processed; the `<style>` body
630
- // only emits when `experiments.css` is on (checked where the dependency is
631
- // created, like every `stylesheet-style*` source).
621
+ // Element-body sources, independent of the `sources` option: a `<script>` body
622
+ // is always processed, while a `<style>` body only emits when `experiments.css`
623
+ // is on, checked where the dependency is created.
632
624
  /** @type {Record<string, ContentSourceItem>} */
633
625
  const CONTENT_SOURCES = dict({
634
626
  script: { type: scriptContentType, filter: scriptContentFilter },
@@ -649,11 +641,9 @@ class HtmlParser extends Parser {
649
641
  this.template = options.template;
650
642
  /** @type {import("../../declarations/WebpackOptions").UrlHintRule[] | undefined} */
651
643
  this._urlHints = options.urlHints;
652
- // `as` selects the parse mode — the HTML analog of the CSS parser's `as`.
653
- // `"document"` (default) parses a full page; any other value is the
654
- // context element whose inner HTML the source is parsed as (a fragment),
655
- // so context-sensitive tags (`<tr>`, `<td>`, `<option>`, …) in a partial
656
- // are kept, not dropped. `"template"` is the neutral generic fragment.
644
+ // `as` selects the parse mode: `"document"` parses a full page, any other
645
+ // value names the context element whose inner HTML this is, so that a
646
+ // partial's `<tr>`, `<td>` or `<option>` is kept rather than dropped.
657
647
  /** @type {string | undefined} */
658
648
  this.fragmentContext =
659
649
  options.as === undefined || options.as === "document"
@@ -673,13 +663,9 @@ class HtmlParser extends Parser {
673
663
  return;
674
664
  }
675
665
 
676
- // User array — `"..."` anywhere opts the per-tag defaults in as the
677
- // base; the built-in any-tag sources (svg presentation + style) are
678
- // always present. A user entry with no `tag` is an any-tag source (e.g.
679
- // `{ attribute: "data-style", type: "stylesheet-style-attribute" }`).
680
- // User entries override regardless of position. `dict()` keeps every
681
- // table null-prototype (see its doc), and per-tag writes rebuild the
682
- // bucket so the aliased default buckets stay intact.
666
+ // `"..."` anywhere opts the per-tag defaults in as the base, and a user
667
+ // entry with no `tag` is an any-tag source; user entries override wherever
668
+ // they sit. Per-tag writes rebuild the bucket, so the defaults stay intact.
683
669
  /** @type {SourceTable} */
684
670
  const byTag = sources.includes("...")
685
671
  ? dict(DEFAULT_SOURCES_BY_TAG)
@@ -804,14 +790,9 @@ class HtmlParser extends Parser {
804
790
  const css = Boolean(compilation.options.experiments.css);
805
791
  const urlHints = this._urlHints;
806
792
 
807
- // Stable, per-HTML-module prefix used when generating entry names for
808
- // script src / modulepreload references so they don't collide across
809
- // HTML modules in the same compilation. We hash the module's resource
810
- // path (a plain absolute path) — going through `contextify` against
811
- // the compilation root keeps the hash machine-stable for the same
812
- // project layout. Note: `module.identifier()` returns `html|<path>`
813
- // for HTML modules, which doesn't start with `/`, so contextify would
814
- // leave it absolute. `module.resource` is the bare path.
793
+ // Per-module prefix keeping generated entry names from colliding across the
794
+ // HTML modules of one compilation. It hashes `module.resource` rather than
795
+ // `identifier()`, whose `html|` prefix `contextify` would leave absolute.
815
796
  /** @type {string} */
816
797
  const resource =
817
798
  /** @type {EXPECTED_ANY} */ (module).resource || module.identifier();
@@ -820,11 +801,9 @@ class HtmlParser extends Parser {
820
801
  .digest("hex")
821
802
  .slice(0, 8);
822
803
 
823
- // `output.html` head injection: facts are collected during the walk and
824
- // become presentational dependencies afterwards — no later asset pass has
825
- // to re-parse the page. `data:` documents are skipped: synthetic entry
826
- // wrappers already carry the tags and iframe srcdoc pages must stay
827
- // untouched.
804
+ // `output.html` head injection collects facts during the walk and turns
805
+ // them into presentational dependencies after, so no later pass re-parses
806
+ // the page. `data:` documents are skipped — they already carry the tags.
828
807
  const htmlOutputOptions =
829
808
  compilation.options && compilation.options.output
830
809
  ? compilation.options.output.html
@@ -846,10 +825,9 @@ class HtmlParser extends Parser {
846
825
  let inHead = false;
847
826
  // `<template>` contents are inert
848
827
  let headTemplateDepth = 0;
849
- // Depth of open `<template>` elements anywhere in the tree. Template
850
- // content is an inert, separate fragment per spec, so a `<base>` inside
851
- // it must NOT set the document base (`headTemplateDepth` only covers
852
- // templates seen while in `<head>`, so it can't guard body templates).
828
+ // Depth of open `<template>` elements anywhere in the tree: their content
829
+ // is an inert fragment, so a `<base>` inside one must not set the document
830
+ // base. `headTemplateDepth` covers only `<head>`, so it cannot guard this.
853
831
  let templateDepth = 0;
854
832
  let headHasTitle = false;
855
833
  let headHasBase = false;
@@ -857,17 +835,14 @@ class HtmlParser extends Parser {
857
835
  /** @type {Set<string> | undefined} */
858
836
  let headMetaNames;
859
837
 
860
- // Script src / modulepreload references are collected per-type
861
- // during the walk; HtmlModulesPlugin later turns them into real
862
- // entries. `script` and `script-module` entries are chained via a
863
- // leader-only dependOn so they share a runtime.
864
- // `<link rel="modulepreload">` entries are kept independent — they
865
- // must preload without running, so they can never become a runtime
866
- // leader that other entries would import.
838
+ // Collected per type during the walk; HtmlModulesPlugin turns them into
839
+ // entries. `script` and `script-module` chain through a leader-only
840
+ // dependOn; modulepreload stays independent, as it must not run.
867
841
  /**
868
842
  * @typedef {object} HtmlEntryInfo
869
843
  * @property {string} request
870
844
  * @property {string} entryName
845
+ * @property {number} index position in the document, across all groups — the order the emitted files are named in
871
846
  * @property {"script" | "script-module" | "modulepreload" | "stylesheet" | "html" | "preload" | "prefetch"} type
872
847
  * @property {boolean=} css entry emits a CSS chunk (`<link rel="preload" as="style">`), so it needs the CSS filename template
873
848
  */
@@ -891,28 +866,26 @@ class HtmlParser extends Parser {
891
866
  /** @type {HtmlEntryInfo[]} */
892
867
  const prefetchEntries = [];
893
868
 
894
- // Offset of the first classic blocking script tag; injected stylesheet
895
- // `<link>`s stay ahead of it. `defer`/`async`/module scripts don't
896
- // anchor — they execute after parsing (and after pending stylesheets),
897
- // so CSS may follow their tags (the order Vite emits).
869
+ // Offset of the first classic blocking script tag, which injected stylesheet
870
+ // `<link>`s stay ahead of. `defer`/`async`/module scripts do not anchor: they
871
+ // run after parsing and after pending stylesheets.
898
872
  let firstBlockingScriptStart = -1;
899
873
 
900
874
  let nextEntryIndex = 0;
901
875
 
902
- // `<base href>` resolves the relative URLs that follow it. A relative base
903
- // (`./assets/`) rewrites them into a subdirectory — still bundled; a
904
- // root-relative or absolute base (`/`, `https://cdn/`) points them outside
905
- // the build, so those URLs are left untouched. Resolved in the walk below
906
- // from the first `<base href>` seen (`documentBase` undefined until then).
876
+ // WHY: `<base href>` resolves the relative URLs that follow it. A relative base
877
+ // (`./assets/`) rewrites them into a subdirectory and they stay bundled; a
878
+ // root-relative or absolute one (`/`, `https://cdn/`) points outside the
879
+ // build, so those URLs are left untouched. Resolved in the walk below from
880
+ // the first `<base href>` seen, `documentBase` being undefined until then.
907
881
  /** @type {string | undefined} */
908
882
  let documentBase;
909
883
  /** @type {string | undefined} */
910
884
  let baseDir;
911
885
  let baseIsExternal = false;
912
- // Prepended to the emitted URLs' auto-public-path undo path so the base
913
- // doesn't misdirect them: the browser resolves rewritten (relative)
914
- // output URLs against the base dir, so one `../` per base segment cancels
915
- // it. Undefined for absolute publicPath (no undo path is emitted).
886
+ // Prepended to the emitted URLs' auto-public-path undo path: the browser
887
+ // resolves them against the base dir, so one `../` per base segment cancels
888
+ // it. Undefined for an absolute publicPath, which emits no undo path.
916
889
  /** @type {string | undefined} */
917
890
  let baseUrlPrefix;
918
891
 
@@ -1016,10 +989,9 @@ class HtmlParser extends Parser {
1016
989
  baseIsExternal = true;
1017
990
  return;
1018
991
  }
1019
- // Normalize the base path into its descending directory segments,
1020
- // resolving `.`/`..` like the URL spec. The final segment is the
1021
- // referenced file (dropped) unless the href ends with `/` or a
1022
- // dot-segment; `up` counts `..`s that climb above the document dir.
992
+ // Normalize the base path into descending directory segments, resolving
993
+ // `.`/`..` as the URL spec does. The final segment names a file and is
994
+ // dropped; `up` counts the `..`s climbing above the document dir.
1023
995
  const parts = documentBase.split("/");
1024
996
  /** @type {string[]} */
1025
997
  const dirs = [];
@@ -1069,9 +1041,8 @@ class HtmlParser extends Parser {
1069
1041
  };
1070
1042
 
1071
1043
  // TODO implement full HTML parser (WASM)
1072
- // The walker descends into children (and `<template>` content) itself;
1073
- // the Element `exit` clears a pending `webpackIgnore` once an element's
1074
- // children are done (the old `walkChildren` behaviour).
1044
+ // The walker descends into children and `<template>` content itself, and the
1045
+ // Element `exit` clears a pending `webpackIgnore` once they are done.
1075
1046
  new SourceProcessor()
1076
1047
  .use({
1077
1048
  [NodeType.Comment]: (path) => {
@@ -1219,9 +1190,8 @@ class HtmlParser extends Parser {
1219
1190
  pendingWebpackIgnore = undefined;
1220
1191
  pendingWebpackInline = undefined;
1221
1192
 
1222
- // `<head>` anchors are collected for every page — they place
1223
- // `inject: "head"` siblings and resource hints; the
1224
- // title/meta/base facts only when configured. Structural, so it
1193
+ // `<head>` anchors are collected for every page, since they place
1194
+ // `inject: "head"` siblings and resource hints. Structural, so this
1225
1195
  // runs even for `webpackIgnore`d elements.
1226
1196
  {
1227
1197
  const name = path.tagName();
@@ -1446,11 +1416,9 @@ class HtmlParser extends Parser {
1446
1416
  module.addCodeGenerationDependency(dep);
1447
1417
  break;
1448
1418
  }
1449
- // `<iframe srcdoc>`: an entity-encoded HTML document. Feed the
1450
- // decoded markup back through the HTML pipeline as a nested
1451
- // `data:text/html` module. Per spec the value is a full document
1452
- // whose URL is `about:srcdoc`, so its base URL is inherited from
1453
- // this document — asset URLs resolve against this file's context.
1419
+ // `<iframe srcdoc>` is an entity-encoded document, fed back through
1420
+ // the pipeline as a nested `data:text/html` module. Its URL is
1421
+ // `about:srcdoc`, so asset URLs resolve against this file.
1454
1422
  case "srcdoc": {
1455
1423
  const htmlText = decodeEntities(value, true);
1456
1424
  // Only spin up a nested module when there is markup that can
@@ -1478,7 +1446,8 @@ class HtmlParser extends Parser {
1478
1446
  const scriptType =
1479
1447
  /** @type {"script" | "script-module"} */ (type);
1480
1448
  const request = dataUri("text/javascript", value);
1481
- const entryName = `__html_${moduleHash}_${nextEntryIndex++}`;
1449
+ const index = nextEntryIndex++;
1450
+ const entryName = `__html_${moduleHash}_${index}`;
1482
1451
  const dep = new HtmlInlineScriptDependency(
1483
1452
  request,
1484
1453
  nameEnd,
@@ -1501,6 +1470,7 @@ class HtmlParser extends Parser {
1501
1470
  ).push({
1502
1471
  request,
1503
1472
  entryName,
1473
+ index,
1504
1474
  type: scriptType
1505
1475
  });
1506
1476
  break;
@@ -1576,12 +1546,12 @@ class HtmlParser extends Parser {
1576
1546
  }
1577
1547
  const s = start + (map ? map[us] : us);
1578
1548
  const e = start + (map ? map[ue] : ue);
1579
- // `html` links the URL as its own emitted page: the same
1580
- // `HtmlEntryDependency` as `<script src>` / `<link>`, but the `html`
1581
- // kind rewrites to the page's filename and emits no sibling tags.
1582
- // Recorded as an independent entry (no `dependOn`), like an entry point.
1549
+ // `html` links the URL as its own emitted page: the same dependency
1550
+ // as `<script src>`, but rewriting to the page's filename and
1551
+ // emitting no siblings. Independent, like an entry point.
1583
1552
  if (type === "html") {
1584
- const entryName = `__html_${moduleHash}_${nextEntryIndex++}`;
1553
+ const index = nextEntryIndex++;
1554
+ const entryName = `__html_${moduleHash}_${index}`;
1585
1555
  const dep = new HtmlEntryDependency(
1586
1556
  request,
1587
1557
  [s, e],
@@ -1591,23 +1561,22 @@ class HtmlParser extends Parser {
1591
1561
  );
1592
1562
  setLoc(dep, s, e);
1593
1563
  module.addPresentationalDependency(dep);
1594
- htmlLinkEntries.push({ request, entryName, type });
1564
+ htmlLinkEntries.push({ request, entryName, index, type });
1595
1565
  continue;
1596
1566
  }
1597
- // `rel="preload"/"prefetch"` of a bundled resource: an
1598
- // independent, non-executing entry whose `href` is rewritten to
1599
- // the built chunk's URL (CSS for `as="style"`, JS otherwise). No
1600
- // sibling tags — a resource hint references exactly one URL.
1567
+ // `rel="preload"/"prefetch"` of a bundled resource: an independent,
1568
+ // non-executing entry rewritten to the built chunk's URL. No
1569
+ // siblings — a resource hint references exactly one URL.
1601
1570
  if (type === "preload" || type === "prefetch") {
1602
1571
  const as = getAttributeValue(getAttributesMap(), "as");
1603
1572
  const asStyle = as
1604
1573
  ? as.trim().toLowerCase() === "style"
1605
1574
  : false;
1606
- const entryName = `__html_${moduleHash}_${nextEntryIndex++}`;
1607
- // Tag metadata so the template can mirror `crossorigin`/
1608
- // `integrity` onto a native `preload` `<link>` (integrity-
1609
- // eligible per the SRI spec). `prefetch` gets none — the spec
1610
- // doesn't list it — so its `integrity` is left uncaptured.
1575
+ const index = nextEntryIndex++;
1576
+ const entryName = `__html_${moduleHash}_${index}`;
1577
+ // Tag metadata letting the template mirror `crossorigin` and
1578
+ // `integrity` onto a native `preload` `<link>`. `prefetch` is not
1579
+ // integrity-eligible per the SRI spec, so its is left uncaptured.
1611
1580
  const isNativeLink = elementName === "link";
1612
1581
  const dep = new HtmlEntryDependency(
1613
1582
  request,
@@ -1635,6 +1604,7 @@ class HtmlParser extends Parser {
1635
1604
  ).push({
1636
1605
  request,
1637
1606
  entryName,
1607
+ index,
1638
1608
  type,
1639
1609
  css: asStyle
1640
1610
  });
@@ -1649,7 +1619,8 @@ class HtmlParser extends Parser {
1649
1619
  type === "modulepreload" ||
1650
1620
  type === "stylesheet"
1651
1621
  ) {
1652
- const entryName = `__html_${moduleHash}_${nextEntryIndex++}`;
1622
+ const index = nextEntryIndex++;
1623
+ const entryName = `__html_${moduleHash}_${index}`;
1653
1624
  const willBeModuleScript =
1654
1625
  type === "script-module" ||
1655
1626
  (outputModule && type === "script");
@@ -1693,13 +1664,9 @@ class HtmlParser extends Parser {
1693
1664
  }
1694
1665
  }
1695
1666
  }
1696
- // Blocking-ness of the tag as *emitted*:
1697
- // `reconcileScriptTypeAttr` upgrades every script entry
1698
- // to `type="module"` under `output.module` and strips an
1699
- // authored `type="module"` otherwise — so only non-module
1700
- // output without `defer`/`async` blocks. Non-native
1701
- // elements anchor conservatively (their synthesized
1702
- // siblings may be plain blocking `<script>`s).
1667
+ // Blocking-ness of the tag as emitted, not as authored:
1668
+ // `reconcileScriptTypeAttr` decides the final `type`, so only
1669
+ // non-module output without `defer`/`async` blocks.
1703
1670
  if (
1704
1671
  firstBlockingScriptStart === -1 &&
1705
1672
  (type === "script" || type === "script-module") &&
@@ -1710,11 +1677,9 @@ class HtmlParser extends Parser {
1710
1677
  ) {
1711
1678
  firstBlockingScriptStart = elementStart;
1712
1679
  }
1713
- // Sibling-clone attribute edits, captured from the parsed
1714
- // attributes (offsets relative to the tag) so the template
1715
- // needn't re-parse the tag text: `integrity` is dropped
1716
- // (content-specific) and `script-module` clones are forced
1717
- // to `type="module"` (its value range, else inserted).
1680
+ // Sibling-clone attribute edits, captured as offsets relative to
1681
+ // the tag so the template need not re-parse it: `integrity` is
1682
+ // content-specific and dropped, `script-module` forces `type`.
1718
1683
  const integrityRange =
1719
1684
  elementStart >= 0 && elementName === nativeTag
1720
1685
  ? captureIntegrityRange(path, source, elementStart)
@@ -1777,7 +1742,7 @@ class HtmlParser extends Parser {
1777
1742
  : type === "stylesheet"
1778
1743
  ? stylesheetEntries
1779
1744
  : modulePreloadEntries
1780
- ).push({ request, entryName, type });
1745
+ ).push({ request, entryName, index, type });
1781
1746
  } else {
1782
1747
  const dep = new HtmlSourceDependency(request, [s, e]);
1783
1748
  ResourceHintPlugin.applyDefaults(
@@ -1816,10 +1781,9 @@ class HtmlParser extends Parser {
1816
1781
  }
1817
1782
  }
1818
1783
  })
1819
- // Skip AST output this walk never reads: `text` (script/style bodies are
1820
- // read by offset via `contentEnd`) and `doctype` — unless head injection
1821
- // needs the doctype as an insertion anchor; keep `comments` for
1822
- // magic comments (`webpackIgnore`).
1784
+ // Skip AST output this walk never reads: `text`, since script and style
1785
+ // bodies are read by offset, and `doctype` unless head injection needs it
1786
+ // as an anchor. `comments` stays, for `webpackIgnore`.
1823
1787
  .process(source, {
1824
1788
  fragmentContext: this.fragmentContext,
1825
1789
  skip: { text: true, doctype: headOptions === undefined }
@@ -1874,13 +1838,12 @@ class HtmlParser extends Parser {
1874
1838
  const buildInfo = /** @type {HtmlModuleBuildInfo} */ (module.buildInfo);
1875
1839
  buildInfo.strict = true;
1876
1840
  if (baseUrlPrefix !== undefined) buildInfo.baseUrlPrefix = baseUrlPrefix;
1877
- // Hand off the collected entries to HtmlModulesPlugin; it creates the
1878
- // real compilation entries during the finishMake hook. The `script`
1879
- // and `script-module` groups are chained via a leader-only dependOn
1880
- // so they share a runtime; `modulepreload` and `stylesheet` entries
1881
- // are emitted as independent entries since `<link rel=modulepreload>`
1882
- // must preload without running and stylesheets have no runtime. `html`
1883
- // links are independent page entries too.
1841
+ // WHY: hand the collected entries to HtmlModulesPlugin, which creates the
1842
+ // real compilation entries during the finishMake hook. The `script` and
1843
+ // `script-module` groups chain through a leader-only `dependOn` so they share
1844
+ // a runtime, while `modulepreload` and `stylesheet` entries are independent:
1845
+ // `<link rel=modulepreload>` must preload without running, and a stylesheet
1846
+ // has no runtime. `html` links are independent page entries too.
1884
1847
  if (
1885
1848
  scriptEntries.length > 0 ||
1886
1849
  scriptModuleEntries.length > 0 ||
@@ -0,0 +1,107 @@
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 { CSS_TYPE } = require("../ModuleSourceTypeConstants");
9
+
10
+ /** @import { CssProcessOptions } from "../css/syntax" */
11
+ /** @import { EmbeddedSourceRenderer } from "./syntax" */
12
+
13
+ /**
14
+ * What this minifies inline CSS with: the CSS minifier's own options, so an
15
+ * inline declaration is held to the rules a `.css` asset is.
16
+ * @typedef {Pick<CssProcessOptions, "environment" | "convertLengthUnits" | "rewriteCustomProperties" | "transforms" | "unusedSymbols" | "pseudoClasses">} BuiltinEmbeddedRendererOptions
17
+ */
18
+
19
+ // Both are loaded on first render rather than at module load: a document that
20
+ // embeds no CSS and no JSON pays for neither.
21
+ /** @type {typeof import("../css/syntax") | undefined} */
22
+ let _cssSyntax;
23
+ /** @type {typeof import("./syntax") | undefined} */
24
+ let _htmlSyntax;
25
+
26
+ /**
27
+ * Strip the whitespace between a JSON body's tokens, every literal copied byte
28
+ * for byte. Re-serializing would round numbers, drop a duplicate key and rewrite
29
+ * the escapes that keep a string from closing the `<script>` early.
30
+ * @param {string} json a `<script>` body
31
+ * @returns {string} the stripped body, or the body as written where it is not JSON
32
+ */
33
+ const stripJsonWhitespace = (json) => {
34
+ try {
35
+ JSON.parse(json);
36
+ } catch (_err) {
37
+ // Not JSON after all (a template, a placeholder) — not ours to touch.
38
+ return json;
39
+ }
40
+ let out = "";
41
+ let inString = false;
42
+ let escaped = false;
43
+ for (let i = 0; i < json.length; i++) {
44
+ const c = json.charCodeAt(i);
45
+ if (inString) {
46
+ out += json[i];
47
+ if (escaped) escaped = false;
48
+ else if (c === 0x5c) escaped = true;
49
+ else if (c === 0x22) inString = false;
50
+ continue;
51
+ }
52
+ if (c === 0x22) {
53
+ inString = true;
54
+ out += json[i];
55
+ continue;
56
+ }
57
+ // JSON whitespace (RFC 8259): tab, LF, CR, space.
58
+ if (c === 0x09 || c === 0x0a || c === 0x0d || c === 0x20) continue;
59
+ out += json[i];
60
+ }
61
+ return out;
62
+ };
63
+
64
+ /**
65
+ * The renderer webpack ships for what a document embeds: its own CSS minifier
66
+ * for a `<style>` or `style=""` and `stripJsonWhitespace` for JSON, declining
67
+ * every other language. A caller passes it where it has no renderer of its own,
68
+ * or behind one for the languages that one declines — the HTML printer minifies
69
+ * none of this itself.
70
+ * @param {BuiltinEmbeddedRendererOptions=} options the CSS minifier's options, so an inline declaration is minified as the `.css` assets are
71
+ * @returns {EmbeddedSourceRenderer} the renderer
72
+ */
73
+ const builtinEmbeddedRenderer = (options = {}) => {
74
+ const { BLOCK_CONTENTS, JSON_TYPE } =
75
+ _htmlSyntax || (_htmlSyntax = require("./syntax"));
76
+ const sheet = { mode: /** @type {"minify"} */ ("minify"), ...options };
77
+ const block = { ...sheet, as: BLOCK_CONTENTS };
78
+ // A `style=""` repeats across a document far more often than it varies.
79
+ /** @type {Map<string, string>} */
80
+ const blocks = new Map();
81
+ return (source, info) => {
82
+ if (info.type === JSON_TYPE) return stripJsonWhitespace(source);
83
+ if (info.type !== CSS_TYPE) return undefined;
84
+ const isBlock = info.as === BLOCK_CONTENTS;
85
+ if (isBlock) {
86
+ const memoized = blocks.get(source);
87
+ if (memoized !== undefined) return memoized;
88
+ }
89
+ const { SourceProcessor } =
90
+ _cssSyntax || (_cssSyntax = require("../css/syntax"));
91
+ let code;
92
+ try {
93
+ code = new SourceProcessor().process(
94
+ source,
95
+ isBlock ? block : sheet
96
+ ).code;
97
+ } catch (_err) {
98
+ // Text the minifier cannot read is left as written, by declining.
99
+ return undefined;
100
+ }
101
+ if (isBlock) blocks.set(source, code);
102
+ return code;
103
+ };
104
+ };
105
+
106
+ module.exports.builtinEmbeddedRenderer = builtinEmbeddedRenderer;
107
+ module.exports.stripJsonWhitespace = stripJsonWhitespace;