webpack 5.91.0 → 5.92.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 (174) hide show
  1. package/bin/webpack.js +1 -2
  2. package/lib/APIPlugin.js +6 -2
  3. package/lib/Cache.js +1 -1
  4. package/lib/Chunk.js +7 -4
  5. package/lib/ChunkGraph.js +20 -7
  6. package/lib/ChunkGroup.js +9 -3
  7. package/lib/CleanPlugin.js +1 -1
  8. package/lib/Compilation.js +33 -27
  9. package/lib/Compiler.js +28 -8
  10. package/lib/ConcatenationScope.js +3 -3
  11. package/lib/ContextModule.js +95 -43
  12. package/lib/DefinePlugin.js +14 -4
  13. package/lib/Dependency.js +8 -8
  14. package/lib/DependencyTemplate.js +10 -5
  15. package/lib/DllReferencePlugin.js +1 -1
  16. package/lib/EvalDevToolModulePlugin.js +11 -0
  17. package/lib/ExportsInfo.js +22 -4
  18. package/lib/ExternalModule.js +49 -18
  19. package/lib/FileSystemInfo.js +68 -41
  20. package/lib/FlagDependencyExportsPlugin.js +21 -7
  21. package/lib/Generator.js +2 -3
  22. package/lib/HotModuleReplacementPlugin.js +108 -45
  23. package/lib/IgnorePlugin.js +4 -1
  24. package/lib/LibManifestPlugin.js +2 -2
  25. package/lib/Module.js +11 -12
  26. package/lib/ModuleFactory.js +3 -3
  27. package/lib/ModuleFilenameHelpers.js +29 -16
  28. package/lib/ModuleGraph.js +5 -5
  29. package/lib/MultiCompiler.js +36 -1
  30. package/lib/NormalModule.js +10 -12
  31. package/lib/NormalModuleFactory.js +17 -8
  32. package/lib/Parser.js +1 -1
  33. package/lib/PlatformPlugin.js +39 -0
  34. package/lib/ProgressPlugin.js +1 -1
  35. package/lib/RecordIdsPlugin.js +4 -4
  36. package/lib/ResolverFactory.js +3 -3
  37. package/lib/RuntimeTemplate.js +22 -18
  38. package/lib/Stats.js +1 -1
  39. package/lib/Template.js +5 -5
  40. package/lib/TemplatedPathPlugin.js +16 -1
  41. package/lib/asset/AssetGenerator.js +15 -0
  42. package/lib/buildChunkGraph.js +3 -3
  43. package/lib/cache/MemoryWithGcCachePlugin.js +1 -1
  44. package/lib/cache/PackFileCacheStrategy.js +2 -2
  45. package/lib/cache/ResolverCachePlugin.js +8 -8
  46. package/lib/cache/getLazyHashedEtag.js +1 -1
  47. package/lib/cli.js +5 -5
  48. package/lib/config/browserslistTargetHandler.js +7 -1
  49. package/lib/config/defaults.js +85 -34
  50. package/lib/config/target.js +18 -11
  51. package/lib/container/ContainerEntryModule.js +1 -1
  52. package/lib/css/CssExportsGenerator.js +43 -17
  53. package/lib/css/CssGenerator.js +22 -12
  54. package/lib/css/CssLoadingRuntimeModule.js +8 -5
  55. package/lib/css/CssModulesPlugin.js +197 -100
  56. package/lib/css/CssParser.js +24 -15
  57. package/lib/css/walkCssTokens.js +1 -1
  58. package/lib/debug/ProfilingPlugin.js +1 -1
  59. package/lib/dependencies/ContextElementDependency.js +2 -2
  60. package/lib/dependencies/CssExportDependency.js +2 -2
  61. package/lib/dependencies/CssLocalIdentifierDependency.js +9 -2
  62. package/lib/dependencies/CssUrlDependency.js +5 -4
  63. package/lib/dependencies/ExportsInfoDependency.js +1 -1
  64. package/lib/dependencies/ExternalModuleDependency.js +4 -2
  65. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +2 -2
  66. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +2 -2
  67. package/lib/dependencies/HarmonyImportDependency.js +2 -2
  68. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +41 -18
  69. package/lib/dependencies/HarmonyImportSideEffectDependency.js +2 -2
  70. package/lib/dependencies/HarmonyImportSpecifierDependency.js +43 -32
  71. package/lib/dependencies/ImportDependency.js +2 -2
  72. package/lib/dependencies/ImportEagerDependency.js +2 -2
  73. package/lib/dependencies/ImportMetaPlugin.js +1 -1
  74. package/lib/dependencies/ImportParserPlugin.js +3 -1
  75. package/lib/dependencies/ImportWeakDependency.js +2 -2
  76. package/lib/dependencies/LoaderPlugin.js +2 -2
  77. package/lib/dependencies/ModuleDependency.js +2 -2
  78. package/lib/dependencies/PureExpressionDependency.js +63 -49
  79. package/lib/dependencies/WorkerDependency.js +1 -1
  80. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +90 -2
  81. package/lib/hmr/LazyCompilationPlugin.js +2 -2
  82. package/lib/ids/ChunkModuleIdRangePlugin.js +1 -1
  83. package/lib/ids/DeterministicChunkIdsPlugin.js +1 -1
  84. package/lib/ids/DeterministicModuleIdsPlugin.js +1 -1
  85. package/lib/ids/IdHelpers.js +6 -6
  86. package/lib/ids/NamedChunkIdsPlugin.js +1 -1
  87. package/lib/ids/NamedModuleIdsPlugin.js +1 -1
  88. package/lib/ids/SyncModuleIdsPlugin.js +2 -2
  89. package/lib/index.js +11 -0
  90. package/lib/javascript/CommonJsChunkFormatPlugin.js +1 -1
  91. package/lib/javascript/JavascriptGenerator.js +0 -1
  92. package/lib/javascript/JavascriptModulesPlugin.js +174 -17
  93. package/lib/javascript/JavascriptParser.js +37 -16
  94. package/lib/library/AbstractLibraryPlugin.js +2 -2
  95. package/lib/library/AmdLibraryPlugin.js +2 -2
  96. package/lib/library/AssignLibraryPlugin.js +3 -3
  97. package/lib/library/ExportPropertyLibraryPlugin.js +2 -2
  98. package/lib/library/JsonpLibraryPlugin.js +2 -2
  99. package/lib/library/ModuleLibraryPlugin.js +2 -2
  100. package/lib/library/SystemLibraryPlugin.js +2 -2
  101. package/lib/library/UmdLibraryPlugin.js +33 -12
  102. package/lib/logging/createConsoleLogger.js +2 -2
  103. package/lib/node/CommonJsChunkLoadingPlugin.js +2 -1
  104. package/lib/node/NodeEnvironmentPlugin.js +1 -1
  105. package/lib/node/NodeTemplatePlugin.js +1 -1
  106. package/lib/node/ReadFileCompileWasmPlugin.js +1 -1
  107. package/lib/node/nodeConsole.js +1 -1
  108. package/lib/optimize/AggressiveMergingPlugin.js +1 -1
  109. package/lib/optimize/ConcatenatedModule.js +11 -76
  110. package/lib/optimize/InnerGraph.js +1 -1
  111. package/lib/optimize/LimitChunkCountPlugin.js +1 -2
  112. package/lib/optimize/ModuleConcatenationPlugin.js +1 -1
  113. package/lib/optimize/RealContentHashPlugin.js +3 -3
  114. package/lib/optimize/SideEffectsFlagPlugin.js +2 -2
  115. package/lib/optimize/SplitChunksPlugin.js +8 -8
  116. package/lib/performance/SizeLimitsPlugin.js +2 -2
  117. package/lib/rules/ObjectMatcherRulePlugin.js +11 -1
  118. package/lib/rules/RuleSetCompiler.js +9 -7
  119. package/lib/runtime/LoadScriptRuntimeModule.js +1 -1
  120. package/lib/runtime/StartupChunkDependenciesPlugin.js +1 -1
  121. package/lib/schemes/HttpUriPlugin.js +1 -1
  122. package/lib/serialization/BinaryMiddleware.js +4 -4
  123. package/lib/serialization/FileMiddleware.js +3 -3
  124. package/lib/serialization/NullPrototypeObjectSerializer.js +2 -2
  125. package/lib/serialization/ObjectMiddleware.js +6 -5
  126. package/lib/serialization/PlainObjectSerializer.js +2 -2
  127. package/lib/serialization/SerializerMiddleware.js +2 -2
  128. package/lib/serialization/SingleItemMiddleware.js +2 -2
  129. package/lib/serialization/types.js +1 -1
  130. package/lib/sharing/ConsumeSharedModule.js +1 -1
  131. package/lib/sharing/ProvideSharedPlugin.js +1 -1
  132. package/lib/sharing/resolveMatchedConfigs.js +1 -1
  133. package/lib/stats/DefaultStatsFactoryPlugin.js +20 -20
  134. package/lib/stats/DefaultStatsPrinterPlugin.js +1 -1
  135. package/lib/stats/StatsFactory.js +2 -2
  136. package/lib/stats/StatsPrinter.js +6 -6
  137. package/lib/util/ArrayQueue.js +14 -21
  138. package/lib/util/AsyncQueue.js +1 -1
  139. package/lib/util/Queue.js +8 -2
  140. package/lib/util/SortableSet.js +16 -4
  141. package/lib/util/TupleQueue.js +8 -2
  142. package/lib/util/WeakTupleMap.js +3 -3
  143. package/lib/util/binarySearchBounds.js +1 -1
  144. package/lib/util/cleverMerge.js +2 -2
  145. package/lib/util/comparators.js +4 -2
  146. package/lib/util/conventions.js +1 -1
  147. package/lib/util/createHash.js +3 -5
  148. package/lib/util/deprecation.js +3 -3
  149. package/lib/util/deterministicGrouping.js +2 -2
  150. package/lib/util/findGraphRoots.js +1 -1
  151. package/lib/util/fs.js +15 -15
  152. package/lib/util/identifier.js +5 -5
  153. package/lib/util/mergeScope.js +79 -0
  154. package/lib/util/runtime.js +2 -17
  155. package/lib/util/semver.js +3 -0
  156. package/lib/util/smartGrouping.js +3 -3
  157. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +4 -2
  158. package/lib/wasm-async/AsyncWebAssemblyGenerator.js +1 -1
  159. package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +3 -3
  160. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +1 -1
  161. package/lib/wasm-sync/WebAssemblyGenerator.js +17 -17
  162. package/lib/wasm-sync/WebAssemblyModulesPlugin.js +1 -1
  163. package/lib/wasm-sync/WebAssemblyUtils.js +2 -1
  164. package/lib/web/FetchCompileWasmPlugin.js +1 -1
  165. package/lib/web/JsonpChunkLoadingRuntimeModule.js +1 -1
  166. package/lib/webpack.js +12 -3
  167. package/package.json +20 -18
  168. package/schemas/WebpackOptions.check.js +1 -1
  169. package/schemas/WebpackOptions.json +30 -2
  170. package/schemas/plugins/css/CssAutoGeneratorOptions.check.js +1 -1
  171. package/schemas/plugins/css/CssGeneratorOptions.check.js +1 -1
  172. package/schemas/plugins/css/CssGlobalGeneratorOptions.check.js +1 -1
  173. package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +1 -1
  174. package/types.d.ts +213 -81
@@ -11,7 +11,7 @@ const createHash = require("../util/createHash");
11
11
  /** @typedef {typeof import("../util/Hash")} HashConstructor */
12
12
 
13
13
  /**
14
- * @typedef {Object} HashableObject
14
+ * @typedef {object} HashableObject
15
15
  * @property {function(Hash): void} updateHash
16
16
  */
17
17
 
package/lib/cli.js CHANGED
@@ -10,7 +10,7 @@ const webpackSchema = require("../schemas/WebpackOptions.json");
10
10
 
11
11
  // TODO add originPath to PathItem for better errors
12
12
  /**
13
- * @typedef {Object} PathItem
13
+ * @typedef {object} PathItem
14
14
  * @property {any} schema the part of the schema
15
15
  * @property {string} path the path in the config
16
16
  */
@@ -18,7 +18,7 @@ const webpackSchema = require("../schemas/WebpackOptions.json");
18
18
  /** @typedef {"unknown-argument" | "unexpected-non-array-in-path" | "unexpected-non-object-in-path" | "multiple-values-unexpected" | "invalid-value"} ProblemType */
19
19
 
20
20
  /**
21
- * @typedef {Object} Problem
21
+ * @typedef {object} Problem
22
22
  * @property {ProblemType} type
23
23
  * @property {string} path
24
24
  * @property {string} argument
@@ -28,14 +28,14 @@ const webpackSchema = require("../schemas/WebpackOptions.json");
28
28
  */
29
29
 
30
30
  /**
31
- * @typedef {Object} LocalProblem
31
+ * @typedef {object} LocalProblem
32
32
  * @property {ProblemType} type
33
33
  * @property {string} path
34
34
  * @property {string=} expected
35
35
  */
36
36
 
37
37
  /**
38
- * @typedef {Object} ArgumentConfig
38
+ * @typedef {object} ArgumentConfig
39
39
  * @property {string} description
40
40
  * @property {string} [negatedDescription]
41
41
  * @property {string} path
@@ -45,7 +45,7 @@ const webpackSchema = require("../schemas/WebpackOptions.json");
45
45
  */
46
46
 
47
47
  /**
48
- * @typedef {Object} Argument
48
+ * @typedef {object} Argument
49
49
  * @property {string} description
50
50
  * @property {"string"|"number"|"boolean"} simpleType
51
51
  * @property {boolean} multiple
@@ -16,7 +16,7 @@ const path = require("path");
16
16
  const inputRx = /^(?:((?:[A-Z]:)?[/\\].*?))?(?::(.+?))?$/i;
17
17
 
18
18
  /**
19
- * @typedef {Object} BrowserslistHandlerConfig
19
+ * @typedef {object} BrowserslistHandlerConfig
20
20
  * @property {string=} configPath
21
21
  * @property {string=} env
22
22
  * @property {string=} query
@@ -344,6 +344,12 @@ const resolve = browsers => {
344
344
  importScripts: false,
345
345
  importScriptsInWorker: true,
346
346
  nodeBuiltins: nodeProperty,
347
+ nodePrefixForCoreModules:
348
+ nodeProperty &&
349
+ !browsers.some(b => /^node 15/.test(b)) &&
350
+ rawChecker({
351
+ node: [14, 18]
352
+ }),
347
353
  require: nodeProperty
348
354
  };
349
355
  };
@@ -27,7 +27,8 @@ const {
27
27
  getDefaultTarget
28
28
  } = require("./target");
29
29
 
30
- /** @typedef {import("../../declarations/WebpackOptions").CacheOptionsNormalized} CacheOptions */
30
+ /** @typedef {import("../../declarations/WebpackOptions").CacheOptions} CacheOptions */
31
+ /** @typedef {import("../../declarations/WebpackOptions").CacheOptionsNormalized} CacheOptionsNormalized */
31
32
  /** @typedef {import("../../declarations/WebpackOptions").Context} Context */
32
33
  /** @typedef {import("../../declarations/WebpackOptions").CssGeneratorOptions} CssGeneratorOptions */
33
34
  /** @typedef {import("../../declarations/WebpackOptions").CssParserOptions} CssParserOptions */
@@ -60,12 +61,20 @@ const {
60
61
  /** @typedef {import("../../declarations/WebpackOptions").RuleSetRules} RuleSetRules */
61
62
  /** @typedef {import("../../declarations/WebpackOptions").SnapshotOptions} SnapshotOptions */
62
63
  /** @typedef {import("../../declarations/WebpackOptions").Target} Target */
63
- /** @typedef {import("../../declarations/WebpackOptions").WebpackOptionsNormalized} WebpackOptions */
64
+ /** @typedef {import("../../declarations/WebpackOptions").WebpackOptions} WebpackOptions */
65
+ /** @typedef {import("../../declarations/WebpackOptions").WebpackOptionsNormalized} WebpackOptionsNormalized */
64
66
  /** @typedef {import("../Compiler")} Compiler */
65
67
  /** @typedef {import("../Module")} Module */
68
+ /** @typedef {import("./target").PlatformTargetProperties} PlatformTargetProperties */
66
69
  /** @typedef {import("./target").TargetProperties} TargetProperties */
67
70
 
71
+ /**
72
+ * @typedef {object} ResolvedOptions
73
+ * @property {PlatformTargetProperties | false} platform - platform target properties
74
+ */
75
+
68
76
  const NODE_MODULES_REGEXP = /[\\/]node_modules[\\/]/i;
77
+ const DEFAULT_CACHE_NAME = "default";
69
78
 
70
79
  /**
71
80
  * Sets a constant default value when undefined
@@ -137,7 +146,7 @@ const A = (obj, prop, factory) => {
137
146
  };
138
147
 
139
148
  /**
140
- * @param {WebpackOptions} options options to be modified
149
+ * @param {WebpackOptionsNormalized} options options to be modified
141
150
  * @returns {void}
142
151
  */
143
152
  const applyWebpackOptionsBaseDefaults = options => {
@@ -146,10 +155,11 @@ const applyWebpackOptionsBaseDefaults = options => {
146
155
  };
147
156
 
148
157
  /**
149
- * @param {WebpackOptions} options options to be modified
150
- * @returns {void}
158
+ * @param {WebpackOptionsNormalized} options options to be modified
159
+ * @param {number} [compilerIndex] index of compiler
160
+ * @returns {ResolvedOptions} Resolved options after apply defaults
151
161
  */
152
- const applyWebpackOptionsDefaults = options => {
162
+ const applyWebpackOptionsDefaults = (options, compilerIndex) => {
153
163
  F(options, "context", () => process.cwd());
154
164
  F(options, "target", () => {
155
165
  return getDefaultTarget(/** @type {string} */ (options.context));
@@ -201,10 +211,11 @@ const applyWebpackOptionsDefaults = options => {
201
211
  development ? { type: /** @type {"memory"} */ ("memory") } : false
202
212
  );
203
213
  applyCacheDefaults(options.cache, {
204
- name: name || "default",
214
+ name: name || DEFAULT_CACHE_NAME,
205
215
  mode: mode || "production",
206
216
  development,
207
- cacheUnaffected: options.experiments.cacheUnaffected
217
+ cacheUnaffected: options.experiments.cacheUnaffected,
218
+ compilerIndex
208
219
  });
209
220
  const cache = !!options.cache;
210
221
 
@@ -242,7 +253,6 @@ const applyWebpackOptionsDefaults = options => {
242
253
  (options.experiments.outputModule),
243
254
  development,
244
255
  entry: options.entry,
245
- module: options.module,
246
256
  futureDefaults
247
257
  });
248
258
 
@@ -252,7 +262,9 @@ const applyWebpackOptionsDefaults = options => {
252
262
  });
253
263
 
254
264
  applyLoaderDefaults(
255
- /** @type {NonNullable<WebpackOptions["loader"]>} */ (options.loader),
265
+ /** @type {NonNullable<WebpackOptionsNormalized["loader"]>} */ (
266
+ options.loader
267
+ ),
256
268
  { targetProperties, environment: options.output.environment }
257
269
  );
258
270
 
@@ -269,7 +281,7 @@ const applyWebpackOptionsDefaults = options => {
269
281
 
270
282
  applyNodeDefaults(options.node, {
271
283
  futureDefaults:
272
- /** @type {NonNullable<WebpackOptions["experiments"]["futureDefaults"]>} */
284
+ /** @type {NonNullable<WebpackOptionsNormalized["experiments"]["futureDefaults"]>} */
273
285
  (options.experiments.futureDefaults),
274
286
  outputModule: options.output.module,
275
287
  targetProperties
@@ -283,7 +295,7 @@ const applyWebpackOptionsDefaults = options => {
283
295
  : false
284
296
  );
285
297
  applyPerformanceDefaults(
286
- /** @type {NonNullable<WebpackOptions["performance"]>} */
298
+ /** @type {NonNullable<WebpackOptionsNormalized["performance"]>} */
287
299
  (options.performance),
288
300
  {
289
301
  production
@@ -316,11 +328,25 @@ const applyWebpackOptionsDefaults = options => {
316
328
  getResolveLoaderDefaults({ cache }),
317
329
  options.resolveLoader
318
330
  );
331
+
332
+ return {
333
+ platform:
334
+ targetProperties === false
335
+ ? targetProperties
336
+ : {
337
+ web: targetProperties.web,
338
+ browser: targetProperties.browser,
339
+ webworker: targetProperties.webworker,
340
+ node: targetProperties.node,
341
+ nwjs: targetProperties.nwjs,
342
+ electron: targetProperties.electron
343
+ }
344
+ };
319
345
  };
320
346
 
321
347
  /**
322
348
  * @param {ExperimentsNormalized} experiments options
323
- * @param {Object} options options
349
+ * @param {object} options options
324
350
  * @param {boolean} options.production is production
325
351
  * @param {boolean} options.development is development mode
326
352
  * @param {TargetProperties | false} options.targetProperties target properties
@@ -355,22 +381,27 @@ const applyExperimentsDefaults = (
355
381
  };
356
382
 
357
383
  /**
358
- * @param {CacheOptions} cache options
359
- * @param {Object} options options
384
+ * @param {CacheOptionsNormalized} cache options
385
+ * @param {object} options options
360
386
  * @param {string} options.name name
361
387
  * @param {Mode} options.mode mode
362
388
  * @param {boolean} options.development is development mode
389
+ * @param {number} [options.compilerIndex] index of compiler
363
390
  * @param {Experiments["cacheUnaffected"]} options.cacheUnaffected the cacheUnaffected experiment is enabled
364
391
  * @returns {void}
365
392
  */
366
393
  const applyCacheDefaults = (
367
394
  cache,
368
- { name, mode, development, cacheUnaffected }
395
+ { name, mode, development, cacheUnaffected, compilerIndex }
369
396
  ) => {
370
397
  if (cache === false) return;
371
398
  switch (cache.type) {
372
399
  case "filesystem":
373
- F(cache, "name", () => name + "-" + mode);
400
+ F(cache, "name", () =>
401
+ compilerIndex !== undefined
402
+ ? `${name + "-" + mode}__compiler${compilerIndex + 1}__`
403
+ : name + "-" + mode
404
+ );
374
405
  D(cache, "version", "");
375
406
  F(cache, "cacheDirectory", () => {
376
407
  const cwd = process.cwd();
@@ -433,7 +464,7 @@ const applyCacheDefaults = (
433
464
 
434
465
  /**
435
466
  * @param {SnapshotOptions} snapshot options
436
- * @param {Object} options options
467
+ * @param {object} options options
437
468
  * @param {boolean} options.production is production
438
469
  * @param {boolean} options.futureDefaults is future defaults enabled
439
470
  * @returns {void}
@@ -509,7 +540,7 @@ const applySnapshotDefaults = (snapshot, { production, futureDefaults }) => {
509
540
 
510
541
  /**
511
542
  * @param {JavascriptParserOptions} parserOptions parser options
512
- * @param {Object} options options
543
+ * @param {object} options options
513
544
  * @param {boolean} options.futureDefaults is future defaults enabled
514
545
  * @param {boolean} options.isNode is node target platform
515
546
  * @returns {void}
@@ -541,7 +572,7 @@ const applyJavascriptParserOptionsDefaults = (
541
572
 
542
573
  /**
543
574
  * @param {CssGeneratorOptions} generatorOptions generator options
544
- * @param {Object} options options
575
+ * @param {object} options options
545
576
  * @param {TargetProperties | false} options.targetProperties target properties
546
577
  * @returns {void}
547
578
  */
@@ -554,12 +585,12 @@ const applyCssGeneratorOptionsDefaults = (
554
585
  "exportsOnly",
555
586
  !targetProperties || !targetProperties.document
556
587
  );
557
- D(generatorOptions, "exportsConvention", "as-is");
588
+ D(generatorOptions, "esModule", true);
558
589
  };
559
590
 
560
591
  /**
561
592
  * @param {ModuleOptions} module options
562
- * @param {Object} options options
593
+ * @param {object} options options
563
594
  * @param {boolean} options.cache is caching enabled
564
595
  * @param {boolean} options.syncWebAssembly is syncWebAssembly enabled
565
596
  * @param {boolean} options.asyncWebAssembly is asyncWebAssembly enabled
@@ -649,6 +680,7 @@ const applyModuleDefaults = (
649
680
  "localIdentName",
650
681
  "[uniqueName]-[id]-[local]"
651
682
  );
683
+ D(module.generator["css/auto"], "exportsConvention", "as-is");
652
684
 
653
685
  F(module.generator, "css/module", () => ({}));
654
686
  D(
@@ -656,6 +688,7 @@ const applyModuleDefaults = (
656
688
  "localIdentName",
657
689
  "[uniqueName]-[id]-[local]"
658
690
  );
691
+ D(module.generator["css/module"], "exportsConvention", "as-is");
659
692
 
660
693
  F(module.generator, "css/global", () => ({}));
661
694
  D(
@@ -663,6 +696,7 @@ const applyModuleDefaults = (
663
696
  "localIdentName",
664
697
  "[uniqueName]-[id]-[local]"
665
698
  );
699
+ D(module.generator["css/global"], "exportsConvention", "as-is");
666
700
  }
667
701
 
668
702
  A(module, "defaultRules", () => {
@@ -804,6 +838,10 @@ const applyModuleDefaults = (
804
838
  {
805
839
  assert: { type: "json" },
806
840
  type: JSON_MODULE_TYPE
841
+ },
842
+ {
843
+ with: { type: "json" },
844
+ type: JSON_MODULE_TYPE
807
845
  }
808
846
  );
809
847
  return rules;
@@ -812,14 +850,13 @@ const applyModuleDefaults = (
812
850
 
813
851
  /**
814
852
  * @param {Output} output options
815
- * @param {Object} options options
853
+ * @param {object} options options
816
854
  * @param {string} options.context context
817
855
  * @param {TargetProperties | false} options.targetProperties target properties
818
856
  * @param {boolean} options.isAffectedByBrowserslist is affected by browserslist
819
857
  * @param {boolean} options.outputModule is outputModule experiment enabled
820
858
  * @param {boolean} options.development is development mode
821
859
  * @param {Entry} options.entry entry option
822
- * @param {ModuleOptions} options.module module option
823
860
  * @param {boolean} options.futureDefaults is future defaults enabled
824
861
  * @returns {void}
825
862
  */
@@ -832,7 +869,6 @@ const applyOutputDefaults = (
832
869
  outputModule,
833
870
  development,
834
871
  entry,
835
- module,
836
872
  futureDefaults
837
873
  }
838
874
  ) => {
@@ -984,7 +1020,7 @@ const applyOutputDefaults = (
984
1020
  if (tp.nodeBuiltins) return "async-node";
985
1021
  break;
986
1022
  case "module":
987
- if (tp.dynamicImport) return "import";
1023
+ if (tp.dynamicImport || output.module) return "import";
988
1024
  break;
989
1025
  }
990
1026
  if (
@@ -1009,7 +1045,7 @@ const applyOutputDefaults = (
1009
1045
  if (tp.nodeBuiltins) return "async-node";
1010
1046
  break;
1011
1047
  case "module":
1012
- if (tp.dynamicImportInWorker) return "import";
1048
+ if (tp.dynamicImportInWorker || output.module) return "import";
1013
1049
  break;
1014
1050
  }
1015
1051
  if (
@@ -1121,6 +1157,15 @@ const applyOutputDefaults = (
1121
1157
  () =>
1122
1158
  tp && optimistic(/** @type {boolean | undefined} */ (tp.optionalChaining))
1123
1159
  );
1160
+ F(
1161
+ environment,
1162
+ "nodePrefixForCoreModules",
1163
+ () =>
1164
+ tp &&
1165
+ optimistic(
1166
+ /** @type {boolean | undefined} */ (tp.nodePrefixForCoreModules)
1167
+ )
1168
+ );
1124
1169
  F(
1125
1170
  environment,
1126
1171
  "templateLiteral",
@@ -1145,6 +1190,11 @@ const applyOutputDefaults = (
1145
1190
  output.module
1146
1191
  )
1147
1192
  );
1193
+ F(
1194
+ environment,
1195
+ "document",
1196
+ () => tp && optimistic(/** @type {boolean | undefined} */ (tp.document))
1197
+ );
1148
1198
 
1149
1199
  const { trustedTypes } = output;
1150
1200
  if (trustedTypes) {
@@ -1216,7 +1266,7 @@ const applyOutputDefaults = (
1216
1266
 
1217
1267
  /**
1218
1268
  * @param {ExternalsPresets} externalsPresets options
1219
- * @param {Object} options options
1269
+ * @param {object} options options
1220
1270
  * @param {TargetProperties | false} options.targetProperties target properties
1221
1271
  * @param {boolean} options.buildHttp buildHttp experiment enabled
1222
1272
  * @returns {void}
@@ -1283,7 +1333,7 @@ const applyExternalsPresetsDefaults = (
1283
1333
 
1284
1334
  /**
1285
1335
  * @param {Loader} loader options
1286
- * @param {Object} options options
1336
+ * @param {object} options options
1287
1337
  * @param {TargetProperties | false} options.targetProperties target properties
1288
1338
  * @param {Environment} options.environment environment
1289
1339
  * @returns {void}
@@ -1307,7 +1357,7 @@ const applyLoaderDefaults = (loader, { targetProperties, environment }) => {
1307
1357
 
1308
1358
  /**
1309
1359
  * @param {WebpackNode} node options
1310
- * @param {Object} options options
1360
+ * @param {object} options options
1311
1361
  * @param {TargetProperties | false} options.targetProperties target properties
1312
1362
  * @param {boolean} options.futureDefaults is future defaults enabled
1313
1363
  * @param {boolean} options.outputModule is output type is module
@@ -1338,7 +1388,7 @@ const applyNodeDefaults = (
1338
1388
 
1339
1389
  /**
1340
1390
  * @param {Performance} performance options
1341
- * @param {Object} options options
1391
+ * @param {object} options options
1342
1392
  * @param {boolean} options.production is production
1343
1393
  * @returns {void}
1344
1394
  */
@@ -1351,7 +1401,7 @@ const applyPerformanceDefaults = (performance, { production }) => {
1351
1401
 
1352
1402
  /**
1353
1403
  * @param {Optimization} optimization options
1354
- * @param {Object} options options
1404
+ * @param {object} options options
1355
1405
  * @param {boolean} options.production is production
1356
1406
  * @param {boolean} options.development is development
1357
1407
  * @param {boolean} options.css is css enabled
@@ -1443,7 +1493,7 @@ const applyOptimizationDefaults = (
1443
1493
  };
1444
1494
 
1445
1495
  /**
1446
- * @param {Object} options options
1496
+ * @param {object} options options
1447
1497
  * @param {boolean} options.cache is cache enable
1448
1498
  * @param {string} options.context build context
1449
1499
  * @param {TargetProperties | false} options.targetProperties target properties
@@ -1503,6 +1553,7 @@ const getResolveDefaults = ({
1503
1553
  exportsFields: ["exports"],
1504
1554
  roots: [context],
1505
1555
  mainFields: ["main"],
1556
+ importsFields: ["imports"],
1506
1557
  byDependency: {
1507
1558
  wasm: esmDeps(),
1508
1559
  esm: esmDeps(),
@@ -1548,7 +1599,7 @@ const getResolveDefaults = ({
1548
1599
  };
1549
1600
 
1550
1601
  /**
1551
- * @param {Object} options options
1602
+ * @param {object} options options
1552
1603
  * @param {boolean} options.cache is cache enable
1553
1604
  * @returns {ResolveOptions} resolve options
1554
1605
  */
@@ -21,7 +21,7 @@ const getDefaultTarget = context => {
21
21
  };
22
22
 
23
23
  /**
24
- * @typedef {Object} PlatformTargetProperties
24
+ * @typedef {object} PlatformTargetProperties
25
25
  * @property {boolean | null} web web platform, importing of http(s) and std: is available
26
26
  * @property {boolean | null} browser browser platform, running in a normal web browser
27
27
  * @property {boolean | null} webworker (Web)Worker platform, running in a web/shared/service worker
@@ -31,16 +31,17 @@ const getDefaultTarget = context => {
31
31
  */
32
32
 
33
33
  /**
34
- * @typedef {Object} ElectronContextTargetProperties
34
+ * @typedef {object} ElectronContextTargetProperties
35
35
  * @property {boolean | null} electronMain in main context
36
36
  * @property {boolean | null} electronPreload in preload context
37
37
  * @property {boolean | null} electronRenderer in renderer context with node integration
38
38
  */
39
39
 
40
40
  /**
41
- * @typedef {Object} ApiTargetProperties
41
+ * @typedef {object} ApiTargetProperties
42
42
  * @property {boolean | null} require has require function available
43
43
  * @property {boolean | null} nodeBuiltins has node.js built-in modules available
44
+ * @property {boolean | null} nodePrefixForCoreModules node.js allows to use `node:` prefix for core modules
44
45
  * @property {boolean | null} document has document available (allows script tags)
45
46
  * @property {boolean | null} importScripts has importScripts available
46
47
  * @property {boolean | null} importScriptsInWorker has importScripts available when creating a worker
@@ -49,7 +50,7 @@ const getDefaultTarget = context => {
49
50
  */
50
51
 
51
52
  /**
52
- * @typedef {Object} EcmaTargetProperties
53
+ * @typedef {object} EcmaTargetProperties
53
54
  * @property {boolean | null} globalThis has globalThis variable available
54
55
  * @property {boolean | null} bigIntLiteral big int literal syntax is available
55
56
  * @property {boolean | null} const const and let variable declarations are available
@@ -168,8 +169,8 @@ You can also more options via the 'target' option: 'browserslist' / 'browserslis
168
169
  [
169
170
  "[async-]node[X[.Y]]",
170
171
  "Node.js in version X.Y. The 'async-' prefix will load chunks asynchronously via 'fs' and 'vm' instead of 'require()'. Examples: node14.5, async-node10.",
171
- /^(async-)?node(\d+(?:\.(\d+))?)?$/,
172
- (asyncFlag, major, minor) => {
172
+ /^(async-)?node((\d+)(?:\.(\d+))?)?$/,
173
+ (asyncFlag, _, major, minor) => {
173
174
  const v = versionDependent(major, minor);
174
175
  // see https://node.green/
175
176
  return {
@@ -182,6 +183,8 @@ You can also more options via the 'target' option: 'browserslist' / 'browserslis
182
183
 
183
184
  require: !asyncFlag,
184
185
  nodeBuiltins: true,
186
+ // v16.0.0, v14.18.0
187
+ nodePrefixForCoreModules: +major < 15 ? v(14, 18) : v(16),
185
188
  global: true,
186
189
  document: false,
187
190
  fetchWasm: false,
@@ -206,8 +209,8 @@ You can also more options via the 'target' option: 'browserslist' / 'browserslis
206
209
  [
207
210
  "electron[X[.Y]]-main/preload/renderer",
208
211
  "Electron in version X.Y. Script is running in main, preload resp. renderer context.",
209
- /^electron(\d+(?:\.(\d+))?)?-(main|preload|renderer)$/,
210
- (major, minor, context) => {
212
+ /^electron((\d+)(?:\.(\d+))?)?-(main|preload|renderer)$/,
213
+ (_, major, minor, context) => {
211
214
  const v = versionDependent(major, minor);
212
215
  // see https://node.green/ + https://github.com/electron/releases
213
216
  return {
@@ -224,6 +227,10 @@ You can also more options via the 'target' option: 'browserslist' / 'browserslis
224
227
 
225
228
  global: true,
226
229
  nodeBuiltins: true,
230
+ // 15.0.0 - Node.js v16.5
231
+ // 14.0.0 - Mode.js v14.17, but prefixes only since v14.18
232
+ nodePrefixForCoreModules: v(15),
233
+
227
234
  require: true,
228
235
  document: context === "renderer",
229
236
  fetchWasm: context === "renderer",
@@ -248,8 +255,8 @@ You can also more options via the 'target' option: 'browserslist' / 'browserslis
248
255
  [
249
256
  "nwjs[X[.Y]] / node-webkit[X[.Y]]",
250
257
  "NW.js in version X.Y.",
251
- /^(?:nwjs|node-webkit)(\d+(?:\.(\d+))?)?$/,
252
- (major, minor) => {
258
+ /^(?:nwjs|node-webkit)((\d+)(?:\.(\d+))?)?$/,
259
+ (_, major, minor) => {
253
260
  const v = versionDependent(major, minor);
254
261
  // see https://node.green/ + https://github.com/nwjs/nw.js/blob/nw48/CHANGELOG.md
255
262
  return {
@@ -341,7 +348,7 @@ const mergeTargetProperties = targetProperties => {
341
348
  keys.add(/** @type {keyof TargetProperties} */ (key));
342
349
  }
343
350
  }
344
- /** @type {Object} */
351
+ /** @type {object} */
345
352
  const result = {};
346
353
  for (const key of keys) {
347
354
  let hasTrue = false;
@@ -34,7 +34,7 @@ const ContainerExposedDependency = require("./ContainerExposedDependency");
34
34
  /** @typedef {import("./ContainerEntryDependency")} ContainerEntryDependency */
35
35
 
36
36
  /**
37
- * @typedef {Object} ExposeOptions
37
+ * @typedef {object} ExposeOptions
38
38
  * @property {string[]} import requests to exposed modules (last one is exported)
39
39
  * @property {string} name custom chunk name for the exposed module
40
40
  */
@@ -16,6 +16,8 @@ const { cssExportConvention } = require("../util/conventions");
16
16
  /** @typedef {import("../../declarations/WebpackOptions").CssGeneratorExportsConvention} CssGeneratorExportsConvention */
17
17
  /** @typedef {import("../../declarations/WebpackOptions").CssGeneratorLocalIdentName} CssGeneratorLocalIdentName */
18
18
  /** @typedef {import("../Dependency")} Dependency */
19
+ /** @typedef {import("../DependencyTemplate").CssDependencyTemplateContext} DependencyTemplateContext */
20
+ /** @typedef {import("../DependencyTemplate").CssExportsData} CssExportsData */
19
21
  /** @typedef {import("../Generator").GenerateContext} GenerateContext */
20
22
  /** @typedef {import("../Generator").UpdateHashContext} UpdateHashContext */
21
23
  /** @typedef {import("../Module").ConcatenationBailoutReasonContext} ConcatenationBailoutReasonContext */
@@ -31,19 +33,38 @@ const TYPES = new Set(["javascript"]);
31
33
 
32
34
  class CssExportsGenerator extends Generator {
33
35
  /**
34
- * @param {CssGeneratorExportsConvention} convention the convention of the exports name
36
+ * @param {CssGeneratorExportsConvention | undefined} convention the convention of the exports name
35
37
  * @param {CssGeneratorLocalIdentName | undefined} localIdentName css export local ident name
38
+ * @param {boolean} esModule whether to use ES modules syntax
36
39
  */
37
- constructor(convention, localIdentName) {
40
+ constructor(convention, localIdentName, esModule) {
38
41
  super();
39
- /** @type {CssGeneratorExportsConvention} */
42
+ /** @type {CssGeneratorExportsConvention | undefined} */
40
43
  this.convention = convention;
41
44
  /** @type {CssGeneratorLocalIdentName | undefined} */
42
45
  this.localIdentName = localIdentName;
46
+ /** @type {boolean} */
47
+ this.esModule = esModule;
43
48
  }
44
49
 
45
- // TODO add getConcatenationBailoutReason to allow concatenation
46
- // but how to make it have a module id
50
+ /**
51
+ * @param {NormalModule} module module for which the bailout reason should be determined
52
+ * @param {ConcatenationBailoutReasonContext} context context
53
+ * @returns {string | undefined} reason why this module can't be concatenated, undefined when it can be concatenated
54
+ */
55
+ getConcatenationBailoutReason(module, context) {
56
+ if (!this.esModule) {
57
+ return "Module is not an ECMAScript module";
58
+ }
59
+ // TODO webpack 6: remove /\[moduleid\]/.test
60
+ if (
61
+ /\[id\]/.test(this.localIdentName) ||
62
+ /\[moduleid\]/.test(this.localIdentName)
63
+ ) {
64
+ return "The localIdentName includes moduleId ([id] or [moduleid])";
65
+ }
66
+ return undefined;
67
+ }
47
68
 
48
69
  /**
49
70
  * @param {NormalModule} module module for which the code should be generated
@@ -54,14 +75,18 @@ class CssExportsGenerator extends Generator {
54
75
  const source = new ReplaceSource(new RawSource(""));
55
76
  /** @type {InitFragment<TODO>[]} */
56
77
  const initFragments = [];
57
- /** @type {Map<string, string>} */
58
- const cssExports = new Map();
78
+ /** @type {CssExportsData} */
79
+ const cssExportsData = {
80
+ esModule: this.esModule,
81
+ exports: new Map()
82
+ };
59
83
 
60
84
  generateContext.runtimeRequirements.add(RuntimeGlobals.module);
61
85
 
62
86
  let chunkInitFragments;
63
87
  const runtimeRequirements = new Set();
64
88
 
89
+ /** @type {DependencyTemplateContext} */
65
90
  const templateContext = {
66
91
  runtimeTemplate: generateContext.runtimeTemplate,
67
92
  dependencyTemplates: generateContext.dependencyTemplates,
@@ -73,7 +98,7 @@ class CssExportsGenerator extends Generator {
73
98
  concatenationScope: generateContext.concatenationScope,
74
99
  codeGenerationResults: generateContext.codeGenerationResults,
75
100
  initFragments,
76
- cssExports,
101
+ cssExportsData,
77
102
  get chunkInitFragments() {
78
103
  if (!chunkInitFragments) {
79
104
  const data = generateContext.getData();
@@ -109,7 +134,7 @@ class CssExportsGenerator extends Generator {
109
134
  if (generateContext.concatenationScope) {
110
135
  const source = new ConcatSource();
111
136
  const usedIdentifiers = new Set();
112
- for (const [name, v] of cssExports) {
137
+ for (const [name, v] of cssExportsData.exports) {
113
138
  for (let k of cssExportConvention(name, this.convention)) {
114
139
  let identifier = Template.toIdentifier(k);
115
140
  let i = 0;
@@ -127,26 +152,27 @@ class CssExportsGenerator extends Generator {
127
152
  }
128
153
  return source;
129
154
  } else {
130
- const otherUsed =
155
+ const needNsObj =
156
+ this.esModule &&
131
157
  generateContext.moduleGraph
132
158
  .getExportsInfo(module)
133
159
  .otherExportsInfo.getUsed(generateContext.runtime) !==
134
- UsageState.Unused;
135
- if (otherUsed) {
160
+ UsageState.Unused;
161
+ if (needNsObj) {
136
162
  generateContext.runtimeRequirements.add(
137
163
  RuntimeGlobals.makeNamespaceObject
138
164
  );
139
165
  }
140
- const newCssExports = [];
141
- for (let [k, v] of cssExports) {
166
+ const newExports = [];
167
+ for (let [k, v] of cssExportsData.exports) {
142
168
  for (let name of cssExportConvention(k, this.convention)) {
143
- newCssExports.push(`\t${JSON.stringify(name)}: ${JSON.stringify(v)}`);
169
+ newExports.push(`\t${JSON.stringify(name)}: ${JSON.stringify(v)}`);
144
170
  }
145
171
  }
146
172
  return new RawSource(
147
- `${otherUsed ? `${RuntimeGlobals.makeNamespaceObject}(` : ""}${
173
+ `${needNsObj ? `${RuntimeGlobals.makeNamespaceObject}(` : ""}${
148
174
  module.moduleArgument
149
- }.exports = {\n${newCssExports.join(",\n")}\n}${otherUsed ? ")" : ""};`
175
+ }.exports = {\n${newExports.join(",\n")}\n}${needNsObj ? ")" : ""};`
150
176
  );
151
177
  }
152
178
  }