webpack 5.89.0 → 5.90.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.

Potentially problematic release.


This version of webpack might be problematic. Click here for more details.

Files changed (148) hide show
  1. package/README.md +3 -0
  2. package/bin/webpack.js +1 -3
  3. package/hot/log.js +0 -2
  4. package/lib/APIPlugin.js +1 -1
  5. package/lib/ChunkGraph.js +1 -1
  6. package/lib/CleanPlugin.js +12 -12
  7. package/lib/Compilation.js +25 -16
  8. package/lib/Compiler.js +13 -0
  9. package/lib/ConcatenationScope.js +2 -2
  10. package/lib/ContextModule.js +4 -4
  11. package/lib/ContextModuleFactory.js +1 -1
  12. package/lib/DependencyTemplate.js +3 -1
  13. package/lib/EnvironmentNotSupportAsyncWarning.js +52 -0
  14. package/lib/EvalDevToolModulePlugin.js +1 -1
  15. package/lib/EvalSourceMapDevToolPlugin.js +1 -1
  16. package/lib/ExportsInfoApiPlugin.js +2 -2
  17. package/lib/ExternalModule.js +47 -12
  18. package/lib/ExternalModuleFactoryPlugin.js +1 -1
  19. package/lib/FileSystemInfo.js +20 -3
  20. package/lib/FlagDependencyExportsPlugin.js +1 -1
  21. package/lib/Generator.js +1 -0
  22. package/lib/HotModuleReplacementPlugin.js +3 -3
  23. package/lib/LibManifestPlugin.js +4 -1
  24. package/lib/Module.js +2 -1
  25. package/lib/ModuleFilenameHelpers.js +1 -1
  26. package/lib/ModuleInfoHeaderPlugin.js +1 -1
  27. package/lib/MultiStats.js +2 -2
  28. package/lib/NodeStuffPlugin.js +48 -0
  29. package/lib/NormalModule.js +13 -11
  30. package/lib/NormalModuleFactory.js +7 -7
  31. package/lib/RuntimeTemplate.js +15 -11
  32. package/lib/SourceMapDevToolPlugin.js +2 -2
  33. package/lib/WebpackOptionsApply.js +4 -3
  34. package/lib/asset/AssetModulesPlugin.js +2 -3
  35. package/lib/cache/AddManagedPathsPlugin.js +6 -1
  36. package/lib/cache/IdleFileCachePlugin.js +12 -5
  37. package/lib/cache/PackFileCacheStrategy.js +3 -3
  38. package/lib/cache/ResolverCachePlugin.js +2 -2
  39. package/lib/config/browserslistTargetHandler.js +24 -5
  40. package/lib/config/defaults.js +87 -52
  41. package/lib/config/normalization.js +17 -18
  42. package/lib/config/target.js +5 -0
  43. package/lib/container/ContainerReferencePlugin.js +1 -1
  44. package/lib/css/CssExportsGenerator.js +14 -1
  45. package/lib/css/CssGenerator.js +14 -1
  46. package/lib/css/CssLoadingRuntimeModule.js +23 -23
  47. package/lib/css/CssModulesPlugin.js +68 -32
  48. package/lib/css/CssParser.js +8 -3
  49. package/lib/debug/ProfilingPlugin.js +2 -2
  50. package/lib/dependencies/CachedConstDependency.js +8 -1
  51. package/lib/dependencies/CommonJsImportsParserPlugin.js +1 -1
  52. package/lib/dependencies/ContextElementDependency.js +1 -1
  53. package/lib/dependencies/ExternalModuleDependency.js +98 -0
  54. package/lib/dependencies/ExternalModuleInitFragment.js +124 -0
  55. package/lib/dependencies/HarmonyAcceptDependency.js +1 -1
  56. package/lib/dependencies/HarmonyDetectionParserPlugin.js +7 -1
  57. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +18 -18
  58. package/lib/dependencies/HarmonyExportInitFragment.js +4 -4
  59. package/lib/dependencies/HarmonyImportDependency.js +4 -4
  60. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +6 -6
  61. package/lib/dependencies/ImportDependency.js +26 -6
  62. package/lib/dependencies/JsonExportsDependency.js +1 -1
  63. package/lib/dependencies/LoaderPlugin.js +2 -1
  64. package/lib/dependencies/PureExpressionDependency.js +12 -4
  65. package/lib/dependencies/RequireIncludeDependency.js +1 -1
  66. package/lib/dependencies/WebpackIsIncludedDependency.js +1 -1
  67. package/lib/dependencies/WorkerPlugin.js +7 -1
  68. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +6 -6
  69. package/lib/hmr/HotModuleReplacement.runtime.js +3 -5
  70. package/lib/hmr/lazyCompilationBackend.js +4 -4
  71. package/lib/ids/DeterministicModuleIdsPlugin.js +1 -1
  72. package/lib/index.js +4 -0
  73. package/lib/javascript/JavascriptGenerator.js +16 -1
  74. package/lib/javascript/JavascriptModulesPlugin.js +33 -33
  75. package/lib/javascript/JavascriptParser.js +8 -0
  76. package/lib/json/JsonGenerator.js +1 -1
  77. package/lib/library/AmdLibraryPlugin.js +5 -1
  78. package/lib/library/AssignLibraryPlugin.js +1 -1
  79. package/lib/library/SystemLibraryPlugin.js +1 -1
  80. package/lib/library/UmdLibraryPlugin.js +39 -39
  81. package/lib/logging/createConsoleLogger.js +1 -19
  82. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +8 -8
  83. package/lib/node/RequireChunkLoadingRuntimeModule.js +8 -8
  84. package/lib/node/nodeConsole.js +1 -5
  85. package/lib/optimize/ConcatenatedModule.js +7 -7
  86. package/lib/optimize/InnerGraphPlugin.js +9 -1
  87. package/lib/optimize/ModuleConcatenationPlugin.js +2 -2
  88. package/lib/optimize/RemoveParentModulesPlugin.js +123 -47
  89. package/lib/optimize/SideEffectsFlagPlugin.js +15 -3
  90. package/lib/optimize/SplitChunksPlugin.js +16 -16
  91. package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +2 -2
  92. package/lib/rules/RuleSetCompiler.js +1 -1
  93. package/lib/runtime/AutoPublicPathRuntimeModule.js +2 -2
  94. package/lib/runtime/GetChunkFilenameRuntimeModule.js +4 -4
  95. package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +4 -4
  96. package/lib/runtime/LoadScriptRuntimeModule.js +2 -2
  97. package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +23 -22
  98. package/lib/runtime/StartupEntrypointRuntimeModule.js +2 -2
  99. package/lib/schemes/HttpUriPlugin.js +1 -1
  100. package/lib/serialization/FileMiddleware.js +4 -4
  101. package/lib/serialization/ObjectMiddleware.js +4 -4
  102. package/lib/sharing/ConsumeSharedPlugin.js +5 -5
  103. package/lib/sharing/ConsumeSharedRuntimeModule.js +8 -4
  104. package/lib/sharing/ProvideSharedModule.js +2 -2
  105. package/lib/sharing/SharePlugin.js +2 -2
  106. package/lib/sharing/ShareRuntimeModule.js +1 -1
  107. package/lib/sharing/utils.js +24 -28
  108. package/lib/stats/DefaultStatsFactoryPlugin.js +10 -10
  109. package/lib/stats/DefaultStatsPresetPlugin.js +3 -7
  110. package/lib/stats/DefaultStatsPrinterPlugin.js +34 -31
  111. package/lib/util/cleverMerge.js +4 -4
  112. package/lib/util/hash/xxhash64.js +2 -2
  113. package/lib/util/identifier.js +2 -2
  114. package/lib/util/internalSerializables.js +6 -0
  115. package/lib/util/runtime.js +18 -1
  116. package/lib/util/semver.js +19 -24
  117. package/lib/util/smartGrouping.js +1 -1
  118. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +1 -1
  119. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +2 -2
  120. package/lib/wasm-async/AsyncWebAssemblyParser.js +6 -0
  121. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +2 -2
  122. package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +2 -2
  123. package/lib/web/JsonpChunkLoadingRuntimeModule.js +13 -13
  124. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +6 -6
  125. package/package.json +23 -23
  126. package/schemas/WebpackOptions.check.js +1 -1
  127. package/schemas/WebpackOptions.json +140 -32
  128. package/schemas/plugins/css/CssAutoGeneratorOptions.check.d.ts +7 -0
  129. package/schemas/plugins/css/CssAutoGeneratorOptions.check.js +6 -0
  130. package/schemas/plugins/css/CssAutoGeneratorOptions.json +3 -0
  131. package/schemas/plugins/css/CssAutoParserOptions.check.d.ts +7 -0
  132. package/schemas/plugins/css/CssAutoParserOptions.check.js +6 -0
  133. package/schemas/plugins/css/CssAutoParserOptions.json +3 -0
  134. package/schemas/plugins/css/CssGeneratorOptions.check.js +1 -1
  135. package/schemas/plugins/css/CssGlobalGeneratorOptions.check.d.ts +7 -0
  136. package/schemas/plugins/css/CssGlobalGeneratorOptions.check.js +6 -0
  137. package/schemas/plugins/css/CssGlobalGeneratorOptions.json +3 -0
  138. package/schemas/plugins/css/CssGlobalParserOptions.check.d.ts +7 -0
  139. package/schemas/plugins/css/CssGlobalParserOptions.check.js +6 -0
  140. package/schemas/plugins/css/CssGlobalParserOptions.json +3 -0
  141. package/schemas/plugins/css/CssModuleGeneratorOptions.check.d.ts +7 -0
  142. package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +6 -0
  143. package/schemas/plugins/css/CssModuleGeneratorOptions.json +3 -0
  144. package/schemas/plugins/css/CssModuleParserOptions.check.d.ts +7 -0
  145. package/schemas/plugins/css/CssModuleParserOptions.check.js +6 -0
  146. package/schemas/plugins/css/CssModuleParserOptions.json +3 -0
  147. package/schemas/plugins/css/CssParserOptions.check.js +1 -1
  148. package/types.d.ts +172 -20
@@ -29,7 +29,8 @@ const {
29
29
 
30
30
  /** @typedef {import("../../declarations/WebpackOptions").CacheOptionsNormalized} CacheOptions */
31
31
  /** @typedef {import("../../declarations/WebpackOptions").Context} Context */
32
- /** @typedef {import("../../declarations/WebpackOptions").CssExperimentOptions} CssExperimentOptions */
32
+ /** @typedef {import("../../declarations/WebpackOptions").CssGeneratorOptions} CssGeneratorOptions */
33
+ /** @typedef {import("../../declarations/WebpackOptions").CssParserOptions} CssParserOptions */
33
34
  /** @typedef {import("../../declarations/WebpackOptions").EntryDescription} EntryDescription */
34
35
  /** @typedef {import("../../declarations/WebpackOptions").EntryNormalized} Entry */
35
36
  /** @typedef {import("../../declarations/WebpackOptions").EntryStaticNormalized} EntryStaticNormalized */
@@ -39,6 +40,7 @@ const {
39
40
  /** @typedef {import("../../declarations/WebpackOptions").ExternalsPresets} ExternalsPresets */
40
41
  /** @typedef {import("../../declarations/WebpackOptions").ExternalsType} ExternalsType */
41
42
  /** @typedef {import("../../declarations/WebpackOptions").FileCacheOptions} FileCacheOptions */
43
+ /** @typedef {import("../../declarations/WebpackOptions").GeneratorOptionsByModuleTypeKnown} GeneratorOptionsByModuleTypeKnown */
42
44
  /** @typedef {import("../../declarations/WebpackOptions").InfrastructureLogging} InfrastructureLogging */
43
45
  /** @typedef {import("../../declarations/WebpackOptions").JavascriptParserOptions} JavascriptParserOptions */
44
46
  /** @typedef {import("../../declarations/WebpackOptions").Library} Library */
@@ -159,11 +161,11 @@ const applyWebpackOptionsDefaults = options => {
159
161
  target === false
160
162
  ? /** @type {false} */ (false)
161
163
  : typeof target === "string"
162
- ? getTargetProperties(target, /** @type {Context} */ (options.context))
163
- : getTargetsProperties(
164
- /** @type {string[]} */ (target),
165
- /** @type {Context} */ (options.context)
166
- );
164
+ ? getTargetProperties(target, /** @type {Context} */ (options.context))
165
+ : getTargetsProperties(
166
+ /** @type {string[]} */ (target),
167
+ /** @type {Context} */ (options.context)
168
+ );
167
169
 
168
170
  const development = mode === "development";
169
171
  const production = mode === "production" || !mode;
@@ -223,7 +225,8 @@ const applyWebpackOptionsDefaults = options => {
223
225
  /** @type {NonNullable<ExperimentsNormalized["css"]>} */
224
226
  (options.experiments.css),
225
227
  futureDefaults,
226
- isNode: targetProperties && targetProperties.node === true
228
+ isNode: targetProperties && targetProperties.node === true,
229
+ targetProperties
227
230
  });
228
231
 
229
232
  applyOutputDefaults(options.output, {
@@ -260,14 +263,15 @@ const applyWebpackOptionsDefaults = options => {
260
263
  validExternalTypes.includes(options.output.library.type)
261
264
  ? /** @type {ExternalsType} */ (options.output.library.type)
262
265
  : options.output.module
263
- ? "module"
264
- : "var";
266
+ ? "module"
267
+ : "var";
265
268
  });
266
269
 
267
270
  applyNodeDefaults(options.node, {
268
271
  futureDefaults:
269
272
  /** @type {NonNullable<WebpackOptions["experiments"]["futureDefaults"]>} */
270
273
  (options.experiments.futureDefaults),
274
+ outputModule: options.output.module,
271
275
  targetProperties
272
276
  });
273
277
 
@@ -335,7 +339,7 @@ const applyExperimentsDefaults = (
335
339
  D(experiments, "lazyCompilation", undefined);
336
340
  D(experiments, "buildHttp", undefined);
337
341
  D(experiments, "cacheUnaffected", experiments.futureDefaults);
338
- F(experiments, "css", () => (experiments.futureDefaults ? {} : undefined));
342
+ F(experiments, "css", () => (experiments.futureDefaults ? true : undefined));
339
343
 
340
344
  // TODO webpack 6: remove this. topLevelAwait should be enabled by default
341
345
  let shouldEnableTopLevelAwait = true;
@@ -348,14 +352,6 @@ const applyExperimentsDefaults = (
348
352
  D(experiments.buildHttp, "frozen", production);
349
353
  D(experiments.buildHttp, "upgrade", false);
350
354
  }
351
-
352
- if (typeof experiments.css === "object") {
353
- D(
354
- experiments.css,
355
- "exportsOnly",
356
- !targetProperties || !targetProperties.document
357
- );
358
- }
359
355
  };
360
356
 
361
357
  /**
@@ -448,7 +444,7 @@ const applySnapshotDefaults = (snapshot, { production, futureDefaults }) => {
448
444
  process.versions.pnp === "3"
449
445
  ? [
450
446
  /^(.+?(?:[\\/]\.yarn[\\/]unplugged[\\/][^\\/]+)?[\\/]node_modules[\\/])/
451
- ]
447
+ ]
452
448
  : [/^(.+?[\\/]node_modules[\\/])/]
453
449
  );
454
450
  F(snapshot, "immutablePaths", () =>
@@ -468,7 +464,6 @@ const applySnapshotDefaults = (snapshot, { production, futureDefaults }) => {
468
464
  }
469
465
  } else {
470
466
  const match = /^(.+?[\\/]node_modules[\\/])/.exec(
471
- // eslint-disable-next-line node/no-extraneous-require
472
467
  require.resolve("watchpack")
473
468
  );
474
469
  if (match) {
@@ -543,20 +538,46 @@ const applyJavascriptParserOptionsDefaults = (
543
538
  if (futureDefaults) D(parserOptions, "exportsPresence", "error");
544
539
  };
545
540
 
541
+ /**
542
+ * @param {CssGeneratorOptions} generatorOptions generator options
543
+ * @param {Object} options options
544
+ * @param {TargetProperties | false} options.targetProperties target properties
545
+ * @returns {void}
546
+ */
547
+ const applyCssGeneratorOptionsDefaults = (
548
+ generatorOptions,
549
+ { targetProperties }
550
+ ) => {
551
+ D(
552
+ generatorOptions,
553
+ "exportsOnly",
554
+ !targetProperties || !targetProperties.document
555
+ );
556
+ };
557
+
546
558
  /**
547
559
  * @param {ModuleOptions} module options
548
560
  * @param {Object} options options
549
561
  * @param {boolean} options.cache is caching enabled
550
562
  * @param {boolean} options.syncWebAssembly is syncWebAssembly enabled
551
563
  * @param {boolean} options.asyncWebAssembly is asyncWebAssembly enabled
552
- * @param {CssExperimentOptions|false} options.css is css enabled
564
+ * @param {boolean} options.css is css enabled
553
565
  * @param {boolean} options.futureDefaults is future defaults enabled
554
566
  * @param {boolean} options.isNode is node target platform
567
+ * @param {TargetProperties | false} options.targetProperties target properties
555
568
  * @returns {void}
556
569
  */
557
570
  const applyModuleDefaults = (
558
571
  module,
559
- { cache, syncWebAssembly, asyncWebAssembly, css, futureDefaults, isNode }
572
+ {
573
+ cache,
574
+ syncWebAssembly,
575
+ asyncWebAssembly,
576
+ css,
577
+ futureDefaults,
578
+ isNode,
579
+ targetProperties
580
+ }
560
581
  ) => {
561
582
  if (cache) {
562
583
  D(
@@ -607,6 +628,20 @@ const applyModuleDefaults = (
607
628
  }
608
629
  );
609
630
 
631
+ if (css) {
632
+ F(module.parser, "css", () => ({}));
633
+
634
+ D(module.parser.css, "namedExports", true);
635
+
636
+ F(module.generator, "css", () => ({}));
637
+
638
+ applyCssGeneratorOptionsDefaults(
639
+ /** @type {NonNullable<GeneratorOptionsByModuleTypeKnown["css"]>} */
640
+ (module.generator.css),
641
+ { targetProperties }
642
+ );
643
+ }
644
+
610
645
  A(module, "defaultRules", () => {
611
646
  const esm = {
612
647
  type: JAVASCRIPT_MODULE_TYPE_ESM,
@@ -818,9 +853,8 @@ const applyOutputDefaults = (
818
853
  } catch (e) {
819
854
  if (/** @type {Error & { code: string }} */ (e).code !== "ENOENT") {
820
855
  /** @type {Error & { code: string }} */
821
- (
822
- e
823
- ).message += `\nwhile determining default 'output.uniqueName' from 'name' in ${pkgPath}`;
856
+ (e).message +=
857
+ `\nwhile determining default 'output.uniqueName' from 'name' in ${pkgPath}`;
824
858
  throw e;
825
859
  }
826
860
  return "";
@@ -870,22 +904,11 @@ const applyOutputDefaults = (
870
904
  D(output, "webassemblyModuleFilename", "[hash].module.wasm");
871
905
  D(output, "compareBeforeEmit", true);
872
906
  D(output, "charset", true);
873
- F(output, "hotUpdateGlobal", () =>
874
- Template.toIdentifier(
875
- "webpackHotUpdate" +
876
- Template.toIdentifier(
877
- /** @type {NonNullable<Output["uniqueName"]>} */ (output.uniqueName)
878
- )
879
- )
880
- );
881
- F(output, "chunkLoadingGlobal", () =>
882
- Template.toIdentifier(
883
- "webpackChunk" +
884
- Template.toIdentifier(
885
- /** @type {NonNullable<Output["uniqueName"]>} */ (output.uniqueName)
886
- )
887
- )
907
+ const uniqueNameId = Template.toIdentifier(
908
+ /** @type {NonNullable<Output["uniqueName"]>} */ (output.uniqueName)
888
909
  );
910
+ F(output, "hotUpdateGlobal", () => "webpackHotUpdate" + uniqueNameId);
911
+ F(output, "chunkLoadingGlobal", () => "webpackChunk" + uniqueNameId);
889
912
  F(output, "globalObject", () => {
890
913
  if (tp) {
891
914
  if (tp.global) return "global";
@@ -1014,6 +1037,7 @@ const applyOutputDefaults = (
1014
1037
  D(output, "hashFunction", futureDefaults ? "xxhash64" : "md4");
1015
1038
  D(output, "hashDigest", "hex");
1016
1039
  D(output, "hashDigestLength", futureDefaults ? 16 : 20);
1040
+ D(output, "strictModuleErrorHandling", false);
1017
1041
  D(output, "strictModuleExceptionHandling", false);
1018
1042
 
1019
1043
  const environment = /** @type {Environment} */ (output.environment);
@@ -1050,6 +1074,12 @@ const applyOutputDefaults = (
1050
1074
  () =>
1051
1075
  tp && optimistic(/** @type {boolean | undefined} */ (tp.arrowFunction))
1052
1076
  );
1077
+ F(
1078
+ environment,
1079
+ "asyncFunction",
1080
+ () =>
1081
+ tp && optimistic(/** @type {boolean | undefined} */ (tp.asyncFunction))
1082
+ );
1053
1083
  F(
1054
1084
  environment,
1055
1085
  "forOf",
@@ -1256,9 +1286,13 @@ const applyLoaderDefaults = (loader, { targetProperties, environment }) => {
1256
1286
  * @param {Object} options options
1257
1287
  * @param {TargetProperties | false} options.targetProperties target properties
1258
1288
  * @param {boolean} options.futureDefaults is future defaults enabled
1289
+ * @param {boolean} options.outputModule is output type is module
1259
1290
  * @returns {void}
1260
1291
  */
1261
- const applyNodeDefaults = (node, { futureDefaults, targetProperties }) => {
1292
+ const applyNodeDefaults = (
1293
+ node,
1294
+ { futureDefaults, outputModule, targetProperties }
1295
+ ) => {
1262
1296
  if (node === false) return;
1263
1297
 
1264
1298
  F(node, "global", () => {
@@ -1266,16 +1300,16 @@ const applyNodeDefaults = (node, { futureDefaults, targetProperties }) => {
1266
1300
  // TODO webpack 6 should always default to false
1267
1301
  return futureDefaults ? "warn" : true;
1268
1302
  });
1269
- F(node, "__filename", () => {
1270
- if (targetProperties && targetProperties.node) return "eval-only";
1271
- // TODO webpack 6 should always default to false
1272
- return futureDefaults ? "warn-mock" : "mock";
1273
- });
1274
- F(node, "__dirname", () => {
1275
- if (targetProperties && targetProperties.node) return "eval-only";
1303
+
1304
+ const handlerForNames = () => {
1305
+ if (targetProperties && targetProperties.node)
1306
+ return outputModule ? "node-module" : "eval-only";
1276
1307
  // TODO webpack 6 should always default to false
1277
1308
  return futureDefaults ? "warn-mock" : "mock";
1278
- });
1309
+ };
1310
+
1311
+ F(node, "__filename", handlerForNames);
1312
+ F(node, "__dirname", handlerForNames);
1279
1313
  };
1280
1314
 
1281
1315
  /**
@@ -1296,7 +1330,7 @@ const applyPerformanceDefaults = (performance, { production }) => {
1296
1330
  * @param {Object} options options
1297
1331
  * @param {boolean} options.production is production
1298
1332
  * @param {boolean} options.development is development
1299
- * @param {CssExperimentOptions|false} options.css is css enabled
1333
+ * @param {boolean} options.css is css enabled
1300
1334
  * @param {boolean} options.records using records
1301
1335
  * @returns {void}
1302
1336
  */
@@ -1390,7 +1424,7 @@ const applyOptimizationDefaults = (
1390
1424
  * @param {string} options.context build context
1391
1425
  * @param {TargetProperties | false} options.targetProperties target properties
1392
1426
  * @param {Mode} options.mode mode
1393
- * @param {CssExperimentOptions|false} options.css is css enabled
1427
+ * @param {boolean} options.css is css enabled
1394
1428
  * @returns {ResolveOptions} resolve options
1395
1429
  */
1396
1430
  const getResolveDefaults = ({
@@ -1481,7 +1515,8 @@ const getResolveDefaults = ({
1481
1515
  mainFiles: [],
1482
1516
  mainFields: ["style", "..."],
1483
1517
  conditionNames: styleConditions,
1484
- extensions: [".css"]
1518
+ extensions: [".css"],
1519
+ preferRelative: true
1485
1520
  };
1486
1521
  }
1487
1522
 
@@ -109,7 +109,7 @@ const keyedNestedConfig = (value, fn, customKeys) => {
109
109
  obj
110
110
  ),
111
111
  /** @type {Record<string, R>} */ ({})
112
- );
112
+ );
113
113
  if (customKeys) {
114
114
  for (const key of Object.keys(customKeys)) {
115
115
  if (!(key in result)) {
@@ -175,19 +175,20 @@ const getNormalizedWebpackOptions = config => {
175
175
  ),
176
176
  context: config.context,
177
177
  dependencies: config.dependencies,
178
- devServer: optionalNestedConfig(config.devServer, devServer => ({
179
- ...devServer
180
- })),
178
+ devServer: optionalNestedConfig(config.devServer, devServer => {
179
+ if (devServer === false) return false;
180
+ return { ...devServer };
181
+ }),
181
182
  devtool: config.devtool,
182
183
  entry:
183
184
  config.entry === undefined
184
185
  ? { main: {} }
185
186
  : typeof config.entry === "function"
186
- ? (
187
- fn => () =>
188
- Promise.resolve().then(fn).then(getNormalizedEntryStatic)
189
- )(config.entry)
190
- : getNormalizedEntryStatic(config.entry),
187
+ ? (
188
+ fn => () =>
189
+ Promise.resolve().then(fn).then(getNormalizedEntryStatic)
190
+ )(config.entry)
191
+ : getNormalizedEntryStatic(config.entry),
191
192
  experiments: nestedConfig(config.experiments, experiments => ({
192
193
  ...experiments,
193
194
  buildHttp: optionalNestedConfig(experiments.buildHttp, options =>
@@ -196,9 +197,6 @@ const getNormalizedWebpackOptions = config => {
196
197
  lazyCompilation: optionalNestedConfig(
197
198
  experiments.lazyCompilation,
198
199
  options => (options === true ? {} : options)
199
- ),
200
- css: optionalNestedConfig(experiments.css, options =>
201
- options === true ? {} : options
202
200
  )
203
201
  })),
204
202
  externals: /** @type {NonNullable<Externals>} */ (config.externals),
@@ -227,7 +225,7 @@ const getNormalizedWebpackOptions = config => {
227
225
  }
228
226
  return true;
229
227
  };
230
- })
228
+ })
231
229
  : undefined,
232
230
  infrastructureLogging: cloneObject(config.infrastructureLogging),
233
231
  loader: cloneObject(config.loader),
@@ -292,7 +290,7 @@ const getNormalizedWebpackOptions = config => {
292
290
  ? handledDeprecatedNoEmitOnErrors(
293
291
  optimization.noEmitOnErrors,
294
292
  optimization.emitOnErrors
295
- )
293
+ )
296
294
  : optimization.emitOnErrors
297
295
  };
298
296
  }),
@@ -306,10 +304,10 @@ const getNormalizedWebpackOptions = config => {
306
304
  "type" in library
307
305
  ? library
308
306
  : libraryAsName || output.libraryTarget
309
- ? /** @type {LibraryOptions} */ ({
310
- name: libraryAsName
311
- })
312
- : undefined;
307
+ ? /** @type {LibraryOptions} */ ({
308
+ name: libraryAsName
309
+ })
310
+ : undefined;
313
311
  /** @type {OutputNormalized} */
314
312
  const result = {
315
313
  assetModuleFilename: output.assetModuleFilename,
@@ -382,6 +380,7 @@ const getNormalizedWebpackOptions = config => {
382
380
  publicPath: output.publicPath,
383
381
  sourceMapFilename: output.sourceMapFilename,
384
382
  sourcePrefix: output.sourcePrefix,
383
+ strictModuleErrorHandling: output.strictModuleErrorHandling,
385
384
  strictModuleExceptionHandling: output.strictModuleExceptionHandling,
386
385
  trustedTypes: optionalNestedConfig(
387
386
  output.trustedTypes,
@@ -61,6 +61,7 @@ const getDefaultTarget = context => {
61
61
  * @property {boolean | null} module ESM syntax is available (when in module)
62
62
  * @property {boolean | null} optionalChaining optional chaining is available
63
63
  * @property {boolean | null} templateLiteral template literal is available
64
+ * @property {boolean | null} asyncFunction async functions and await are available
64
65
  */
65
66
 
66
67
  ///** @typedef {PlatformTargetProperties | ApiTargetProperties | EcmaTargetProperties | PlatformTargetProperties & ApiTargetProperties | PlatformTargetProperties & EcmaTargetProperties | ApiTargetProperties & EcmaTargetProperties} TargetProperties */
@@ -192,6 +193,7 @@ You can also more options via the 'target' option: 'browserslist' / 'browserslis
192
193
  templateLiteral: v(4),
193
194
  optionalChaining: v(14),
194
195
  arrowFunction: v(6),
196
+ asyncFunction: v(7, 6),
195
197
  forOf: v(5),
196
198
  destructuring: v(6),
197
199
  bigIntLiteral: v(10, 4),
@@ -233,6 +235,7 @@ You can also more options via the 'target' option: 'browserslist' / 'browserslis
233
235
  templateLiteral: v(1, 1),
234
236
  optionalChaining: v(8),
235
237
  arrowFunction: v(1, 1),
238
+ asyncFunction: v(1, 7),
236
239
  forOf: v(0, 36),
237
240
  destructuring: v(1, 1),
238
241
  bigIntLiteral: v(4),
@@ -270,6 +273,7 @@ You can also more options via the 'target' option: 'browserslist' / 'browserslis
270
273
  templateLiteral: v(0, 13),
271
274
  optionalChaining: v(0, 44),
272
275
  arrowFunction: v(0, 15),
276
+ asyncFunction: v(0, 21),
273
277
  forOf: v(0, 13),
274
278
  destructuring: v(0, 15),
275
279
  bigIntLiteral: v(0, 32),
@@ -294,6 +298,7 @@ You can also more options via the 'target' option: 'browserslist' / 'browserslis
294
298
  forOf: v >= 2015,
295
299
  destructuring: v >= 2015,
296
300
  module: v >= 2015,
301
+ asyncFunction: v >= 2017,
297
302
  globalThis: v >= 2020,
298
303
  bigIntLiteral: v >= 2020,
299
304
  dynamicImport: v >= 2020,
@@ -113,7 +113,7 @@ class ContainerReferencePlugin {
113
113
  ? external.slice(9)
114
114
  : `webpack/container/reference/${key}${
115
115
  i ? `/fallback-${i}` : ""
116
- }`
116
+ }`
117
117
  ),
118
118
  `.${data.request.slice(key.length)}`,
119
119
  config.shareScope
@@ -47,6 +47,7 @@ class CssExportsGenerator extends Generator {
47
47
 
48
48
  generateContext.runtimeRequirements.add(RuntimeGlobals.module);
49
49
 
50
+ let chunkInitFragments;
50
51
  const runtimeRequirements = new Set();
51
52
 
52
53
  const templateContext = {
@@ -60,7 +61,19 @@ class CssExportsGenerator extends Generator {
60
61
  concatenationScope: generateContext.concatenationScope,
61
62
  codeGenerationResults: generateContext.codeGenerationResults,
62
63
  initFragments,
63
- cssExports
64
+ cssExports,
65
+ get chunkInitFragments() {
66
+ if (!chunkInitFragments) {
67
+ const data = generateContext.getData();
68
+ chunkInitFragments = data.get("chunkInitFragments");
69
+ if (!chunkInitFragments) {
70
+ chunkInitFragments = [];
71
+ data.set("chunkInitFragments", chunkInitFragments);
72
+ }
73
+ }
74
+
75
+ return chunkInitFragments;
76
+ }
64
77
  };
65
78
 
66
79
  /**
@@ -38,6 +38,7 @@ class CssGenerator extends Generator {
38
38
 
39
39
  generateContext.runtimeRequirements.add(RuntimeGlobals.hasCssModules);
40
40
 
41
+ let chunkInitFragments;
41
42
  const templateContext = {
42
43
  runtimeTemplate: generateContext.runtimeTemplate,
43
44
  dependencyTemplates: generateContext.dependencyTemplates,
@@ -49,7 +50,19 @@ class CssGenerator extends Generator {
49
50
  concatenationScope: generateContext.concatenationScope,
50
51
  codeGenerationResults: generateContext.codeGenerationResults,
51
52
  initFragments,
52
- cssExports
53
+ cssExports,
54
+ get chunkInitFragments() {
55
+ if (!chunkInitFragments) {
56
+ const data = generateContext.getData();
57
+ chunkInitFragments = data.get("chunkInitFragments");
58
+ if (!chunkInitFragments) {
59
+ chunkInitFragments = [];
60
+ data.set("chunkInitFragments", chunkInitFragments);
61
+ }
62
+ }
63
+
64
+ return chunkInitFragments;
65
+ }
53
66
  };
54
67
 
55
68
  /**
@@ -129,7 +129,7 @@ class CssLoadingRuntimeModule extends RuntimeModule {
129
129
  `link.crossOrigin = ${JSON.stringify(crossOriginLoading)};`
130
130
  ),
131
131
  "}"
132
- ])
132
+ ])
133
133
  : ""
134
134
  ]);
135
135
 
@@ -141,7 +141,7 @@ class CssLoadingRuntimeModule extends RuntimeModule {
141
141
  { expr: "uniqueName" },
142
142
  "-",
143
143
  { expr: "chunkId" }
144
- )
144
+ )
145
145
  : runtimeTemplate.concatenation("--webpack-", { expr: "chunkId" });
146
146
 
147
147
  return Template.asString([
@@ -158,7 +158,7 @@ class CssLoadingRuntimeModule extends RuntimeModule {
158
158
  uniqueName
159
159
  ? `var uniqueName = ${JSON.stringify(
160
160
  runtimeTemplate.outputOptions.uniqueName
161
- )};`
161
+ )};`
162
162
  : "// data-webpack is not used as build has no uniqueName",
163
163
  `var loadCssChunkData = ${runtimeTemplate.basicFunction(
164
164
  "target, link, chunkId",
@@ -210,10 +210,10 @@ class CssLoadingRuntimeModule extends RuntimeModule {
210
210
  { expr: "token" },
211
211
  "-",
212
212
  { expr: "exports[x]" }
213
- )
213
+ )
214
214
  : runtimeTemplate.concatenation({ expr: "token" }, "-", {
215
215
  expr: "exports[x]"
216
- })
216
+ })
217
217
  }`,
218
218
  "x"
219
219
  )}); exportsWithDashes.forEach(${runtimeTemplate.expressionFunction(
@@ -292,18 +292,18 @@ class CssLoadingRuntimeModule extends RuntimeModule {
292
292
  initialChunkIdsWithCss.size > 2
293
293
  ? `${JSON.stringify(
294
294
  Array.from(initialChunkIdsWithCss)
295
- )}.forEach(loadCssChunkData.bind(null, ${
295
+ )}.forEach(loadCssChunkData.bind(null, ${
296
296
  RuntimeGlobals.moduleFactories
297
- }, 0));`
297
+ }, 0));`
298
298
  : initialChunkIdsWithCss.size > 0
299
- ? `${Array.from(
300
- initialChunkIdsWithCss,
301
- id =>
302
- `loadCssChunkData(${
303
- RuntimeGlobals.moduleFactories
304
- }, 0, ${JSON.stringify(id)});`
305
- ).join("")}`
306
- : "// no initial css",
299
+ ? `${Array.from(
300
+ initialChunkIdsWithCss,
301
+ id =>
302
+ `loadCssChunkData(${
303
+ RuntimeGlobals.moduleFactories
304
+ }, 0, ${JSON.stringify(id)});`
305
+ ).join("")}`
306
+ : "// no initial css",
307
307
  "",
308
308
  withLoading
309
309
  ? Template.asString([
@@ -345,11 +345,11 @@ class CssLoadingRuntimeModule extends RuntimeModule {
345
345
  'if(event.type !== "load") {',
346
346
  Template.indent([
347
347
  "var errorType = event && event.type;",
348
- "var realSrc = event && event.target && event.target.src;",
349
- "error.message = 'Loading css chunk ' + chunkId + ' failed.\\n(' + errorType + ': ' + realSrc + ')';",
348
+ "var realHref = event && event.target && event.target.href;",
349
+ "error.message = 'Loading css chunk ' + chunkId + ' failed.\\n(' + errorType + ': ' + realHref + ')';",
350
350
  "error.name = 'ChunkLoadError';",
351
351
  "error.type = errorType;",
352
- "error.request = realSrc;",
352
+ "error.request = realHref;",
353
353
  "installedChunkData[1](error);"
354
354
  ]),
355
355
  "} else {",
@@ -372,7 +372,7 @@ class CssLoadingRuntimeModule extends RuntimeModule {
372
372
  ]),
373
373
  "}"
374
374
  ])};`
375
- ])
375
+ ])
376
376
  : "// no chunk loading",
377
377
  "",
378
378
  withHmr
@@ -435,11 +435,11 @@ class CssLoadingRuntimeModule extends RuntimeModule {
435
435
  'if(event.type !== "load") {',
436
436
  Template.indent([
437
437
  "var errorType = event && event.type;",
438
- "var realSrc = event && event.target && event.target.src;",
439
- "error.message = 'Loading css hot update chunk ' + chunkId + ' failed.\\n(' + errorType + ': ' + realSrc + ')';",
438
+ "var realHref = event && event.target && event.target.href;",
439
+ "error.message = 'Loading css hot update chunk ' + chunkId + ' failed.\\n(' + errorType + ': ' + realHref + ')';",
440
440
  "error.name = 'ChunkLoadError';",
441
441
  "error.type = errorType;",
442
- "error.request = realSrc;",
442
+ "error.request = realHref;",
443
443
  "reject(error);"
444
444
  ]),
445
445
  "} else {",
@@ -464,7 +464,7 @@ class CssLoadingRuntimeModule extends RuntimeModule {
464
464
  ])});`
465
465
  ]
466
466
  )}`
467
- ])
467
+ ])
468
468
  : "// no hmr"
469
469
  ]);
470
470
  }