webpack 5.108.4 → 5.109.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 (186) hide show
  1. package/lib/APIPlugin.js +48 -29
  2. package/lib/CacheFacade.js +8 -0
  3. package/lib/ChunkGroup.js +1 -0
  4. package/lib/CompatibilityPlugin.js +31 -29
  5. package/lib/Compilation.js +49 -4
  6. package/lib/ConstPlugin.js +11 -11
  7. package/lib/ContextModule.js +239 -6
  8. package/lib/ContextModuleFactory.js +139 -14
  9. package/lib/DefinePlugin.js +396 -101
  10. package/lib/Entrypoint.js +1 -1
  11. package/lib/ExportsInfoApiPlugin.js +2 -2
  12. package/lib/ExternalModule.js +107 -5
  13. package/lib/ExternalModuleFactoryPlugin.js +20 -1
  14. package/lib/FileSystemInfo.js +130 -74
  15. package/lib/HotModuleReplacementPlugin.js +18 -15
  16. package/lib/Module.js +3 -0
  17. package/lib/ModuleFilenameHelpers.js +2 -2
  18. package/lib/ModuleTypeConstants.js +8 -1
  19. package/lib/MultiCompiler.js +13 -2
  20. package/lib/MultiWatching.js +1 -0
  21. package/lib/NodeStuffPlugin.js +51 -33
  22. package/lib/NormalModule.js +169 -401
  23. package/lib/NormalModuleFactory.js +76 -2
  24. package/lib/ProgressPlugin.js +211 -119
  25. package/lib/ProvidePlugin.js +2 -2
  26. package/lib/RuntimeGlobals.js +47 -0
  27. package/lib/RuntimePlugin.js +33 -0
  28. package/lib/RuntimeTemplate.js +304 -16
  29. package/lib/UseStrictPlugin.js +1 -1
  30. package/lib/WebpackIsIncludedPlugin.js +1 -1
  31. package/lib/WebpackOptionsApply.js +24 -19
  32. package/lib/asset/AssetGenerator.js +110 -28
  33. package/lib/asset/AssetModulesPlugin.js +92 -2
  34. package/lib/asset/WebManifestGenerator.js +164 -0
  35. package/lib/asset/WebManifestParser.js +130 -0
  36. package/lib/async-modules/AwaitDependenciesInitFragment.js +14 -4
  37. package/lib/async-modules/isGeneratorLowered.js +26 -0
  38. package/lib/cache/PackFileCacheStrategy.js +9 -3
  39. package/lib/config/browserslistTargetHandler.js +40 -0
  40. package/lib/config/defaults.js +219 -29
  41. package/lib/config/normalization.js +26 -0
  42. package/lib/config/target.js +9 -1
  43. package/lib/css/CssGenerator.js +40 -31
  44. package/lib/css/CssLoadingRuntimeModule.js +5 -1
  45. package/lib/css/CssModulesPlugin.js +13 -0
  46. package/lib/css/CssParser.js +594 -263
  47. package/lib/css/syntax.js +875 -462
  48. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +6 -6
  49. package/lib/dependencies/AMDPlugin.js +2 -2
  50. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +13 -13
  51. package/lib/dependencies/CommonJsDependencyHelpers.js +39 -0
  52. package/lib/dependencies/CommonJsExportsDependency.js +47 -2
  53. package/lib/dependencies/CommonJsExportsParserPlugin.js +10 -10
  54. package/lib/dependencies/CommonJsImportsParserPlugin.js +18 -18
  55. package/lib/dependencies/CommonJsPlugin.js +2 -2
  56. package/lib/dependencies/CommonJsRequireDependency.js +26 -1
  57. package/lib/dependencies/CommonJsSelfReferenceDependency.js +32 -1
  58. package/lib/dependencies/ContextDependencyHelpers.js +3 -3
  59. package/lib/dependencies/CreateRequireParserPlugin.js +6 -6
  60. package/lib/dependencies/CssIcssExportDependency.js +162 -71
  61. package/lib/dependencies/CssUrlDependency.js +35 -4
  62. package/lib/dependencies/ExternalModuleInitFragmentDependency.js +2 -2
  63. package/lib/dependencies/HarmonyCompatibilityDependency.js +32 -14
  64. package/lib/dependencies/HarmonyDetectionParserPlugin.js +43 -13
  65. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +7 -19
  66. package/lib/dependencies/HarmonyImportDependency.js +12 -1
  67. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +11 -11
  68. package/lib/dependencies/HarmonyModulesPlugin.js +6 -0
  69. package/lib/dependencies/HarmonyTopLevelThisParserPlugin.js +1 -1
  70. package/lib/dependencies/HtmlEntryDependency.js +797 -172
  71. package/lib/dependencies/HtmlSourceDependency.js +26 -0
  72. package/lib/dependencies/ImportDependency.js +43 -1
  73. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +31 -18
  74. package/lib/dependencies/ImportMetaContextPlugin.js +38 -7
  75. package/lib/dependencies/ImportMetaGlobDependency.js +81 -0
  76. package/lib/dependencies/ImportMetaGlobDependencyParserPlugin.js +78 -0
  77. package/lib/dependencies/ImportMetaGlobHelpers.js +660 -0
  78. package/lib/dependencies/ImportMetaPlugin.js +532 -180
  79. package/lib/dependencies/ImportMetaResolveDependency.js +90 -0
  80. package/lib/dependencies/ImportParserPlugin.js +80 -17
  81. package/lib/dependencies/ImportPhase.js +10 -8
  82. package/lib/dependencies/LoaderPlugin.js +5 -1
  83. package/lib/dependencies/RequireContextDependencyParserPlugin.js +1 -1
  84. package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +3 -6
  85. package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +4 -11
  86. package/lib/dependencies/SystemPlugin.js +2 -4
  87. package/lib/dependencies/TopLevelAwaitDependency.js +93 -0
  88. package/lib/dependencies/URLDependency.js +141 -21
  89. package/lib/dependencies/{WorkerPlugin.js → WorkerAndWorkletPlugin.js} +324 -112
  90. package/lib/dependencies/WorkerDependency.js +86 -18
  91. package/lib/dependencies/WorkletDependency.js +278 -0
  92. package/lib/dll/DelegatedModuleFactoryPlugin.js +19 -0
  93. package/lib/errors/EnvironmentNotSupportAsyncWarning.js +1 -1
  94. package/lib/errors/LoaderLoadingError.js +20 -0
  95. package/lib/errors/ModuleParseError.js +39 -22
  96. package/lib/errors/NodeStuffInWebError.js +1 -1
  97. package/lib/esm/ModuleChunkFormatPlugin.js +47 -14
  98. package/lib/esm/ModuleChunkLoadingPlugin.js +8 -1
  99. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +29 -1
  100. package/lib/hmr/lazyCompilationBackend.js +32 -8
  101. package/lib/html/HtmlGenerator.js +887 -15
  102. package/lib/html/HtmlModule.js +2 -2
  103. package/lib/html/HtmlModulesPlugin.js +610 -166
  104. package/lib/html/HtmlParser.js +603 -247
  105. package/lib/html/favicon.svg +1 -0
  106. package/lib/html/syntax.js +1264 -661
  107. package/lib/ids/IdHelpers.js +1 -1
  108. package/lib/index.js +6 -0
  109. package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +4 -5
  110. package/lib/javascript/BasicEvaluatedExpression.js +366 -48
  111. package/lib/javascript/JavascriptGenerator.js +197 -49
  112. package/lib/javascript/JavascriptModulesPlugin.js +178 -24
  113. package/lib/javascript/JavascriptParser.js +701 -355
  114. package/lib/javascript/JavascriptParserHelpers.js +3 -6
  115. package/lib/javascript/syntax.js +4380 -0
  116. package/lib/library/ModuleLibraryPlugin.js +38 -1
  117. package/lib/loaders/LoaderRunner.js +714 -0
  118. package/lib/loaders/loadLoader.js +100 -0
  119. package/lib/node/ReadFileCompileAsyncWasmPlugin.js +19 -0
  120. package/lib/node/ReadFileCompileWasmPlugin.js +14 -0
  121. package/lib/optimize/ConcatenatedModule.js +120 -16
  122. package/lib/optimize/FlagIncludedChunksPlugin.js +13 -3
  123. package/lib/optimize/InnerGraphPlugin.js +50 -30
  124. package/lib/optimize/ModuleConcatenationPlugin.js +69 -3
  125. package/lib/optimize/SideEffectsFlagPlugin.js +86 -43
  126. package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +15 -0
  127. package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +24 -13
  128. package/lib/prefetch/ResourceHintPlugin.js +663 -0
  129. package/lib/prefetch/ResourceHintRuntimeModule.js +149 -0
  130. package/lib/prefetch/StartupAssetHintRuntimeModule.js +210 -0
  131. package/lib/prefetch/parseResourceHintOptions.js +103 -0
  132. package/lib/rules/RuleSetCompiler.js +114 -0
  133. package/lib/runtime/AsyncModuleGeneratorRuntimeModule.js +56 -0
  134. package/lib/runtime/AsyncModuleRuntimeModule.js +24 -8
  135. package/lib/runtime/AutoPublicPathRuntimeModule.js +7 -1
  136. package/lib/runtime/CommonJsWrapRuntimeModule.js +37 -0
  137. package/lib/runtime/GetWorkletBootstrapRuntimeModule.js +59 -0
  138. package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +204 -8
  139. package/lib/runtime/SetAnonymousDefaultNameRuntimeModule.js +4 -1
  140. package/lib/schemes/HttpUriPlugin.js +40 -1
  141. package/lib/schemes/VirtualUrlPlugin.js +1 -2
  142. package/lib/serialization/FileMiddleware.js +29 -3
  143. package/lib/stats/DefaultStatsFactoryPlugin.js +32 -3
  144. package/lib/stats/DefaultStatsPresetPlugin.js +2 -0
  145. package/lib/stats/DefaultStatsPrinterPlugin.js +12 -2
  146. package/lib/stats/StatsFactory.js +15 -8
  147. package/lib/url/URLParserPlugin.js +66 -13
  148. package/lib/util/AsyncQueue.js +122 -72
  149. package/lib/util/SetHelpers.js +1 -1
  150. package/lib/util/StackedMap.js +122 -48
  151. package/lib/util/binarySearchBounds.js +2 -2
  152. package/lib/util/concatenate.js +40 -14
  153. package/lib/util/createHooksRegistry.js +13 -5
  154. package/lib/util/dataURL.js +2 -2
  155. package/lib/util/deterministicGrouping.js +7 -5
  156. package/lib/util/formatSize.js +6 -2
  157. package/lib/util/globUtils.js +710 -0
  158. package/lib/util/identifier.js +23 -6
  159. package/lib/util/implicitTypeLoaderFallback.js +62 -0
  160. package/lib/util/internalSerializables.js +88 -71
  161. package/lib/util/magicComment.js +121 -25
  162. package/lib/util/numberHash.js +2 -2
  163. package/lib/wasm-async/AsyncWasmCompileRuntimeModule.js +24 -18
  164. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +33 -22
  165. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +79 -16
  166. package/lib/web/FetchCompileAsyncWasmPlugin.js +19 -0
  167. package/lib/web/FetchCompileWasmPlugin.js +14 -0
  168. package/lib/web/JsonpChunkLoadingRuntimeModule.js +2 -0
  169. package/lib/webpack.js +65 -0
  170. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +3 -0
  171. package/module.d.ts +21 -0
  172. package/package.json +13 -12
  173. package/schemas/WebpackOptions.check.js +1 -1
  174. package/schemas/WebpackOptions.json +759 -36
  175. package/schemas/plugins/HtmlParserOptions.check.js +1 -1
  176. package/schemas/plugins/ProgressPlugin.check.js +1 -1
  177. package/schemas/plugins/ProgressPlugin.json +17 -1
  178. package/schemas/plugins/container/ContainerReferencePlugin.check.js +1 -1
  179. package/schemas/plugins/container/ContainerReferencePlugin.json +1 -0
  180. package/schemas/plugins/container/ExternalsType.check.js +1 -1
  181. package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
  182. package/schemas/plugins/container/ModuleFederationPlugin.json +1 -0
  183. package/schemas/plugins/css/CssAutoOrModuleParserOptions.check.js +1 -1
  184. package/schemas/plugins/css/CssModuleParserOptions.check.js +1 -1
  185. package/schemas/plugins/css/CssParserOptions.check.js +1 -1
  186. package/types.d.ts +1213 -96
@@ -31,6 +31,7 @@ const {
31
31
  WEBASSEMBLY_MODULE_TYPE_SYNC
32
32
  } = require("../ModuleTypeConstants");
33
33
  const Template = require("../Template");
34
+ const RuleSetCompiler = require("../rules/RuleSetCompiler");
34
35
  const { cleverMerge } = require("../util/cleverMerge");
35
36
  const {
36
37
  getDefaultTarget,
@@ -71,6 +72,7 @@ const {
71
72
  /** @typedef {import("../../declarations/WebpackOptions").ParserOptionsByModuleTypeKnown} ParserOptionsByModuleTypeKnown */
72
73
  /** @typedef {import("../../declarations/WebpackOptions").Performance} Performance */
73
74
  /** @typedef {import("../../declarations/WebpackOptions").ResolveOptions} ResolveOptions */
75
+ /** @typedef {import("../../declarations/WebpackOptions").RuleSetRule} RuleSetRule */
74
76
  /** @typedef {import("../../declarations/WebpackOptions").RuleSetRules} RuleSetRules */
75
77
  /** @typedef {import("../../declarations/WebpackOptions").SnapshotOptions} SnapshotOptions */
76
78
  /** @typedef {import("../../declarations/WebpackOptions").WebpackOptionsNormalized} WebpackOptionsNormalized */
@@ -341,6 +343,26 @@ const applyWebpackOptionsDefaults = (options, compilerIndex) => {
341
343
  }
342
344
  }
343
345
 
346
+ D(options, "watch", false);
347
+ D(options, "profile", false);
348
+ D(options, "parallelism", 100);
349
+ D(options, "recordsInputPath", false);
350
+ D(options, "recordsOutputPath", false);
351
+
352
+ // Capture the raw html intent before "auto" is resolved: only an explicit
353
+ // `html: true` (or futureDefaults) keeps `.html` ahead of `.js` when resolving.
354
+ const htmlExplicitlyEnabled = options.experiments.html === true;
355
+ const htmlWasUnset = options.experiments.html === undefined;
356
+
357
+ applyExperimentsDefaults(options.experiments, {
358
+ production,
359
+ development,
360
+ targetProperties,
361
+ rules: options.module.rules
362
+ });
363
+
364
+ // After experiments are resolved: the default dev source map depends on the
365
+ // (possibly "auto"-resolved) `experiments.css` value.
344
366
  F(
345
367
  options,
346
368
  "devtool",
@@ -363,24 +385,20 @@ const applyWebpackOptionsDefaults = (options, compilerIndex) => {
363
385
  )
364
386
  );
365
387
 
366
- D(options, "watch", false);
367
- D(options, "profile", false);
368
- D(options, "parallelism", 100);
369
- D(options, "recordsInputPath", false);
370
- D(options, "recordsOutputPath", false);
371
-
372
- applyExperimentsDefaults(options.experiments, {
373
- production,
374
- development,
375
- targetProperties
376
- });
377
-
378
388
  const futureDefaults =
379
389
  /** @type {NonNullable<ExperimentsNormalized["futureDefaults"]>} */
380
390
  (options.experiments.futureDefaults);
381
391
 
392
+ // `.html` outranks `.js` only for an explicit opt-in (`html: true`, or the
393
+ // futureDefaults-forced default), never for the auto-enabled default.
394
+ const htmlFirst = htmlExplicitlyEnabled || (htmlWasUnset && futureDefaults);
395
+
382
396
  F(options, "validate", () => !(futureDefaults === true && production));
383
397
 
398
+ // Progress lives on infrastructureLogging; webpack@6 shows the interactive
399
+ // bar by default (`"auto"` = TTY only), webpack@5 stays opt-in.
400
+ D(options.infrastructureLogging, "progress", futureDefaults ? "auto" : false);
401
+
384
402
  F(options, "cache", () =>
385
403
  development ? { type: /** @type {"memory"} */ ("memory") } : false
386
404
  );
@@ -414,7 +432,7 @@ const applyWebpackOptionsDefaults = (options, compilerIndex) => {
414
432
  entry: options.entry,
415
433
  futureDefaults,
416
434
  asyncWebAssembly:
417
- /** @type {NonNullable<ExperimentsNormalized["asyncWebAssembly"]>} */
435
+ /** @type {boolean} */
418
436
  (options.experiments.asyncWebAssembly)
419
437
  });
420
438
 
@@ -430,16 +448,16 @@ const applyWebpackOptionsDefaults = (options, compilerIndex) => {
430
448
  /** @type {NonNullable<ExperimentsNormalized["syncWebAssembly"]>} */
431
449
  (options.experiments.syncWebAssembly),
432
450
  asyncWebAssembly:
433
- /** @type {NonNullable<ExperimentsNormalized["asyncWebAssembly"]>} */
451
+ /** @type {boolean} */
434
452
  (options.experiments.asyncWebAssembly),
435
453
  css:
436
- /** @type {NonNullable<ExperimentsNormalized["css"]>} */
454
+ /** @type {boolean} */
437
455
  (options.experiments.css),
438
456
  html:
439
- /** @type {NonNullable<ExperimentsNormalized["html"]>} */
457
+ /** @type {boolean} */
440
458
  (options.experiments.html),
441
459
  typescript:
442
- /** @type {NonNullable<ExperimentsNormalized["typescript"]>} */
460
+ /** @type {boolean} */
443
461
  (options.experiments.typescript),
444
462
  deferImport:
445
463
  /** @type {NonNullable<ExperimentsNormalized["deferImport"]>} */
@@ -458,6 +476,29 @@ const applyWebpackOptionsDefaults = (options, compilerIndex) => {
458
476
  library: options.output.library
459
477
  });
460
478
 
479
+ // `output.resourceHints.urlHints` shorthand: fan the project-wide rules out
480
+ // as the base `urlHints` of every URL-emitting parser (JS `new URL`, CSS
481
+ // `url()`, HTML `<img src>`). They go first so parser-scoped
482
+ // `parser.<type>.urlHints` rules — matched later, last-match-wins — override.
483
+ const outputUrlHints =
484
+ options.output.resourceHints && options.output.resourceHints.urlHints;
485
+ if (outputUrlHints && outputUrlHints.length > 0) {
486
+ for (const type of [
487
+ "javascript",
488
+ CSS_MODULE_TYPE,
489
+ CSS_MODULE_TYPE_AUTO,
490
+ CSS_MODULE_TYPE_MODULE,
491
+ CSS_MODULE_TYPE_GLOBAL,
492
+ HTML_MODULE_TYPE
493
+ ]) {
494
+ const parser =
495
+ /** @type {{ urlHints?: import("../../declarations/WebpackOptions").UrlHintRule[] } | undefined} */
496
+ (options.module.parser[type]);
497
+ if (!parser) continue;
498
+ parser.urlHints = [...outputUrlHints, ...(parser.urlHints || [])];
499
+ }
500
+ }
501
+
461
502
  applyExternalsPresetsDefaults(options.externalsPresets, {
462
503
  targetProperties,
463
504
  buildHttp: Boolean(options.experiments.buildHttp),
@@ -514,7 +555,7 @@ const applyWebpackOptionsDefaults = (options, compilerIndex) => {
514
555
  development,
515
556
  production,
516
557
  css:
517
- /** @type {NonNullable<ExperimentsNormalized["css"]>} */
558
+ /** @type {boolean} */
518
559
  (options.experiments.css),
519
560
  records: Boolean(options.recordsInputPath || options.recordsOutputPath)
520
561
  });
@@ -526,13 +567,14 @@ const applyWebpackOptionsDefaults = (options, compilerIndex) => {
526
567
  targetProperties,
527
568
  mode: /** @type {Mode} */ (options.mode),
528
569
  css:
529
- /** @type {NonNullable<ExperimentsNormalized["css"]>} */
570
+ /** @type {boolean} */
530
571
  (options.experiments.css),
531
572
  html:
532
- /** @type {NonNullable<ExperimentsNormalized["html"]>} */
573
+ /** @type {boolean} */
533
574
  (options.experiments.html),
575
+ htmlFirst,
534
576
  typescript:
535
- /** @type {NonNullable<ExperimentsNormalized["typescript"]>} */
577
+ /** @type {boolean} */
536
578
  (options.experiments.typescript)
537
579
  }),
538
580
  options.resolve
@@ -570,17 +612,22 @@ const applyWebpackOptionsDefaults = (options, compilerIndex) => {
570
612
  * @param {boolean} options.production is production
571
613
  * @param {boolean} options.development is development mode
572
614
  * @param {TargetProperties | false} options.targetProperties target properties
615
+ * @param {RuleSetRules} options.rules user `module.rules`, used to resolve the css/html/asyncWebAssembly/typescript "auto" defaults
573
616
  * @returns {void}
574
617
  */
575
618
  const applyExperimentsDefaults = (
576
619
  experiments,
577
- { production, development, targetProperties }
620
+ { production, development, targetProperties, rules }
578
621
  ) => {
579
622
  D(experiments, "futureDefaults", false);
580
623
  D(experiments, "backCompat", !experiments.futureDefaults);
581
624
  // TODO do we need sync web assembly in webpack@6?
582
625
  D(experiments, "syncWebAssembly", false);
583
- D(experiments, "asyncWebAssembly", experiments.futureDefaults);
626
+ D(
627
+ experiments,
628
+ "asyncWebAssembly",
629
+ experiments.futureDefaults ? true : "auto"
630
+ );
584
631
  // the universal target (web + node, neither specific) only works as ESM
585
632
  const universal =
586
633
  Boolean(targetProperties) &&
@@ -599,12 +646,52 @@ const applyExperimentsDefaults = (
599
646
  D(experiments, "cacheUnaffected", experiments.futureDefaults);
600
647
  D(experiments, "deferImport", false);
601
648
  D(experiments, "sourceImport", false);
602
- F(experiments, "css", () => (experiments.futureDefaults ? true : undefined));
603
- F(experiments, "html", () => (experiments.futureDefaults ? true : undefined));
649
+ F(experiments, "css", () => (experiments.futureDefaults ? true : "auto"));
650
+ F(experiments, "html", () => (experiments.futureDefaults ? true : "auto"));
604
651
  F(experiments, "typescript", () =>
605
- experiments.futureDefaults ? true : undefined
652
+ experiments.futureDefaults ? true : "auto"
606
653
  );
607
654
 
655
+ // Resolve the "auto" default: enable the built-in css/html module type unless
656
+ // the user already registered a loader (or explicit type) for these files, so
657
+ // enabling them by default does not break existing css-loader/html-loader setups.
658
+ // The built-in `/\.css$/i` rule also covers `.module.css`, so a loader scoped to
659
+ // CSS modules must disable the built-in type too — sample both extensions.
660
+ // When enabled implicitly the value stays `"auto"` (truthy): Css/HtmlModulesPlugin
661
+ // then step aside per-module for requests that loaders were applied to
662
+ // (inline requests or loaders injected via hooks, e.g. html-webpack-plugin).
663
+ // TODO webpack 6: css/html default to `true`, drop the `"auto"` marker.
664
+ if (experiments.css === "auto") {
665
+ experiments.css =
666
+ !(
667
+ RuleSetCompiler.hasRuleForResource(rules, "/file.css") ||
668
+ RuleSetCompiler.hasRuleForResource(rules, "/file.module.css")
669
+ ) && "auto";
670
+ }
671
+ if (experiments.html === "auto") {
672
+ experiments.html =
673
+ !RuleSetCompiler.hasRuleForResource(rules, "/file.html") && "auto";
674
+ }
675
+ // Auto-enable only when the built-in TypeScript support can actually run:
676
+ // it needs `module.stripTypeScriptTypes` (Node.js >= 22.6) and must step
677
+ // aside for a loader registered for `.ts`/`.mts`/`.cts` (e.g. ts-loader).
678
+ if (experiments.typescript === "auto") {
679
+ experiments.typescript =
680
+ // eslint-disable-next-line n/no-unsupported-features/node-builtins
681
+ typeof require("module").stripTypeScriptTypes === "function" &&
682
+ !(
683
+ RuleSetCompiler.hasRuleForResource(rules, "/file.ts") ||
684
+ RuleSetCompiler.hasRuleForResource(rules, "/file.mts") ||
685
+ RuleSetCompiler.hasRuleForResource(rules, "/file.cts")
686
+ );
687
+ }
688
+ // `syncWebAssembly` already claims `.wasm`, so don't let "auto" override it.
689
+ if (experiments.asyncWebAssembly === "auto") {
690
+ experiments.asyncWebAssembly =
691
+ !experiments.syncWebAssembly &&
692
+ !RuleSetCompiler.hasRuleForResource(rules, "/file.wasm");
693
+ }
694
+
608
695
  if (typeof experiments.buildHttp === "object") {
609
696
  D(experiments.buildHttp, "frozen", production);
610
697
  D(experiments.buildHttp, "upgrade", false);
@@ -820,6 +907,7 @@ const applyJavascriptParserOptionsDefaults = (
820
907
  D(parserOptions, "sourceImport", sourceImport);
821
908
  D(parserOptions, "typescript", typescript);
822
909
  if (futureDefaults) D(parserOptions, "exportsPresence", "error");
910
+ D(parserOptions, "strictModeViolations", futureDefaults ? "error" : "warn");
823
911
  D(parserOptions, "anonymousDefaultExportName", !library);
824
912
  };
825
913
 
@@ -989,6 +1077,18 @@ const applyModuleDefaults = (
989
1077
  "namedExports",
990
1078
  true
991
1079
  );
1080
+ D(
1081
+ /** @type {NonNullable<ParserOptionsByModuleTypeKnown[CSS_MODULE_TYPE]>} */
1082
+ (module.parser[CSS_MODULE_TYPE]),
1083
+ "customMedia",
1084
+ true
1085
+ );
1086
+ D(
1087
+ /** @type {NonNullable<ParserOptionsByModuleTypeKnown[CSS_MODULE_TYPE]>} */
1088
+ (module.parser[CSS_MODULE_TYPE]),
1089
+ "customSelectors",
1090
+ true
1091
+ );
992
1092
 
993
1093
  for (const type of [
994
1094
  CSS_MODULE_TYPE_AUTO,
@@ -1033,6 +1133,18 @@ const applyModuleDefaults = (
1033
1133
  "grid",
1034
1134
  true
1035
1135
  );
1136
+ D(
1137
+ /** @type {NonNullable<ParserOptionsByModuleTypeKnown[CSS_MODULE_TYPE_AUTO]> | NonNullable<ParserOptionsByModuleTypeKnown[CSS_MODULE_TYPE_MODULE]> | NonNullable<ParserOptionsByModuleTypeKnown[CSS_MODULE_TYPE_GLOBAL]>} */
1138
+ (module.parser[type]),
1139
+ "customMedia",
1140
+ true
1141
+ );
1142
+ D(
1143
+ /** @type {NonNullable<ParserOptionsByModuleTypeKnown[CSS_MODULE_TYPE_AUTO]> | NonNullable<ParserOptionsByModuleTypeKnown[CSS_MODULE_TYPE_MODULE]> | NonNullable<ParserOptionsByModuleTypeKnown[CSS_MODULE_TYPE_GLOBAL]>} */
1144
+ (module.parser[type]),
1145
+ "customSelectors",
1146
+ true
1147
+ );
1036
1148
  }
1037
1149
 
1038
1150
  F(module.generator, CSS_MODULE_TYPE, () => ({}));
@@ -1407,6 +1519,46 @@ const applyModuleDefaults = (
1407
1519
  type: ASSET_MODULE_TYPE_BYTES
1408
1520
  }
1409
1521
  );
1522
+ if (html) {
1523
+ // A `.webmanifest` referenced by `<link rel="manifest">` is a `url`
1524
+ // dependency; route it to the `asset/webmanifest` type so its icon URLs
1525
+ // are parsed. Must come after the generic `url` → asset rule so it wins.
1526
+ rules.push({
1527
+ dependency: "url",
1528
+ test: /\.webmanifest$/i,
1529
+ type: "asset/webmanifest"
1530
+ });
1531
+ // A generated manifest (`output.html.manifest` object) is injected as a
1532
+ // `data:application/manifest+json` URL with no `.webmanifest` extension;
1533
+ // route it by mimetype so its icons are parsed and hashed too.
1534
+ rules.push({
1535
+ dependency: "url",
1536
+ mimetype: "application/manifest+json",
1537
+ type: "asset/webmanifest"
1538
+ });
1539
+ }
1540
+ if (futureDefaults) {
1541
+ rules.push({
1542
+ oneOf: [
1543
+ {
1544
+ resourceQuery: /(\?|&)raw(&|$)/,
1545
+ type: ASSET_MODULE_TYPE_SOURCE
1546
+ },
1547
+ {
1548
+ resourceQuery: /(\?|&)url(&|$)/,
1549
+ type: ASSET_MODULE_TYPE_RESOURCE
1550
+ },
1551
+ {
1552
+ resourceQuery: /(\?|&)no-inline(&|$)/,
1553
+ type: ASSET_MODULE_TYPE_RESOURCE
1554
+ },
1555
+ {
1556
+ resourceQuery: /(\?|&)inline(&|$)/,
1557
+ type: ASSET_MODULE_TYPE_INLINE
1558
+ }
1559
+ ]
1560
+ });
1561
+ }
1410
1562
  return rules;
1411
1563
  });
1412
1564
  };
@@ -1565,6 +1717,11 @@ const applyOutputDefaults = (
1565
1717
  () =>
1566
1718
  tp && optimistic(/** @type {boolean | undefined} */ (tp.asyncFunction))
1567
1719
  );
1720
+ F(
1721
+ environment,
1722
+ "generator",
1723
+ () => tp && optimistic(/** @type {boolean | undefined} */ (tp.generator))
1724
+ );
1568
1725
  F(
1569
1726
  environment,
1570
1727
  "forOf",
@@ -1639,6 +1796,30 @@ const applyOutputDefaults = (
1639
1796
  "document",
1640
1797
  () => tp && optimistic(/** @type {boolean | undefined} */ (tp.document))
1641
1798
  );
1799
+ F(
1800
+ environment,
1801
+ "modulePreload",
1802
+ () =>
1803
+ tp && optimistic(/** @type {boolean | undefined} */ (tp.modulePreload))
1804
+ );
1805
+
1806
+ // Vite-style default for ESM output (`output.module`): preload the entry's
1807
+ // initial dependency graph, which native `import()` would otherwise fetch in
1808
+ // a waterfall. Classic output loads initial chunks via parallel `<script>`
1809
+ // tags (no waterfall), so it stays opt-in.
1810
+ if (output.module && output.resourceHints === undefined) {
1811
+ output.resourceHints = {};
1812
+ }
1813
+ if (output.resourceHints) {
1814
+ if (output.module) D(output.resourceHints, "initial", true);
1815
+ // `modulePreloadPolyfill` defaults from the target's modulepreload
1816
+ // support: inject the polyfill iff the environment lacks it.
1817
+ D(
1818
+ output.resourceHints,
1819
+ "modulePreloadPolyfill",
1820
+ !environment.modulePreload
1821
+ );
1822
+ }
1642
1823
 
1643
1824
  D(output, "filename", output.module ? "[name].mjs" : "[name].js");
1644
1825
  F(output, "iife", () => !output.module);
@@ -1718,6 +1899,8 @@ const applyOutputDefaults = (
1718
1899
  D(output, "html", false);
1719
1900
  D(output, "assetModuleFilename", "[hash][ext][query][fragment]");
1720
1901
  D(output, "webassemblyModuleFilename", "[hash].module.wasm");
1902
+ // On by default like other wasm toolchains; set false to drop the fallback runtime code.
1903
+ D(output, "wasmStreamingFallback", true);
1721
1904
  D(output, "compareBeforeEmit", true);
1722
1905
  D(output, "charset", !futureDefaults);
1723
1906
  const uniqueNameId = Template.toIdentifier(
@@ -1863,7 +2046,9 @@ const applyOutputDefaults = (
1863
2046
  D(
1864
2047
  output,
1865
2048
  "hotUpdateMainFilename",
1866
- `[runtime].[fullhash].hot-update.${output.module ? "json.mjs" : "json"}`
2049
+ // Only `chunkLoading: "import"` loads the manifest via `import()` (needs an
2050
+ // `export default` ES module); every other loader fetches it as raw JSON.
2051
+ `[runtime].[fullhash].hot-update.${output.chunkLoading === "import" ? "json.mjs" : "json"}`
1867
2052
  );
1868
2053
  D(output, "crossOriginLoading", false);
1869
2054
  F(output, "scriptType", () => (output.module ? "module" : false));
@@ -2255,6 +2440,7 @@ const applyOptimizationDefaults = (
2255
2440
  * @param {Mode} options.mode mode
2256
2441
  * @param {boolean} options.css is css enabled
2257
2442
  * @param {boolean} options.html is html enabled
2443
+ * @param {boolean} options.htmlFirst whether `.html` should outrank `.js` when resolving (only when html was explicitly enabled)
2258
2444
  * @param {boolean} options.typescript is typescript enabled
2259
2445
  * @returns {ResolveOptions} resolve options
2260
2446
  */
@@ -2265,6 +2451,7 @@ const getResolveDefaults = ({
2265
2451
  mode,
2266
2452
  css,
2267
2453
  html,
2454
+ htmlFirst,
2268
2455
  typescript
2269
2456
  }) => {
2270
2457
  /** @type {string[]} */
@@ -2286,10 +2473,13 @@ const getResolveDefaults = ({
2286
2473
  ? [".ts", ".js", ".json", ".wasm"]
2287
2474
  : [".js", ".json", ".wasm"];
2288
2475
 
2289
- // HTML-first when enabled: `.html` outranks `.js`, `.css` is the last fallback.
2476
+ // Explicitly enabling html keeps `.html` ahead of `.js` (html-as-entry feature).
2477
+ // Auto-enabled html/css are lower-priority fallbacks after `.js`, so enabling
2478
+ // them by default never makes `x.html`/`x.css` shadow `x.js`.
2290
2479
  const esmResolveExtensions = [
2291
- ...(html ? [".html"] : []),
2480
+ ...(html && htmlFirst ? [".html"] : []),
2292
2481
  ...jsExtensions,
2482
+ ...(html && !htmlFirst ? [".html"] : []),
2293
2483
  ...(css ? [".css"] : [])
2294
2484
  ];
2295
2485
 
@@ -133,6 +133,30 @@ const keyedNestedConfig = (value, fn, customKeys) => {
133
133
  return result;
134
134
  };
135
135
 
136
+ /**
137
+ * Normalize `output.resourceHints` into its object form: the scalar / array /
138
+ * function shorthand becomes `{ initial: <value> }` (with `"preload"` aliased to
139
+ * `true`); an object is passed through, its `initial` getting the same alias.
140
+ * @param {import("../../declarations/WebpackOptions").ResourceHints=} resourceHints raw value
141
+ * @returns {import("../../declarations/WebpackOptions").ResourceHintsOptions | undefined} normalized object form
142
+ */
143
+ const normalizeResourceHints = (resourceHints) => {
144
+ if (resourceHints === undefined) return undefined;
145
+ /**
146
+ * @param {import("../../declarations/WebpackOptions").ResourceHintsInitial=} value initial value
147
+ * @returns {import("../../declarations/WebpackOptions").ResourceHintsInitial | undefined} `"preload"` aliased to `true`
148
+ */
149
+ const alias = (value) => (value === "preload" ? true : value);
150
+ if (
151
+ typeof resourceHints === "object" &&
152
+ !Array.isArray(resourceHints) &&
153
+ typeof resourceHints !== "function"
154
+ ) {
155
+ return { ...resourceHints, initial: alias(resourceHints.initial) };
156
+ }
157
+ return { initial: alias(resourceHints) };
158
+ };
159
+
136
160
  /**
137
161
  * Gets normalized webpack options.
138
162
  * @param {WebpackOptions} config input config
@@ -404,6 +428,7 @@ const getNormalizedWebpackOptions = (config) => ({
404
428
  path: output.path,
405
429
  pathinfo: output.pathinfo,
406
430
  publicPath: output.publicPath,
431
+ resourceHints: normalizeResourceHints(output.resourceHints),
407
432
  sourceMapFilename: output.sourceMapFilename,
408
433
  sourcePrefix: output.sourcePrefix,
409
434
  strictModuleErrorHandling: output.strictModuleErrorHandling,
@@ -421,6 +446,7 @@ const getNormalizedWebpackOptions = (config) => ({
421
446
  ),
422
447
  uniqueName: output.uniqueName,
423
448
  wasmLoading: output.wasmLoading,
449
+ wasmStreamingFallback: output.wasmStreamingFallback,
424
450
  webassemblyModuleFilename: output.webassemblyModuleFilename,
425
451
  workerPublicPath: output.workerPublicPath,
426
452
  workerChunkFilename: output.workerChunkFilename,
@@ -52,6 +52,7 @@ const getDefaultTarget = (context) => {
52
52
  * @property {boolean | null} nodeBuiltinModuleGetter node.js exposes `process.getBuiltinModule()` to synchronously load core modules
53
53
  * @property {boolean | null} importMetaDirnameAndFilename node.js allows to use `import.meta.dirname` and `import.meta.filename`
54
54
  * @property {boolean | null} document has document available (allows script tags)
55
+ * @property {(boolean | null)=} modulePreload supports `<link rel="modulepreload">` (optional; absent means "assume supported")
55
56
  * @property {boolean | null} importScripts has importScripts available
56
57
  * @property {boolean | null} importScriptsInWorker has importScripts available when creating a worker
57
58
  * @property {boolean | null} fetchWasm has fetch function available for WebAssembly
@@ -79,6 +80,7 @@ const getDefaultTarget = (context) => {
79
80
  * @property {boolean | null} spread spread and rest in array/object literals and calls is available
80
81
  * @property {boolean | null} templateLiteral template literal is available
81
82
  * @property {boolean | null} asyncFunction async functions and await are available
83
+ * @property {boolean | null} generator generator functions and yield are available
82
84
  */
83
85
 
84
86
  /**
@@ -259,6 +261,7 @@ You can also more options via the 'target' option: 'browserslist' / 'browserslis
259
261
  methodShorthand: v(4),
260
262
  arrowFunction: v(6),
261
263
  asyncFunction: v(7, 6),
264
+ generator: v(4),
262
265
  forOf: v(5),
263
266
  destructuring: v(6),
264
267
  bigIntLiteral: v(10, 4),
@@ -315,7 +318,8 @@ You can also more options via the 'target' option: 'browserslist' / 'browserslis
315
318
  optionalChaining: true,
316
319
  spread: true,
317
320
  templateLiteral: true,
318
- asyncFunction: true
321
+ asyncFunction: true,
322
+ generator: true
319
323
  };
320
324
  }
321
325
  ],
@@ -362,6 +366,7 @@ You can also more options via the 'target' option: 'browserslist' / 'browserslis
362
366
  methodShorthand: true,
363
367
  arrowFunction: true,
364
368
  asyncFunction: true,
369
+ generator: true,
365
370
  forOf: true,
366
371
  destructuring: true,
367
372
  bigIntLiteral: true,
@@ -418,6 +423,7 @@ You can also more options via the 'target' option: 'browserslist' / 'browserslis
418
423
  methodShorthand: v(1, 1),
419
424
  arrowFunction: v(1, 1),
420
425
  asyncFunction: v(1, 7),
426
+ generator: v(1, 1),
421
427
  forOf: v(0, 36),
422
428
  destructuring: v(1, 1),
423
429
  bigIntLiteral: v(4),
@@ -466,6 +472,7 @@ You can also more options via the 'target' option: 'browserslist' / 'browserslis
466
472
  methodShorthand: v(0, 15),
467
473
  arrowFunction: v(0, 15),
468
474
  asyncFunction: v(0, 21),
475
+ generator: v(0, 15),
469
476
  forOf: v(0, 13),
470
477
  destructuring: v(0, 15),
471
478
  bigIntLiteral: v(0, 32),
@@ -495,6 +502,7 @@ You can also more options via the 'target' option: 'browserslist' / 'browserslis
495
502
  destructuring: v >= 2015,
496
503
  module: v >= 2015,
497
504
  asyncFunction: v >= 2017,
505
+ generator: v >= 2015,
498
506
  globalThis: v >= 2020,
499
507
  symbol: v >= 2015,
500
508
  hasOwn: v >= 2022,
@@ -402,20 +402,28 @@ class CssGenerator extends Generator {
402
402
  return new RawSource("");
403
403
  }
404
404
 
405
+ const exportsInfo =
406
+ generateContext.moduleGraph.getExportsInfo(module);
407
+
408
+ /**
409
+ * @param {string} name export name
410
+ * @returns {string | false} used export name when the export is referenced
411
+ */
412
+ const getUsedExportName = (name) =>
413
+ /** @type {string | false} */ (
414
+ exportsInfo
415
+ .getExportInfo(name)
416
+ .getUsedName(name, generateContext.runtime)
417
+ );
418
+
405
419
  if (generateContext.concatenationScope) {
406
420
  const source = new ConcatSource();
407
421
  /** @type {Set<string>} */
408
422
  const usedIdentifiers = new Set();
409
423
  const { RESERVED_IDENTIFIER } = getPropertyName();
410
- const exportsInfo =
411
- generateContext.moduleGraph.getExportsInfo(module);
412
424
 
413
425
  if (defaultExport) {
414
- const usedName = /** @type {string | false} */ (
415
- exportsInfo
416
- .getExportInfo("default")
417
- .getUsedName("default", generateContext.runtime)
418
- );
426
+ const usedName = getUsedExportName("default");
419
427
  if (usedName) {
420
428
  let identifier = Template.toIdentifier(usedName);
421
429
  if (RESERVED_IDENTIFIER.has(identifier)) {
@@ -435,16 +443,8 @@ class CssGenerator extends Generator {
435
443
  }
436
444
 
437
445
  for (const [name, v] of cssData.exports) {
438
- const usedName = /** @type {string | false} */ (
439
- exportsInfo
440
- .getExportInfo(name)
441
- .getUsedName(name, generateContext.runtime)
442
- );
443
- if (!usedName) {
444
- continue;
445
- }
446
-
447
- let identifier = Template.toIdentifier(usedName);
446
+ const usedName = getUsedExportName(name);
447
+ let identifier = Template.toIdentifier(usedName || name);
448
448
  if (RESERVED_IDENTIFIER.has(identifier)) {
449
449
  identifier = `_${identifier}`;
450
450
  }
@@ -469,9 +469,7 @@ class CssGenerator extends Generator {
469
469
 
470
470
  const needNsObj =
471
471
  this._esModule &&
472
- generateContext.moduleGraph
473
- .getExportsInfo(module)
474
- .otherExportsInfo.getUsed(generateContext.runtime) !==
472
+ exportsInfo.otherExportsInfo.getUsed(generateContext.runtime) !==
475
473
  UsageState.Unused;
476
474
 
477
475
  if (needNsObj) {
@@ -483,7 +481,25 @@ class CssGenerator extends Generator {
483
481
  // Should be after `concatenationScope` to allow module inlining
484
482
  generateContext.runtimeRequirements.add(RuntimeGlobals.module);
485
483
 
486
- if (!isCssModule && !needNsObj) {
484
+ const defaultUsedName = defaultExport
485
+ ? getUsedExportName("default")
486
+ : false;
487
+
488
+ /** @type {string[]} */
489
+ const exportEntries = [];
490
+ for (const [name, v] of cssData.exports) {
491
+ const exportKey = getUsedExportName(name) || name;
492
+ exportEntries.push(
493
+ `\t${JSON.stringify(exportKey)}: ${JSON.stringify(v)}`
494
+ );
495
+ }
496
+
497
+ if (
498
+ !isCssModule &&
499
+ !needNsObj &&
500
+ exportEntries.length === 0 &&
501
+ defaultUsedName
502
+ ) {
487
503
  return new ConcatSource(
488
504
  `${module.moduleArgument}.exports = `,
489
505
  /** @type {Source} */ (defaultExport)
@@ -497,21 +513,14 @@ class CssGenerator extends Generator {
497
513
  }.exports = {\n`
498
514
  );
499
515
 
500
- if (defaultExport) {
516
+ if (defaultUsedName) {
501
517
  result.add('\t"default": ');
502
- result.add(defaultExport);
503
- if (cssData.exports.size > 0) {
518
+ result.add(/** @type {Source} */ (defaultExport));
519
+ if (exportEntries.length > 0) {
504
520
  result.add(",\n");
505
521
  }
506
522
  }
507
523
 
508
- /** @type {string[]} */
509
- const exportEntries = [];
510
- for (const [name, v] of cssData.exports) {
511
- exportEntries.push(
512
- `\t${JSON.stringify(name)}: ${JSON.stringify(v)}`
513
- );
514
- }
515
524
  if (exportEntries.length > 0) {
516
525
  result.add(exportEntries.join(",\n"));
517
526
  }
@@ -99,7 +99,9 @@ class CssLoadingRuntimeModule extends RuntimeModule {
99
99
  const withPreload =
100
100
  this._runtimeRequirements.has(RuntimeGlobals.preloadChunkHandlers) &&
101
101
  (environment.document || isNeutralPlatform) &&
102
- chunk.hasChildByOrder(chunkGraph, "preload", true, chunkHasCss);
102
+ (chunk.hasChildByOrder(chunkGraph, "preload", true, chunkHasCss) ||
103
+ // `parser.javascript.dynamicImportCssPreload` — CSS-only preload order.
104
+ chunk.hasChildByOrder(chunkGraph, "cssPreload", true, chunkHasCss));
103
105
 
104
106
  const { linkPreload, linkPrefetch, createStylesheet, linkInsert } =
105
107
  CssLoadingRuntimeModule.getCompilationHooks(compilation);
@@ -295,6 +297,7 @@ class CssLoadingRuntimeModule extends RuntimeModule {
295
297
  "error.name = 'ChunkLoadError';",
296
298
  "error.type = errorType;",
297
299
  "error.request = realHref;",
300
+ "error.event = event;",
298
301
  "installedChunkData[1](error);"
299
302
  ]),
300
303
  "} else {",
@@ -548,6 +551,7 @@ class CssLoadingRuntimeModule extends RuntimeModule {
548
551
  "error.name = 'ChunkLoadError';",
549
552
  "error.type = errorType;",
550
553
  "error.request = realHref;",
554
+ "error.event = event;",
551
555
  "reject(error);"
552
556
  ]),
553
557
  "} else {",