@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
@@ -7,6 +7,7 @@
7
7
  const {
8
8
  CSS_IMPORT_TYPE,
9
9
  CSS_TYPE,
10
+ HTML_TYPE,
10
11
  JAVASCRIPT_TYPE
11
12
  } = require("../ModuleSourceTypeConstants");
12
13
  const ResourceHintPlugin = require("../prefetch/ResourceHintPlugin");
@@ -497,11 +498,12 @@ const cloneTagWithUrl = (
497
498
  return isLink ? body : `${body}</script>`;
498
499
  };
499
500
 
500
- // ES5 `<link rel="modulepreload">` polyfill (Safari <17, Firefox <115, …):
501
- // on browsers without native support, fetch each modulepreload target with the
502
- // tag's own credentials/integrity so the pending module import reuses it. The
503
- // `.ep` guard makes it idempotent, and the observer catches any later-inserted
504
- // links. Emitted only when the target environment lacks native support.
501
+ // WHY: an ES5 `<link rel="modulepreload">` polyfill (Safari <17, Firefox <115,
502
+ // …). On a browser without native support, each modulepreload target is fetched
503
+ // with the tag's own credentials and integrity, so the pending module import
504
+ // reuses it. The `.ep` guard makes that idempotent and the observer catches any
505
+ // later-inserted link. Emitted only where the target environment lacks native
506
+ // support.
505
507
  const MODULEPRELOAD_POLYFILL = [
506
508
  "(function(){",
507
509
  'var s=document.createElement("link").relList;',
@@ -587,6 +589,47 @@ const buildLinkTag = (rel, attrs) =>
587
589
  : ""
588
590
  }>`;
589
591
 
592
+ /**
593
+ * The chunks a hint means when it names a page: a page loads no JavaScript of
594
+ * its own, so the hint follows the entries the parser extracted from it.
595
+ * @param {import("../Compilation")} compilation compilation
596
+ * @param {Chunk} chunk chunk a hint resolved to
597
+ * @returns {Chunk[]} the chunks to hint at
598
+ */
599
+ const resolvePageChunk = (compilation, chunk) => {
600
+ const { chunkGraph } = compilation;
601
+ const modules = chunkGraph.getChunkModulesIterableBySourceType(
602
+ chunk,
603
+ HTML_TYPE
604
+ );
605
+ // A page with a JavaScript side of its own (an `output.library` entry) is
606
+ // hinted too — `chunkHasJs` can't say so, it holds for any runtime chunk.
607
+ const javascript = chunkGraph.getChunkModulesIterableBySourceType(
608
+ chunk,
609
+ JAVASCRIPT_TYPE
610
+ );
611
+ /** @type {Chunk[]} */
612
+ const chunks = javascript === undefined ? [] : [chunk];
613
+ // A chunk carrying no page stands for itself; a page stands for the entries
614
+ // extracted from it, so one that extracted nothing hints nothing.
615
+ if (modules === undefined) return chunks.length === 0 ? [chunk] : chunks;
616
+ for (const module of modules) {
617
+ const { htmlEntries } =
618
+ /** @type {import("../html/HtmlModule").HtmlModuleBuildInfo} */ (
619
+ module.buildInfo
620
+ ) || {};
621
+ if (!htmlEntries) continue;
622
+ for (const group of Object.values(htmlEntries)) {
623
+ for (const { entryName } of group) {
624
+ const entrypoint = compilation.entrypoints.get(entryName);
625
+ const entryChunk = entrypoint && entrypoint.getEntrypointChunk();
626
+ if (entryChunk) chunks.push(entryChunk);
627
+ }
628
+ }
629
+ }
630
+ return chunks;
631
+ };
632
+
590
633
  /**
591
634
  * Resolve one `output.html.resourceHints` descriptor to zero or more `<link>`
592
635
  * tags. A `chunk`/`entry` reference becomes the emitted chunk URL (a sentinel
@@ -633,6 +676,14 @@ const resolveResourceHint = (desc, ctx) => {
633
676
  } else {
634
677
  return [];
635
678
  }
679
+ /** @type {Chunk[]} */
680
+ const hinted = [];
681
+ for (const chunk of chunks) {
682
+ for (const resolved of resolvePageChunk(ctx.compilation, chunk)) {
683
+ hinted.push(resolved);
684
+ }
685
+ }
686
+ chunks = hinted;
636
687
  const kind = desc.as === "style" ? "css" : "javascript";
637
688
  const as = desc.as || (rel === "modulepreload" ? undefined : "script");
638
689
  // A hint targeting another chunk must match how that chunk is fetched, so
@@ -687,10 +738,9 @@ HtmlEntryDependency.Template = class HtmlEntryDependencyTemplate extends (
687
738
  const dep = /** @type {HtmlEntryDependency} */ (dependency);
688
739
  const compilation = runtimeTemplate.compilation;
689
740
 
690
- // A `type: "html"` link points at another emitted page, not a JS/CSS
691
- // chunk: rewrite the attribute to that page's filename (resolved by
692
- // HtmlModulesPlugin once it's built) and emit no sibling tags — a page
693
- // link loads only itself.
741
+ // A `type: "html"` link points at another emitted page rather than a chunk,
742
+ // so rewrite the attribute to that page's filename and emit no siblings:
743
+ // a page link loads only itself.
694
744
  if (dep.elementKind === "html") {
695
745
  source.replace(
696
746
  dep.range[0],
@@ -714,21 +764,17 @@ HtmlEntryDependency.Template = class HtmlEntryDependencyTemplate extends (
714
764
  const orderedChunks = getEntrypointChunksInLoadOrder(entrypoint);
715
765
  const entryChunk = orderedChunks[orderedChunks.length - 1];
716
766
 
717
- // `crossorigin` mirrors `output.crossOriginLoading` onto every injected
718
- // tag. Empty when the option is off or the originating tag already set
719
- // `crossorigin` (author value wins, flagged at parse time). Mirrors
720
- // webpack's runtime, which sets `crossOrigin` on chunk-loading scripts,
721
- // and matches Vite, which emits it on every injected script/stylesheet.
767
+ // Mirrors `output.crossOriginLoading` onto every injected tag, as webpack's
768
+ // runtime does for chunk-loading scripts. Empty when the option is off or
769
+ // the originating tag set `crossorigin` itself, since the author wins.
722
770
  const crossOrigin =
723
771
  crossOriginLoading && !dep.hasOwnCrossOrigin
724
772
  ? ` crossorigin="${crossOriginLoading}"`
725
773
  : "";
726
774
 
727
- // Per-chunk SRI: emit an `integrity` sentinel resolved late (after the
728
- // chunks' final bytes exist) by `resolveChunkIntegritySentinels`. Tags are
729
- // generated per HTML module, but one module can back pages with different
730
- // `integrity` options, so sentinels are emitted whenever any page wants SRI
731
- // and each page then resolves or strips them on emit.
775
+ // Per-chunk SRI emits an `integrity` sentinel resolved once the chunks'
776
+ // final bytes exist. One module can back pages with different `integrity`
777
+ // options, so every page emits them and strips its own on emit.
732
778
  const htmlOption = compilation.outputOptions.html;
733
779
  const integrityOn = getHtmlGenerator().hasIntegritySentinels(compilation);
734
780
  const inject =
@@ -898,11 +944,9 @@ HtmlEntryDependency.Template = class HtmlEntryDependencyTemplate extends (
898
944
  ? ` integrity="${getHtmlGenerator().makeChunkIntegritySentinel(chunk, kind)}"`
899
945
  : "";
900
946
  if (kind === "css") {
901
- // A CSS chunk is always loaded via `<link rel="stylesheet">`.
902
- // Clone only when the entry tag is itself a native `<link
903
- // rel="stylesheet">` (so attributes like `media` carry over);
904
- // a `<script>` entry that imported CSS, or a custom element,
905
- // gets a freshly synthesized `<link>`.
947
+ // A CSS chunk always loads through `<link rel="stylesheet">`. Clone
948
+ // only when the entry tag is itself one, so `media` carries over;
949
+ // anything else gets a freshly synthesized `<link>`.
906
950
  if (isStylesheet && tagIsNative) {
907
951
  return cloneTagWithUrl(
908
952
  originalTag,
@@ -954,10 +998,9 @@ HtmlEntryDependency.Template = class HtmlEntryDependencyTemplate extends (
954
998
  // Parser-derived anchor (a source text scan would match `</head>` inside
955
999
  // comments or raw text).
956
1000
  const headClose = inject === "head" ? dep.headAnchor : -1;
957
- // When the entry tag is already inside <head> (tagStart < headClose),
958
- // inserting siblings at headClose would place them after the entry,
959
- // reversing runtime-before-entry execution order for deferred scripts.
960
- // Insert before the entry tag instead so the load order is preserved.
1001
+ // With the entry tag already inside `<head>`, inserting at `headClose`
1002
+ // would place siblings after it and reverse runtime-before-entry order
1003
+ // for deferred scripts. Insert before the entry tag instead.
961
1004
  const headAt =
962
1005
  headClose < 0
963
1006
  ? -1
@@ -968,29 +1011,24 @@ HtmlEntryDependency.Template = class HtmlEntryDependencyTemplate extends (
968
1011
  let cssHtml = "";
969
1012
  let cssAt = -1;
970
1013
  if (isStylesheet) {
971
- // `<link rel="stylesheet">` entries are CSS, but a shared/runtime
972
- // JS-only chunk (e.g. `optimization.runtimeChunk`) can still sit in
973
- // the entrypoint — only clone the `<link>` for siblings that actually
974
- // produce a `.css` asset (mirrors the JS branch below), otherwise the
975
- // link points at a non-existent `.css` file (a 404, or an empty
976
- // `<style>` when inlined). Attributes like `media` still carry over.
1014
+ // WHY: a `<link rel="stylesheet">` entry is CSS, but a shared or runtime
1015
+ // JS-only chunk — `optimization.runtimeChunk`, say — can still sit in the
1016
+ // entrypoint, so the `<link>` is cloned only for siblings that actually
1017
+ // produce a `.css` asset, mirroring the JS branch below. Otherwise it
1018
+ // points at a `.css` file that does not exist: a 404, or an empty
1019
+ // `<style>` when inlined. Attributes such as `media` still carry over.
977
1020
  for (let i = 0; i < orderedChunks.length - 1; i++) {
978
1021
  if (chunkHasCss(orderedChunks[i], chunkGraph)) {
979
1022
  siblings.push(buildSibling(orderedChunks[i], "css"));
980
1023
  }
981
1024
  }
982
1025
  } else {
983
- // CSS chunks are emitted before JS chunks so the cascade is set
984
- // up before any script runs. Within CSS the order needs to match
985
- // the source's import order — `entrypoint.chunks` alone doesn't
986
- // give us that for arbitrary splitChunks layouts (splitChunks
987
- // inserts each new chunk before the entry chunk via
988
- // `insertChunk(_, before)`, so split CSS siblings end up in
989
- // *reverse* of the order they were processed — exactly the
990
- // html-webpack-plugin#1838 / mini-css-extract#959 symptom). We
991
- // re-derive the order from the entrypoint's module post-order
992
- // index, which mirrors the dependency walk and so reflects the
993
- // import order.
1026
+ // WHY: splitChunks inserts each new chunk before the entry chunk, so
1027
+ // `entrypoint.chunks` hands back split CSS siblings in reverse of the
1028
+ // order they were processed — the html-webpack-plugin#1838 and
1029
+ // mini-css-extract#959 symptom. The order is re-derived from the
1030
+ // entrypoint's module post-order index, which follows the dependency
1031
+ // walk and so the source's import order.
994
1032
  /** @type {{ chunk: Chunk, index: number, key: string }[]} */
995
1033
  const cssChunkOrder = [];
996
1034
  /** @type {Chunk[]} */
@@ -1010,18 +1048,14 @@ HtmlEntryDependency.Template = class HtmlEntryDependencyTemplate extends (
1010
1048
  key: cssChunkSortKey(chunk)
1011
1049
  });
1012
1050
  }
1013
- // Anything that isn't CSS-only stays on the JS lane, in the
1014
- // `orderedChunks` order — that preserves the runtime-first /
1015
- // vendor-before-entry invariant of `getEntrypointChunksInLoadOrder`.
1016
- // Chunks that produce no `.js` and no `.css` (e.g. wasm-only
1017
- // or asset-only) still get a `<script>` clone here so we
1018
- // keep prior behavior for users who relied on it.
1051
+ // Anything not CSS-only stays on the JS lane in `orderedChunks` order,
1052
+ // preserving the runtime-first invariant. A chunk emitting neither
1053
+ // `.js` nor `.css` still gets a clone, as it always has.
1019
1054
  if (hasJs || !hasCss) jsChunks.push(chunk);
1020
1055
  }
1021
- // If the entry chunk itself contains CSS (entry JS imports CSS
1022
- // without splitChunks separating it), fold it into the same CSS
1023
- // ordering so the entry-chunk `<link>` lands in the correct
1024
- // cascade position relative to sibling CSS chunks.
1056
+ // When the entry chunk carries CSS itself, fold it into the same
1057
+ // ordering so its `<link>` lands in the right cascade position
1058
+ // relative to the sibling CSS chunks.
1025
1059
  if (chunkHasCss(entryChunk, chunkGraph)) {
1026
1060
  cssChunkOrder.push({
1027
1061
  chunk: entryChunk,
@@ -1034,13 +1068,9 @@ HtmlEntryDependency.Template = class HtmlEntryDependencyTemplate extends (
1034
1068
  });
1035
1069
  }
1036
1070
  cssChunkOrder.sort(compareCssChunkOrder);
1037
- // Stylesheets always land in <head> when the page has one. A
1038
- // classic blocking script pins them ahead of itself (`cssAnchor`)
1039
- // so its execution never awaits later CSS; when every script is
1040
- // `defer`/module they go to the *end* of head, after the script
1041
- // tags — Vite's and html-webpack-plugin's order: the scripts
1042
- // start fetching earlier yet still execute after parsing and
1043
- // after pending stylesheets.
1071
+ // Stylesheets land in `<head>`. A classic blocking script pins them
1072
+ // ahead of itself, so it never awaits later CSS; with only `defer` and
1073
+ // module scripts they go last, which starts the script fetches earlier.
1044
1074
  cssAt =
1045
1075
  dep.headAnchor >= 0
1046
1076
  ? dep.cssAnchor >= 0 && dep.cssAnchor < dep.headAnchor
@@ -1066,15 +1096,15 @@ HtmlEntryDependency.Template = class HtmlEntryDependencyTemplate extends (
1066
1096
  if (cssHtml !== "" && dep.cssAnchor < 0) source.insert(cssAt, cssHtml);
1067
1097
  }
1068
1098
 
1069
- // Resource hints are opt-in — webpack already loads the initial chunks
1070
- // via parallel `<script>` tags, so there is no waterfall to prevent by
1071
- // default. `output.resourceHints` requests them: `true` preloads the
1072
- // entry's initial dependency chunks (runtime, vendor, split); an array
1073
- // or function adds custom hints (a function may spread the auto
1074
- // `defaultHints`). Only for extracted pages — a JS-string HTML export
1075
- // would embed the sentinels in the JS chunk. URL-referenced assets
1076
- // (fonts, images) carrying `webpackPrefetch` / `webpackPreload`
1077
- // (magic-comment or `parser.<type>.urlHints` rule) also emit here.
1099
+ // WHY: resource hints are opt-in, the initial chunks already loading
1100
+ // through parallel `<script>` tags, so there is no default waterfall to
1101
+ // prevent. `output.resourceHints` requests them: `true` preloads the entry's
1102
+ // initial dependency chunks (runtime, vendor, split), while an array or a
1103
+ // function adds custom ones and a function may spread the auto
1104
+ // `defaultHints`. Extracted pages only — a JS-string HTML export would embed
1105
+ // the sentinels in the JS chunk. A URL-referenced asset carrying
1106
+ // `webpackPrefetch` / `webpackPreload`, by magic comment or a
1107
+ // `parser.<type>.urlHints` rule, emits here too.
1078
1108
  const resourceHintResolver =
1079
1109
  ResourceHintPlugin.getCompilationResolver(compilation);
1080
1110
  const resourceHints = resourceHintResolver.hints;
@@ -1102,15 +1132,16 @@ HtmlEntryDependency.Template = class HtmlEntryDependencyTemplate extends (
1102
1132
 
1103
1133
  // === chunks channel — the entry's own initial dependency graph ===
1104
1134
  if (resourceHints !== undefined && resourceHints !== false) {
1105
- // The auto initial-graph preload as descriptors carrying their exact
1106
- // tag, built only when needed (`true`/`"prefetch"` emits them, a
1107
- // function may spread them). The entry chunk is skipped — it's
1108
- // already the `<script src>`. ESM uses `modulepreload` (fetch +
1109
- // parse), classic output `preload as="script"`, and `"prefetch"`
1110
- // opts into `<link rel="prefetch">` (idle-time fetch, no `as` / no
1111
- // `integrity` — the spec doesn't list them). Async `import()` chunks
1112
- // aren't covered here; use `module.parser.javascript.dynamicImport*`
1113
- // which routes through webpack's on-demand chunk-load runtime.
1135
+ // WHY: descriptors for the auto initial-graph preload, carrying their
1136
+ // exact tag and built only when needed — `true` or `"prefetch"` emits
1137
+ // them, and a function may spread them. The entry chunk is skipped, being
1138
+ // the `<script src>` already. ESM uses `modulepreload`, which fetches and
1139
+ // parses; classic output `preload as="script"`; and `"prefetch"` opts into
1140
+ // `<link rel="prefetch">`, an idle-time fetch with no `as` and no
1141
+ // `integrity`, which the spec does not list. An async `import()` chunk is
1142
+ // not covered here: that is
1143
+ // `module.parser.javascript.dynamicImport*`, which routes through
1144
+ // webpack's on-demand chunk-load runtime.
1114
1145
  const prefetchMode = resourceHints === "prefetch";
1115
1146
  const preloadMode = resourceHints === true;
1116
1147
  /** @type {"modulepreload" | "preload" | "prefetch"} */
@@ -1145,10 +1176,9 @@ HtmlEntryDependency.Template = class HtmlEntryDependencyTemplate extends (
1145
1176
  "javascript"
1146
1177
  )}"`
1147
1178
  : "";
1148
- // Mirror the entry tag's `nonce`/`crossorigin`/`referrerpolicy`
1149
- // (and `output.crossOriginLoading`) so the request matches the
1150
- // sibling `<script>`'s and the browser reuses it instead of
1151
- // fetching twice.
1179
+ // Mirror the entry tag's `nonce`, `crossorigin` and `referrerpolicy`,
1180
+ // so the request matches the sibling `<script>`'s and the browser
1181
+ // reuses it rather than fetching twice.
1152
1182
  const attrs = `${dep.copyableAttrsText}${crossOrigin}${integrityAttr}`;
1153
1183
  const tag = prefetchMode
1154
1184
  ? `<link rel="prefetch" href="${href}"${attrs}>`
@@ -1226,14 +1256,10 @@ HtmlEntryDependency.Template = class HtmlEntryDependencyTemplate extends (
1226
1256
  }
1227
1257
 
1228
1258
  // === assets channel — URL-referenced assets carrying `prefetch`/`preload` ===
1229
- // The plugin has already scanned the entrypoint's chunks × modules
1230
- // once and cached the URL/CSS/HTML asset deps for this entry name;
1231
- // consume that list here so this template doesn't repeat the walk.
1232
- // Each unique asset emits one `<link rel="prefetch|preload">` into
1233
- // the HTML `<head>`; the JS chunk-startup runtime skips it (no
1234
- // double `<link>` in DOM). URLs are sentinels resolved from asset
1235
- // codegen data during `HtmlModulesPlugin` render — the asset
1236
- // module might not have been codegen'd yet at this point.
1259
+
1260
+ // The plugin already walked the entrypoint once and cached this entry's
1261
+ // asset deps, so consume that list rather than repeat it. URLs stay
1262
+ // sentinels here: the asset module may not be codegen'd yet.
1237
1263
  const outputCrossOriginAttr = crossOriginLoading
1238
1264
  ? ` crossorigin="${crossOriginLoading}"`
1239
1265
  : "";
@@ -1274,12 +1300,9 @@ HtmlEntryDependency.Template = class HtmlEntryDependencyTemplate extends (
1274
1300
  finalHints.push(h);
1275
1301
  }
1276
1302
  }
1277
- // When the target environment lacks native `modulepreload` (an
1278
- // `output.environment` capability, like the JS-feature checks), append
1279
- // a tiny polyfill once per page so the hints still warm the cache there.
1280
- // `resourceHints.modulePreloadPolyfill` defaults from the target's
1281
- // modulepreload support (`output.environment.modulePreload`); `false`
1282
- // opts out (strict CSP).
1303
+ // Without native `modulepreload` the hints warm no cache, so append the
1304
+ // polyfill once per page. It defaults from the target's support, and
1305
+ // `false` opts out, which a strict CSP needs.
1283
1306
  if (
1284
1307
  rhOptions &&
1285
1308
  rhOptions.modulePreloadPolyfill &&
@@ -1289,10 +1312,9 @@ HtmlEntryDependency.Template = class HtmlEntryDependencyTemplate extends (
1289
1312
  polyfilledSources.add(source);
1290
1313
  finalHints.push(`<script>${MODULEPRELOAD_POLYFILL}</script>`);
1291
1314
  }
1292
- // Insert right after the `<head>` open tag (parser-derived) so the
1293
- // hints are the document's first fetches; fall back to the first
1294
- // blocking script (else the entry tag) when the page has no
1295
- // written `<head>` (e.g. an HTML fragment).
1315
+ // Insert just after the `<head>` open tag, so the hints are the first
1316
+ // fetches. A page with no written `<head>` falls back to the first
1317
+ // blocking script, else the entry tag.
1296
1318
  const hintAt =
1297
1319
  dep.headOpenEnd >= 0
1298
1320
  ? dep.headOpenEnd
@@ -112,10 +112,9 @@ HtmlInlineScriptDependency.Template = class HtmlInlineScriptDependencyTemplate e
112
112
  url = getHtmlGenerator().makeChunkUrlSentinel(chunk, "javascript");
113
113
  }
114
114
 
115
- // Insert ` src="…"` right after `<script` so the inline body is
116
- // served from the emitted chunk instead. The browser ignores the
117
- // remaining inline body once `src` is present, but we still clear
118
- // it below so the unprocessed JS doesn't ride along.
115
+ // Insert ` src="…"` just after `<script`, serving the body from the emitted
116
+ // chunk. The browser ignores an inline body beside `src`, but it is cleared
117
+ // below so the unprocessed JS does not ride along.
119
118
  source.insert(dep.insertPos, ` src="${url}"`);
120
119
  source.replace(dep.contentRange[0], dep.contentRange[1] - 1, "");
121
120
  }
@@ -127,10 +127,9 @@ HtmlInlineStyleDependency.Template = class HtmlInlineStyleDependencyTemplate ext
127
127
  }
128
128
  }
129
129
 
130
- // An attribute value was entity-decoded before parsing, so re-escape
131
- // the processed CSS to keep the surrounding markup valid in any
132
- // quoting context, and drop the trailing newline the CSS generator
133
- // appends so the rewritten attribute stays on one line.
130
+ // An attribute value was entity-decoded before parsing, so the processed CSS
131
+ // is re-escaped to keep the markup valid in any quoting context, and the
132
+ // generator's trailing newline dropped to keep it on one line.
134
133
  if (dep.inAttribute) {
135
134
  cssText = cssText
136
135
  .replace(TRAILING_WHITESPACE_REGEXP, "")
@@ -20,7 +20,7 @@ const ImportMetaContextDependency = require("./ImportMetaContextDependency");
20
20
  * } from "estree"
21
21
  */
22
22
  /** @import JavascriptParser, { Range } from "../javascript/JavascriptParser" */
23
- /** @import { ContextModuleOptions, ContextMode } from "../ContextModule" */
23
+ /** @import { ContextModuleOptions, ContextMode } from "../context/ContextModule" */
24
24
  /** @import { ChunkName } from "../Chunk" */
25
25
  /** @import { RawChunkGroupOptions } from "../ChunkGroup" */
26
26
  /** @import { RawReferencedExports, DependencyLocation } from "../Dependency" */
@@ -27,7 +27,7 @@ const getUnsupportedFeatureWarning = memoize(() =>
27
27
  require("../errors/UnsupportedFeatureWarning")
28
28
  );
29
29
 
30
- /** @import { ContextModuleOptions } from "../ContextModule" */
30
+ /** @import { ContextModuleOptions } from "../context/ContextModule" */
31
31
  /** @import JavascriptParser, { Range } from "../javascript/JavascriptParser" */
32
32
  /** @import { RawReferencedExports, DependencyLocation } from "../Dependency" */
33
33
  /**
@@ -0,0 +1,104 @@
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 makeSerializable = require("../util/makeSerializable");
9
+ const ConstDependency = require("./ConstDependency");
10
+ const NullDependency = require("./NullDependency");
11
+
12
+ /** @import { ReplaceSource } from "webpack-sources" */
13
+ /** @import Dependency, { UpdateHashContext } from "../Dependency" */
14
+ /** @import { DependencyTemplateContext } from "../DependencyTemplate" */
15
+ /** @import { Range } from "../javascript/JavascriptParser" */
16
+ /**
17
+ * @import {
18
+ * ObjectDeserializerContext,
19
+ * ObjectSerializerContext
20
+ * } from "../serialization/ObjectMiddleware"
21
+ */
22
+ /** @import Hash from "../util/Hash" */
23
+
24
+ /**
25
+ * `import.meta.main` asks whether the module is the entry, which needs the
26
+ * module argument scope hoisting removes. An inner concatenated module is
27
+ * never an entry module, so it answers with a separate constant expression.
28
+ */
29
+ class ImportMetaMainDependency extends ConstDependency {
30
+ /**
31
+ * Creates an instance of ImportMetaMainDependency.
32
+ * @param {string} expression the expression a module outside a concatenation evaluates
33
+ * @param {string} concatenatedExpression the expression an inner concatenated module evaluates
34
+ * @param {Range} range the source range
35
+ * @param {(string[] | null)=} runtimeRequirements runtime requirements of `expression`
36
+ */
37
+ constructor(expression, concatenatedExpression, range, runtimeRequirements) {
38
+ super(expression, range, runtimeRequirements);
39
+ /** @type {string} */
40
+ this.concatenatedExpression = concatenatedExpression;
41
+ }
42
+
43
+ /**
44
+ * Updates the hash with the data contributed by this instance.
45
+ * @param {Hash} hash hash to be updated
46
+ * @param {UpdateHashContext} context context
47
+ * @returns {void}
48
+ */
49
+ updateHash(hash, context) {
50
+ super.updateHash(hash, context);
51
+ hash.update(this.concatenatedExpression);
52
+ }
53
+
54
+ /**
55
+ * Serializes this instance into the provided serializer context.
56
+ * @param {ObjectSerializerContext} context context
57
+ */
58
+ serialize(context) {
59
+ context.write(this.concatenatedExpression);
60
+ super.serialize(context);
61
+ }
62
+
63
+ /**
64
+ * Restores this instance from the provided deserializer context.
65
+ * @param {ObjectDeserializerContext} context context
66
+ */
67
+ deserialize(context) {
68
+ this.concatenatedExpression = context.read();
69
+ super.deserialize(context.rest);
70
+ }
71
+ }
72
+
73
+ makeSerializable(
74
+ ImportMetaMainDependency,
75
+ "webpack/lib/dependencies/ImportMetaMainDependency"
76
+ );
77
+
78
+ ImportMetaMainDependency.Template = class ImportMetaMainDependencyTemplate extends (
79
+ NullDependency.Template
80
+ ) {
81
+ /**
82
+ * Applies the plugin by registering its hooks on the compiler.
83
+ * @param {Dependency} dependency the dependency for which the template should be applied
84
+ * @param {ReplaceSource} source the current replace source which can be modified
85
+ * @param {DependencyTemplateContext} templateContext the context object
86
+ * @returns {void}
87
+ */
88
+ apply(dependency, source, templateContext) {
89
+ const dep = /** @type {ImportMetaMainDependency} */ (dependency);
90
+ const concatenated = templateContext.concatenationScope !== undefined;
91
+ if (!concatenated && dep.runtimeRequirements) {
92
+ for (const req of dep.runtimeRequirements) {
93
+ templateContext.runtimeRequirements.add(req);
94
+ }
95
+ }
96
+ const expression = concatenated
97
+ ? dep.concatenatedExpression
98
+ : dep.expression;
99
+ const range = /** @type {Range} */ (dep.range);
100
+ source.replace(range[0], range[1] - 1, expression);
101
+ }
102
+ };
103
+
104
+ module.exports = ImportMetaMainDependency;