webpack 5.59.0 → 5.76.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 (236) hide show
  1. package/README.md +22 -24
  2. package/bin/webpack.js +0 -0
  3. package/hot/dev-server.js +17 -4
  4. package/hot/lazy-compilation-node.js +3 -1
  5. package/hot/poll.js +1 -1
  6. package/hot/signal.js +1 -1
  7. package/lib/APIPlugin.js +33 -0
  8. package/lib/BannerPlugin.js +13 -5
  9. package/lib/Cache.js +1 -1
  10. package/lib/CacheFacade.js +4 -11
  11. package/lib/Chunk.js +6 -3
  12. package/lib/ChunkGraph.js +94 -8
  13. package/lib/ChunkGroup.js +1 -1
  14. package/lib/CleanPlugin.js +81 -20
  15. package/lib/Compilation.js +188 -93
  16. package/lib/Compiler.js +87 -18
  17. package/lib/ConstPlugin.js +2 -2
  18. package/lib/ContextModule.js +142 -51
  19. package/lib/ContextModuleFactory.js +65 -25
  20. package/lib/DelegatedModule.js +1 -1
  21. package/lib/DelegatedModuleFactoryPlugin.js +1 -1
  22. package/lib/Dependency.js +17 -0
  23. package/lib/DependencyTemplate.js +9 -0
  24. package/lib/DependencyTemplates.js +1 -1
  25. package/lib/DllModule.js +1 -1
  26. package/lib/DllReferencePlugin.js +1 -1
  27. package/lib/EntryOptionPlugin.js +2 -0
  28. package/lib/ErrorHelpers.js +2 -2
  29. package/lib/EvalDevToolModulePlugin.js +16 -1
  30. package/lib/EvalSourceMapDevToolPlugin.js +25 -4
  31. package/lib/ExportsInfo.js +5 -5
  32. package/lib/ExternalModule.js +94 -54
  33. package/lib/ExternalModuleFactoryPlugin.js +5 -5
  34. package/lib/FileSystemInfo.js +124 -58
  35. package/lib/Generator.js +3 -0
  36. package/lib/HookWebpackError.js +1 -1
  37. package/lib/HotModuleReplacementPlugin.js +3 -1
  38. package/lib/LoaderOptionsPlugin.js +1 -1
  39. package/lib/Module.js +28 -4
  40. package/lib/ModuleFilenameHelpers.js +8 -4
  41. package/lib/ModuleHashingError.js +29 -0
  42. package/lib/MultiCompiler.js +1 -1
  43. package/lib/MultiWatching.js +1 -1
  44. package/lib/NodeStuffPlugin.js +13 -3
  45. package/lib/NormalModule.js +51 -33
  46. package/lib/NormalModuleFactory.js +42 -37
  47. package/lib/ProgressPlugin.js +4 -5
  48. package/lib/RawModule.js +1 -1
  49. package/lib/RuntimeGlobals.js +29 -1
  50. package/lib/RuntimeModule.js +1 -1
  51. package/lib/RuntimePlugin.js +84 -1
  52. package/lib/RuntimeTemplate.js +114 -2
  53. package/lib/Template.js +3 -2
  54. package/lib/TemplatedPathPlugin.js +48 -23
  55. package/lib/WatchIgnorePlugin.js +19 -7
  56. package/lib/Watching.js +33 -19
  57. package/lib/WebpackOptionsApply.js +79 -11
  58. package/lib/asset/AssetGenerator.js +228 -71
  59. package/lib/asset/AssetModulesPlugin.js +3 -0
  60. package/lib/asset/AssetParser.js +1 -0
  61. package/lib/asset/AssetSourceGenerator.js +31 -6
  62. package/lib/asset/AssetSourceParser.js +1 -0
  63. package/lib/asset/RawDataUrlModule.js +148 -0
  64. package/lib/async-modules/AwaitDependenciesInitFragment.js +4 -4
  65. package/lib/buildChunkGraph.js +38 -7
  66. package/lib/cache/PackFileCacheStrategy.js +15 -8
  67. package/lib/cache/ResolverCachePlugin.js +90 -29
  68. package/lib/cli.js +44 -3
  69. package/lib/config/browserslistTargetHandler.js +41 -6
  70. package/lib/config/defaults.js +123 -19
  71. package/lib/config/normalization.js +10 -2
  72. package/lib/config/target.js +10 -0
  73. package/lib/container/ContainerEntryModule.js +8 -5
  74. package/lib/container/FallbackModule.js +4 -4
  75. package/lib/container/ModuleFederationPlugin.js +2 -0
  76. package/lib/container/RemoteModule.js +4 -2
  77. package/lib/container/RemoteRuntimeModule.js +8 -7
  78. package/lib/css/CssExportsGenerator.js +139 -0
  79. package/lib/css/CssGenerator.js +109 -0
  80. package/lib/css/CssLoadingRuntimeModule.js +442 -0
  81. package/lib/css/CssModulesPlugin.js +462 -0
  82. package/lib/css/CssParser.js +618 -0
  83. package/lib/css/walkCssTokens.js +659 -0
  84. package/lib/debug/ProfilingPlugin.js +24 -21
  85. package/lib/dependencies/AMDRequireDependency.js +6 -6
  86. package/lib/dependencies/CommonJsExportsParserPlugin.js +1 -2
  87. package/lib/dependencies/CommonJsFullRequireDependency.js +5 -1
  88. package/lib/dependencies/CommonJsImportsParserPlugin.js +344 -61
  89. package/lib/dependencies/CommonJsRequireContextDependency.js +6 -2
  90. package/lib/dependencies/CommonJsRequireDependency.js +2 -1
  91. package/lib/dependencies/ContextDependency.js +16 -2
  92. package/lib/dependencies/ContextDependencyHelpers.js +21 -8
  93. package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +4 -1
  94. package/lib/dependencies/ContextElementDependency.js +25 -3
  95. package/lib/dependencies/CreateScriptUrlDependency.js +12 -0
  96. package/lib/dependencies/CssExportDependency.js +85 -0
  97. package/lib/dependencies/CssImportDependency.js +75 -0
  98. package/lib/dependencies/CssLocalIdentifierDependency.js +119 -0
  99. package/lib/dependencies/CssSelfLocalIdentifierDependency.js +101 -0
  100. package/lib/dependencies/CssUrlDependency.js +132 -0
  101. package/lib/dependencies/ExportsInfoDependency.js +6 -0
  102. package/lib/dependencies/HarmonyAcceptImportDependency.js +5 -3
  103. package/lib/dependencies/HarmonyCompatibilityDependency.js +5 -5
  104. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +127 -0
  105. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +12 -3
  106. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +25 -17
  107. package/lib/dependencies/HarmonyExportInitFragment.js +4 -1
  108. package/lib/dependencies/HarmonyImportDependency.js +23 -0
  109. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +142 -45
  110. package/lib/dependencies/HarmonyImportSpecifierDependency.js +46 -22
  111. package/lib/dependencies/HarmonyModulesPlugin.js +10 -0
  112. package/lib/dependencies/ImportContextDependency.js +0 -2
  113. package/lib/dependencies/ImportMetaContextDependency.js +35 -0
  114. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +252 -0
  115. package/lib/dependencies/ImportMetaContextPlugin.js +59 -0
  116. package/lib/dependencies/ImportMetaPlugin.js +22 -3
  117. package/lib/dependencies/ImportParserPlugin.js +35 -29
  118. package/lib/dependencies/JsonExportsDependency.js +17 -21
  119. package/lib/dependencies/LoaderDependency.js +13 -0
  120. package/lib/dependencies/LoaderImportDependency.js +13 -0
  121. package/lib/dependencies/LoaderPlugin.js +4 -2
  122. package/lib/dependencies/ModuleDependency.js +11 -1
  123. package/lib/dependencies/ProvidedDependency.js +31 -8
  124. package/lib/dependencies/RequireContextDependency.js +0 -16
  125. package/lib/dependencies/RequireEnsureDependency.js +2 -2
  126. package/lib/dependencies/RequireResolveContextDependency.js +2 -2
  127. package/lib/dependencies/RequireResolveDependency.js +2 -1
  128. package/lib/dependencies/URLDependency.js +3 -8
  129. package/lib/dependencies/URLPlugin.js +22 -1
  130. package/lib/dependencies/WorkerPlugin.js +2 -0
  131. package/lib/esm/ModuleChunkFormatPlugin.js +74 -49
  132. package/lib/esm/ModuleChunkLoadingPlugin.js +3 -1
  133. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +25 -9
  134. package/lib/hmr/HotModuleReplacement.runtime.js +29 -14
  135. package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +4 -3
  136. package/lib/hmr/LazyCompilationPlugin.js +54 -26
  137. package/lib/hmr/lazyCompilationBackend.js +51 -12
  138. package/lib/ids/DeterministicModuleIdsPlugin.js +55 -35
  139. package/lib/ids/HashedModuleIdsPlugin.js +11 -14
  140. package/lib/ids/IdHelpers.js +26 -12
  141. package/lib/ids/NamedModuleIdsPlugin.js +6 -9
  142. package/lib/ids/NaturalModuleIdsPlugin.js +10 -13
  143. package/lib/ids/OccurrenceModuleIdsPlugin.js +13 -10
  144. package/lib/ids/SyncModuleIdsPlugin.js +140 -0
  145. package/lib/index.js +20 -0
  146. package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +2 -2
  147. package/lib/javascript/BasicEvaluatedExpression.js +5 -2
  148. package/lib/javascript/ChunkHelpers.js +33 -0
  149. package/lib/javascript/JavascriptGenerator.js +1 -0
  150. package/lib/javascript/JavascriptModulesPlugin.js +27 -2
  151. package/lib/javascript/JavascriptParser.js +143 -73
  152. package/lib/javascript/StartupHelpers.js +7 -30
  153. package/lib/json/JsonData.js +8 -0
  154. package/lib/json/JsonParser.js +4 -6
  155. package/lib/library/AssignLibraryPlugin.js +39 -15
  156. package/lib/library/EnableLibraryPlugin.js +11 -0
  157. package/lib/library/UmdLibraryPlugin.js +5 -3
  158. package/lib/node/NodeTargetPlugin.js +3 -0
  159. package/lib/node/NodeWatchFileSystem.js +85 -31
  160. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +23 -8
  161. package/lib/node/RequireChunkLoadingRuntimeModule.js +24 -9
  162. package/lib/optimize/ConcatenatedModule.js +62 -26
  163. package/lib/optimize/ModuleConcatenationPlugin.js +26 -4
  164. package/lib/optimize/RealContentHashPlugin.js +45 -15
  165. package/lib/optimize/SplitChunksPlugin.js +8 -1
  166. package/lib/runtime/AsyncModuleRuntimeModule.js +50 -66
  167. package/lib/runtime/BaseUriRuntimeModule.js +31 -0
  168. package/lib/runtime/CreateScriptRuntimeModule.js +36 -0
  169. package/lib/runtime/CreateScriptUrlRuntimeModule.js +9 -34
  170. package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +76 -0
  171. package/lib/runtime/LoadScriptRuntimeModule.js +11 -9
  172. package/lib/runtime/NonceRuntimeModule.js +24 -0
  173. package/lib/schemes/HttpUriPlugin.js +77 -14
  174. package/lib/serialization/FileMiddleware.js +44 -9
  175. package/lib/sharing/ConsumeSharedModule.js +8 -2
  176. package/lib/sharing/ConsumeSharedRuntimeModule.js +26 -5
  177. package/lib/sharing/ProvideSharedModule.js +4 -2
  178. package/lib/sharing/ProvideSharedPlugin.js +1 -2
  179. package/lib/sharing/ShareRuntimeModule.js +1 -1
  180. package/lib/sharing/utils.js +1 -1
  181. package/lib/stats/DefaultStatsFactoryPlugin.js +113 -68
  182. package/lib/stats/DefaultStatsPrinterPlugin.js +90 -25
  183. package/lib/util/ArrayHelpers.js +30 -0
  184. package/lib/util/AsyncQueue.js +1 -1
  185. package/lib/util/compileBooleanMatcher.js +1 -1
  186. package/lib/util/create-schema-validation.js +9 -2
  187. package/lib/util/createHash.js +12 -0
  188. package/lib/util/deprecation.js +10 -2
  189. package/lib/util/deterministicGrouping.js +1 -1
  190. package/lib/util/extractUrlAndGlobal.js +3 -0
  191. package/lib/util/fs.js +11 -0
  192. package/lib/util/hash/BatchedHash.js +7 -4
  193. package/lib/util/hash/md4.js +20 -0
  194. package/lib/util/hash/wasm-hash.js +163 -0
  195. package/lib/util/hash/xxhash64.js +5 -139
  196. package/lib/util/identifier.js +65 -44
  197. package/lib/util/internalSerializables.js +15 -0
  198. package/lib/util/nonNumericOnlyHash.js +22 -0
  199. package/lib/util/semver.js +17 -10
  200. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +9 -3
  201. package/lib/wasm-sync/WebAssemblyParser.js +1 -1
  202. package/lib/web/JsonpChunkLoadingRuntimeModule.js +31 -18
  203. package/lib/webpack.js +10 -3
  204. package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +3 -11
  205. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +33 -22
  206. package/module.d.ts +215 -0
  207. package/package.json +28 -32
  208. package/schemas/WebpackOptions.check.js +1 -1
  209. package/schemas/WebpackOptions.json +321 -30
  210. package/schemas/plugins/BannerPlugin.check.js +1 -1
  211. package/schemas/plugins/BannerPlugin.json +4 -0
  212. package/schemas/plugins/DllReferencePlugin.check.js +1 -1
  213. package/schemas/plugins/HashedModuleIdsPlugin.check.js +1 -1
  214. package/schemas/plugins/ProgressPlugin.check.js +1 -1
  215. package/schemas/plugins/asset/AssetGeneratorOptions.check.js +1 -1
  216. package/schemas/plugins/asset/AssetParserOptions.check.js +1 -1
  217. package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.js +1 -1
  218. package/schemas/plugins/container/ContainerPlugin.check.js +1 -1
  219. package/schemas/plugins/container/ContainerPlugin.json +2 -1
  220. package/schemas/plugins/container/ContainerReferencePlugin.check.js +1 -1
  221. package/schemas/plugins/container/ContainerReferencePlugin.json +1 -0
  222. package/schemas/plugins/container/ExternalsType.check.js +1 -1
  223. package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
  224. package/schemas/plugins/container/ModuleFederationPlugin.json +3 -1
  225. package/schemas/plugins/css/CssGeneratorOptions.check.d.ts +7 -0
  226. package/schemas/plugins/css/CssGeneratorOptions.check.js +6 -0
  227. package/schemas/plugins/css/CssGeneratorOptions.json +3 -0
  228. package/schemas/plugins/css/CssParserOptions.check.d.ts +7 -0
  229. package/schemas/plugins/css/CssParserOptions.check.js +6 -0
  230. package/schemas/plugins/css/CssParserOptions.json +3 -0
  231. package/schemas/plugins/optimize/AggressiveSplittingPlugin.check.js +1 -1
  232. package/schemas/plugins/optimize/LimitChunkCountPlugin.check.js +1 -1
  233. package/schemas/plugins/optimize/MinChunkSizePlugin.check.js +1 -1
  234. package/schemas/plugins/schemes/HttpUriPlugin.check.js +1 -1
  235. package/schemas/plugins/schemes/HttpUriPlugin.json +4 -0
  236. package/types.d.ts +869 -296
@@ -16,6 +16,7 @@ const {
16
16
  } = require("./target");
17
17
 
18
18
  /** @typedef {import("../../declarations/WebpackOptions").CacheOptionsNormalized} CacheOptions */
19
+ /** @typedef {import("../../declarations/WebpackOptions").CssExperimentOptions} CssExperimentOptions */
19
20
  /** @typedef {import("../../declarations/WebpackOptions").EntryDescription} EntryDescription */
20
21
  /** @typedef {import("../../declarations/WebpackOptions").EntryNormalized} Entry */
21
22
  /** @typedef {import("../../declarations/WebpackOptions").Experiments} Experiments */
@@ -160,7 +161,11 @@ const applyWebpackOptionsDefaults = options => {
160
161
  D(options, "recordsInputPath", false);
161
162
  D(options, "recordsOutputPath", false);
162
163
 
163
- applyExperimentsDefaults(options.experiments, { production, development });
164
+ applyExperimentsDefaults(options.experiments, {
165
+ production,
166
+ development,
167
+ targetProperties
168
+ });
164
169
 
165
170
  const futureDefaults = options.experiments.futureDefaults;
166
171
 
@@ -183,7 +188,10 @@ const applyWebpackOptionsDefaults = options => {
183
188
  applyModuleDefaults(options.module, {
184
189
  cache,
185
190
  syncWebAssembly: options.experiments.syncWebAssembly,
186
- asyncWebAssembly: options.experiments.asyncWebAssembly
191
+ asyncWebAssembly: options.experiments.asyncWebAssembly,
192
+ css: options.experiments.css,
193
+ futureDefaults,
194
+ isNode: targetProperties && targetProperties.node === true
187
195
  });
188
196
 
189
197
  applyOutputDefaults(options.output, {
@@ -238,6 +246,7 @@ const applyWebpackOptionsDefaults = options => {
238
246
  applyOptimizationDefaults(options.optimization, {
239
247
  development,
240
248
  production,
249
+ css: options.experiments.css,
241
250
  records: !!(options.recordsInputPath || options.recordsOutputPath)
242
251
  });
243
252
 
@@ -262,24 +271,37 @@ const applyWebpackOptionsDefaults = options => {
262
271
  * @param {Object} options options
263
272
  * @param {boolean} options.production is production
264
273
  * @param {boolean} options.development is development mode
274
+ * @param {TargetProperties | false} options.targetProperties target properties
265
275
  * @returns {void}
266
276
  */
267
- const applyExperimentsDefaults = (experiments, { production, development }) => {
268
- D(experiments, "topLevelAwait", false);
277
+ const applyExperimentsDefaults = (
278
+ experiments,
279
+ { production, development, targetProperties }
280
+ ) => {
281
+ D(experiments, "futureDefaults", false);
282
+ D(experiments, "backCompat", !experiments.futureDefaults);
283
+ D(experiments, "topLevelAwait", experiments.futureDefaults);
269
284
  D(experiments, "syncWebAssembly", false);
270
- D(experiments, "asyncWebAssembly", false);
285
+ D(experiments, "asyncWebAssembly", experiments.futureDefaults);
271
286
  D(experiments, "outputModule", false);
272
- D(experiments, "asset", false);
273
287
  D(experiments, "layers", false);
274
288
  D(experiments, "lazyCompilation", undefined);
275
289
  D(experiments, "buildHttp", undefined);
276
- D(experiments, "futureDefaults", false);
277
290
  D(experiments, "cacheUnaffected", experiments.futureDefaults);
291
+ F(experiments, "css", () => (experiments.futureDefaults ? {} : undefined));
278
292
 
279
293
  if (typeof experiments.buildHttp === "object") {
280
294
  D(experiments.buildHttp, "frozen", production);
281
295
  D(experiments.buildHttp, "upgrade", false);
282
296
  }
297
+
298
+ if (typeof experiments.css === "object") {
299
+ D(
300
+ experiments.css,
301
+ "exportsOnly",
302
+ !targetProperties || !targetProperties.document
303
+ );
304
+ }
283
305
  };
284
306
 
285
307
  /**
@@ -382,7 +404,7 @@ const applySnapshotDefaults = (snapshot, { production, futureDefaults }) => {
382
404
  return [path.resolve(match[1], "unplugged")];
383
405
  }
384
406
  } else {
385
- const match = /^(.+?[\\/]node_modules)[\\/]/.exec(
407
+ const match = /^(.+?[\\/]node_modules[\\/])/.exec(
386
408
  // eslint-disable-next-line node/no-extraneous-require
387
409
  require.resolve("watchpack")
388
410
  );
@@ -428,9 +450,15 @@ const applySnapshotDefaults = (snapshot, { production, futureDefaults }) => {
428
450
 
429
451
  /**
430
452
  * @param {JavascriptParserOptions} parserOptions parser options
453
+ * @param {Object} options options
454
+ * @param {boolean} options.futureDefaults is future defaults enabled
455
+ * @param {boolean} options.isNode is node target platform
431
456
  * @returns {void}
432
457
  */
433
- const applyJavascriptParserOptionsDefaults = parserOptions => {
458
+ const applyJavascriptParserOptionsDefaults = (
459
+ parserOptions,
460
+ { futureDefaults, isNode }
461
+ ) => {
434
462
  D(parserOptions, "unknownContextRequest", ".");
435
463
  D(parserOptions, "unknownContextRegExp", false);
436
464
  D(parserOptions, "unknownContextRecursive", true);
@@ -442,9 +470,13 @@ const applyJavascriptParserOptionsDefaults = parserOptions => {
442
470
  D(parserOptions, "wrappedContextRegExp", /.*/);
443
471
  D(parserOptions, "wrappedContextRecursive", true);
444
472
  D(parserOptions, "wrappedContextCritical", false);
445
-
446
- D(parserOptions, "strictExportPresence", false);
447
473
  D(parserOptions, "strictThisContextOnImports", false);
474
+ D(parserOptions, "importMeta", true);
475
+ D(parserOptions, "dynamicImportMode", "lazy");
476
+ D(parserOptions, "dynamicImportPrefetch", false);
477
+ D(parserOptions, "dynamicImportPreload", false);
478
+ D(parserOptions, "createRequire", isNode);
479
+ if (futureDefaults) D(parserOptions, "exportsPresence", "error");
448
480
  };
449
481
 
450
482
  /**
@@ -453,11 +485,14 @@ const applyJavascriptParserOptionsDefaults = parserOptions => {
453
485
  * @param {boolean} options.cache is caching enabled
454
486
  * @param {boolean} options.syncWebAssembly is syncWebAssembly enabled
455
487
  * @param {boolean} options.asyncWebAssembly is asyncWebAssembly enabled
488
+ * @param {CssExperimentOptions|false} options.css is css enabled
489
+ * @param {boolean} options.futureDefaults is future defaults enabled
490
+ * @param {boolean} options.isNode is node target platform
456
491
  * @returns {void}
457
492
  */
458
493
  const applyModuleDefaults = (
459
494
  module,
460
- { cache, syncWebAssembly, asyncWebAssembly }
495
+ { cache, syncWebAssembly, asyncWebAssembly, css, futureDefaults, isNode }
461
496
  ) => {
462
497
  if (cache) {
463
498
  D(module, "unsafeCache", module => {
@@ -475,7 +510,10 @@ const applyModuleDefaults = (
475
510
  }
476
511
 
477
512
  F(module.parser, "javascript", () => ({}));
478
- applyJavascriptParserOptionsDefaults(module.parser.javascript);
513
+ applyJavascriptParserOptionsDefaults(module.parser.javascript, {
514
+ futureDefaults,
515
+ isNode
516
+ });
479
517
 
480
518
  A(module, "defaultRules", () => {
481
519
  const esm = {
@@ -579,6 +617,41 @@ const applyModuleDefaults = (
579
617
  ...wasm
580
618
  });
581
619
  }
620
+ if (css) {
621
+ const cssRule = {
622
+ type: "css",
623
+ resolve: {
624
+ fullySpecified: true,
625
+ preferRelative: true
626
+ }
627
+ };
628
+ const cssModulesRule = {
629
+ type: "css/module",
630
+ resolve: {
631
+ fullySpecified: true
632
+ }
633
+ };
634
+ rules.push({
635
+ test: /\.css$/i,
636
+ oneOf: [
637
+ {
638
+ test: /\.module\.css$/i,
639
+ ...cssModulesRule
640
+ },
641
+ {
642
+ ...cssRule
643
+ }
644
+ ]
645
+ });
646
+ rules.push({
647
+ mimetype: "text/css+module",
648
+ ...cssModulesRule
649
+ });
650
+ rules.push({
651
+ mimetype: "text/css",
652
+ ...cssRule
653
+ });
654
+ }
582
655
  rules.push(
583
656
  {
584
657
  dependency: "url",
@@ -650,7 +723,15 @@ const applyOutputDefaults = (
650
723
  };
651
724
 
652
725
  F(output, "uniqueName", () => {
653
- const libraryName = getLibraryName(output.library);
726
+ const libraryName = getLibraryName(output.library).replace(
727
+ /^\[(\\*[\w:]+\\*)\](\.)|(\.)\[(\\*[\w:]+\\*)\](?=\.|$)|\[(\\*[\w:]+\\*)\]/g,
728
+ (m, a, d1, d2, b, c) => {
729
+ const content = a || b || c;
730
+ return content.startsWith("\\") && content.endsWith("\\")
731
+ ? `${d2 || ""}[${content.slice(1, -1)}]${d1 || ""}`
732
+ : "";
733
+ }
734
+ );
654
735
  if (libraryName) return libraryName;
655
736
  const pkgPath = path.resolve(context, "package.json");
656
737
  try {
@@ -684,6 +765,20 @@ const applyOutputDefaults = (
684
765
  }
685
766
  return output.module ? "[id].mjs" : "[id].js";
686
767
  });
768
+ F(output, "cssFilename", () => {
769
+ const filename = output.filename;
770
+ if (typeof filename !== "function") {
771
+ return filename.replace(/\.[mc]?js(\?|$)/, ".css$1");
772
+ }
773
+ return "[id].css";
774
+ });
775
+ F(output, "cssChunkFilename", () => {
776
+ const chunkFilename = output.chunkFilename;
777
+ if (typeof chunkFilename !== "function") {
778
+ return chunkFilename.replace(/\.[mc]?js(\?|$)/, ".css$1");
779
+ }
780
+ return "[id].css";
781
+ });
687
782
  D(output, "assetModuleFilename", "[hash][ext][query]");
688
783
  D(output, "webassemblyModuleFilename", "[hash].module.wasm");
689
784
  D(output, "compareBeforeEmit", true);
@@ -736,6 +831,7 @@ const applyOutputDefaults = (
736
831
  "Chunk format can't be selected by default when no target is specified"
737
832
  );
738
833
  });
834
+ D(output, "asyncChunks", true);
739
835
  F(output, "chunkLoading", () => {
740
836
  if (tp) {
741
837
  switch (output.chunkFormat) {
@@ -823,10 +919,11 @@ const applyOutputDefaults = (
823
919
  D(output, "chunkLoadTimeout", 120000);
824
920
  D(output, "hashFunction", futureDefaults ? "xxhash64" : "md4");
825
921
  D(output, "hashDigest", "hex");
826
- D(output, "hashDigestLength", 20);
922
+ D(output, "hashDigestLength", futureDefaults ? 16 : 20);
827
923
  D(output, "strictModuleExceptionHandling", false);
828
924
 
829
925
  const optimistic = v => v || v === undefined;
926
+ const conditionallyOptimistic = (v, c) => (v === undefined && c) || v;
830
927
  F(
831
928
  output.environment,
832
929
  "arrowFunction",
@@ -840,8 +937,12 @@ const applyOutputDefaults = (
840
937
  );
841
938
  F(output.environment, "forOf", () => tp && optimistic(tp.forOf));
842
939
  F(output.environment, "bigIntLiteral", () => tp && tp.bigIntLiteral);
843
- F(output.environment, "dynamicImport", () => tp && tp.dynamicImport);
844
- F(output.environment, "module", () => tp && tp.module);
940
+ F(output.environment, "dynamicImport", () =>
941
+ conditionallyOptimistic(tp && tp.dynamicImport, output.module)
942
+ );
943
+ F(output.environment, "module", () =>
944
+ conditionallyOptimistic(tp && tp.module, output.module)
945
+ );
845
946
 
846
947
  const { trustedTypes } = output;
847
948
  if (trustedTypes) {
@@ -1021,12 +1122,13 @@ const applyPerformanceDefaults = (performance, { production }) => {
1021
1122
  * @param {Object} options options
1022
1123
  * @param {boolean} options.production is production
1023
1124
  * @param {boolean} options.development is development
1125
+ * @param {CssExperimentOptions|false} options.css is css enabled
1024
1126
  * @param {boolean} options.records using records
1025
1127
  * @returns {void}
1026
1128
  */
1027
1129
  const applyOptimizationDefaults = (
1028
1130
  optimization,
1029
- { production, development, records }
1131
+ { production, development, css, records }
1030
1132
  ) => {
1031
1133
  D(optimization, "removeAvailableModules", false);
1032
1134
  D(optimization, "removeEmptyChunks", true);
@@ -1077,7 +1179,9 @@ const applyOptimizationDefaults = (
1077
1179
  });
1078
1180
  const { splitChunks } = optimization;
1079
1181
  if (splitChunks) {
1080
- A(splitChunks, "defaultSizeTypes", () => ["javascript", "unknown"]);
1182
+ A(splitChunks, "defaultSizeTypes", () =>
1183
+ css ? ["javascript", "css", "unknown"] : ["javascript", "unknown"]
1184
+ );
1081
1185
  D(splitChunks, "hidePathInfo", production);
1082
1186
  D(splitChunks, "chunks", "async");
1083
1187
  D(splitChunks, "usedExports", optimization.usedExports === true);
@@ -178,8 +178,10 @@ const getNormalizedWebpackOptions = config => {
178
178
  ),
179
179
  lazyCompilation: optionalNestedConfig(
180
180
  experiments.lazyCompilation,
181
- options =>
182
- options === true ? {} : options === false ? undefined : options
181
+ options => (options === true ? {} : options)
182
+ ),
183
+ css: optionalNestedConfig(experiments.css, options =>
184
+ options === true ? {} : options
183
185
  )
184
186
  })),
185
187
  externals: config.externals,
@@ -229,6 +231,7 @@ const getNormalizedWebpackOptions = config => {
229
231
  wrappedContextRegExp: module.wrappedContextRegExp,
230
232
  wrappedContextRecursive: module.wrappedContextRecursive,
231
233
  wrappedContextCritical: module.wrappedContextCritical,
234
+ // TODO webpack 6 remove
232
235
  strictExportPresence: module.strictExportPresence,
233
236
  strictThisContextOnImports: module.strictThisContextOnImports,
234
237
  ...parserOptions
@@ -289,12 +292,15 @@ const getNormalizedWebpackOptions = config => {
289
292
  /** @type {OutputNormalized} */
290
293
  const result = {
291
294
  assetModuleFilename: output.assetModuleFilename,
295
+ asyncChunks: output.asyncChunks,
292
296
  charset: output.charset,
293
297
  chunkFilename: output.chunkFilename,
294
298
  chunkFormat: output.chunkFormat,
295
299
  chunkLoading: output.chunkLoading,
296
300
  chunkLoadingGlobal: output.chunkLoadingGlobal,
297
301
  chunkLoadTimeout: output.chunkLoadTimeout,
302
+ cssFilename: output.cssFilename,
303
+ cssChunkFilename: output.cssChunkFilename,
298
304
  clean: output.clean,
299
305
  compareBeforeEmit: output.compareBeforeEmit,
300
306
  crossOriginLoading: output.crossOriginLoading,
@@ -481,8 +487,10 @@ const getNormalizedEntryStatic = entry => {
481
487
  filename: value.filename,
482
488
  layer: value.layer,
483
489
  runtime: value.runtime,
490
+ baseUri: value.baseUri,
484
491
  publicPath: value.publicPath,
485
492
  chunkLoading: value.chunkLoading,
493
+ asyncChunks: value.asyncChunks,
486
494
  wasmLoading: value.wasmLoading,
487
495
  dependOn:
488
496
  value.dependOn &&
@@ -59,6 +59,8 @@ const getDefaultTarget = context => {
59
59
  * @property {boolean | null} dynamicImport async import() is available
60
60
  * @property {boolean | null} dynamicImportInWorker async import() is available when creating a worker
61
61
  * @property {boolean | null} module ESM syntax is available (when in module)
62
+ * @property {boolean | null} optionalChaining optional chaining is available
63
+ * @property {boolean | null} templateLiteral template literal is available
62
64
  */
63
65
 
64
66
  ///** @typedef {PlatformTargetProperties | ApiTargetProperties | EcmaTargetProperties | PlatformTargetProperties & ApiTargetProperties | PlatformTargetProperties & EcmaTargetProperties | ApiTargetProperties & EcmaTargetProperties} TargetProperties */
@@ -167,6 +169,8 @@ You can also more options via the 'target' option: 'browserslist' / 'browserslis
167
169
 
168
170
  globalThis: v(12),
169
171
  const: v(6),
172
+ templateLiteral: v(4),
173
+ optionalChaining: v(14),
170
174
  arrowFunction: v(6),
171
175
  forOf: v(5),
172
176
  destructuring: v(6),
@@ -206,6 +210,8 @@ You can also more options via the 'target' option: 'browserslist' / 'browserslis
206
210
 
207
211
  globalThis: v(5),
208
212
  const: v(1, 1),
213
+ templateLiteral: v(1, 1),
214
+ optionalChaining: v(8),
209
215
  arrowFunction: v(1, 1),
210
216
  forOf: v(0, 36),
211
217
  destructuring: v(1, 1),
@@ -241,6 +247,8 @@ You can also more options via the 'target' option: 'browserslist' / 'browserslis
241
247
 
242
248
  globalThis: v(0, 43),
243
249
  const: v(0, 15),
250
+ templateLiteral: v(0, 13),
251
+ optionalChaining: v(0, 44),
244
252
  arrowFunction: v(0, 15),
245
253
  forOf: v(0, 13),
246
254
  destructuring: v(0, 15),
@@ -260,6 +268,8 @@ You can also more options via the 'target' option: 'browserslist' / 'browserslis
260
268
  if (v < 1000) v = v + 2009;
261
269
  return {
262
270
  const: v >= 2015,
271
+ templateLiteral: v >= 2015,
272
+ optionalChaining: v >= 2020,
263
273
  arrowFunction: v >= 2015,
264
274
  forOf: v >= 2015,
265
275
  destructuring: v >= 2015,
@@ -10,6 +10,7 @@ const AsyncDependenciesBlock = require("../AsyncDependenciesBlock");
10
10
  const Module = require("../Module");
11
11
  const RuntimeGlobals = require("../RuntimeGlobals");
12
12
  const Template = require("../Template");
13
+ const StaticExportsDependency = require("../dependencies/StaticExportsDependency");
13
14
  const makeSerializable = require("../util/makeSerializable");
14
15
  const ContainerExposedDependency = require("./ContainerExposedDependency");
15
16
 
@@ -78,12 +79,14 @@ class ContainerEntryModule extends Module {
78
79
  * @returns {string | null} an identifier for library inclusion
79
80
  */
80
81
  libIdent(options) {
81
- return `webpack/container/entry/${this._name}`;
82
+ return `${this.layer ? `(${this.layer})/` : ""}webpack/container/entry/${
83
+ this._name
84
+ }`;
82
85
  }
83
86
 
84
87
  /**
85
88
  * @param {NeedBuildContext} context context info
86
- * @param {function(WebpackError=, boolean=): void} callback callback function, returns true, if the module needs a rebuild
89
+ * @param {function((WebpackError | null)=, boolean=): void} callback callback function, returns true, if the module needs a rebuild
87
90
  * @returns {void}
88
91
  */
89
92
  needBuild(context, callback) {
@@ -104,6 +107,7 @@ class ContainerEntryModule extends Module {
104
107
  strict: true,
105
108
  topLevelDeclarations: new Set(["moduleMap", "get", "init"])
106
109
  };
110
+ this.buildMeta.exportsType = "namespace";
107
111
 
108
112
  this.clearDependenciesAndBlocks();
109
113
 
@@ -127,6 +131,7 @@ class ContainerEntryModule extends Module {
127
131
  }
128
132
  this.addBlock(block);
129
133
  }
134
+ this.addDependency(new StaticExportsDependency(["get", "init"], false));
130
135
 
131
136
  callback();
132
137
  }
@@ -217,10 +222,8 @@ class ContainerEntryModule extends Module {
217
222
  ])};`,
218
223
  `var init = ${runtimeTemplate.basicFunction("shareScope, initScope", [
219
224
  `if (!${RuntimeGlobals.shareScopeMap}) return;`,
220
- `var oldScope = ${RuntimeGlobals.shareScopeMap}[${JSON.stringify(
221
- this._shareScope
222
- )}];`,
223
225
  `var name = ${JSON.stringify(this._shareScope)}`,
226
+ `var oldScope = ${RuntimeGlobals.shareScopeMap}[name];`,
224
227
  `if(oldScope && oldScope !== shareScope) throw new Error("Container initialization failed as it has already been initialized with a different share scope");`,
225
228
  `${RuntimeGlobals.shareScopeMap}[name] = shareScope;`,
226
229
  `return ${RuntimeGlobals.initializeSharing}(name, initScope);`
@@ -60,9 +60,9 @@ class FallbackModule extends Module {
60
60
  * @returns {string | null} an identifier for library inclusion
61
61
  */
62
62
  libIdent(options) {
63
- return `webpack/container/fallback/${this.requests[0]}/and ${
64
- this.requests.length - 1
65
- } more`;
63
+ return `${this.layer ? `(${this.layer})/` : ""}webpack/container/fallback/${
64
+ this.requests[0]
65
+ }/and ${this.requests.length - 1} more`;
66
66
  }
67
67
 
68
68
  /**
@@ -76,7 +76,7 @@ class FallbackModule extends Module {
76
76
 
77
77
  /**
78
78
  * @param {NeedBuildContext} context context info
79
- * @param {function(WebpackError=, boolean=): void} callback callback function, returns true, if the module needs a rebuild
79
+ * @param {function((WebpackError | null)=, boolean=): void} callback callback function, returns true, if the module needs a rebuild
80
80
  * @returns {void}
81
81
  */
82
82
  needBuild(context, callback) {
@@ -65,6 +65,7 @@ class ModuleFederationPlugin {
65
65
  library,
66
66
  filename: options.filename,
67
67
  runtime: options.runtime,
68
+ shareScope: options.shareScope,
68
69
  exposes: options.exposes
69
70
  }).apply(compiler);
70
71
  }
@@ -76,6 +77,7 @@ class ModuleFederationPlugin {
76
77
  ) {
77
78
  new ContainerReferencePlugin({
78
79
  remoteType,
80
+ shareScope: options.shareScope,
79
81
  remotes: options.remotes
80
82
  }).apply(compiler);
81
83
  }
@@ -67,12 +67,14 @@ class RemoteModule extends Module {
67
67
  * @returns {string | null} an identifier for library inclusion
68
68
  */
69
69
  libIdent(options) {
70
- return `webpack/container/remote/${this.request}`;
70
+ return `${this.layer ? `(${this.layer})/` : ""}webpack/container/remote/${
71
+ this.request
72
+ }`;
71
73
  }
72
74
 
73
75
  /**
74
76
  * @param {NeedBuildContext} context context info
75
- * @param {function(WebpackError=, boolean=): void} callback callback function, returns true, if the module needs a rebuild
77
+ * @param {function((WebpackError | null)=, boolean=): void} callback callback function, returns true, if the module needs a rebuild
76
78
  * @returns {void}
77
79
  */
78
80
  needBuild(context, callback) {
@@ -73,9 +73,9 @@ class RemoteRuntimeModule extends RuntimeModule {
73
73
  Template.indent(
74
74
  `error.message += '\\nwhile loading "' + data[1] + '" from ' + data[2];`
75
75
  ),
76
- `__webpack_modules__[id] = ${runtimeTemplate.basicFunction("", [
77
- "throw error;"
78
- ])}`,
76
+ `${
77
+ RuntimeGlobals.moduleFactories
78
+ }[id] = ${runtimeTemplate.basicFunction("", ["throw error;"])}`,
79
79
  "data.p = 0;"
80
80
  ])};`,
81
81
  `var handleFunction = ${runtimeTemplate.basicFunction(
@@ -111,10 +111,11 @@ class RemoteRuntimeModule extends RuntimeModule {
111
111
  )};`,
112
112
  `var onFactory = ${runtimeTemplate.basicFunction("factory", [
113
113
  "data.p = 1;",
114
- `__webpack_modules__[id] = ${runtimeTemplate.basicFunction(
115
- "module",
116
- ["module.exports = factory();"]
117
- )}`
114
+ `${
115
+ RuntimeGlobals.moduleFactories
116
+ }[id] = ${runtimeTemplate.basicFunction("module", [
117
+ "module.exports = factory();"
118
+ ])}`
118
119
  ])};`,
119
120
  "handleFunction(__webpack_require__, data[2], 0, 0, onExternal, 1);"
120
121
  ])});`
@@ -0,0 +1,139 @@
1
+ /*
2
+ MIT License http://www.opensource.org/licenses/mit-license.php
3
+ Author Sergey Melyukov @smelukov
4
+ */
5
+
6
+ "use strict";
7
+
8
+ const { ReplaceSource, RawSource, ConcatSource } = require("webpack-sources");
9
+ const { UsageState } = require("../ExportsInfo");
10
+ const Generator = require("../Generator");
11
+ const RuntimeGlobals = require("../RuntimeGlobals");
12
+ const Template = require("../Template");
13
+
14
+ /** @typedef {import("webpack-sources").Source} Source */
15
+ /** @typedef {import("../Dependency")} Dependency */
16
+ /** @typedef {import("../Generator").GenerateContext} GenerateContext */
17
+ /** @typedef {import("../Generator").UpdateHashContext} UpdateHashContext */
18
+ /** @typedef {import("../Module").ConcatenationBailoutReasonContext} ConcatenationBailoutReasonContext */
19
+ /** @typedef {import("../NormalModule")} NormalModule */
20
+ /** @typedef {import("../util/Hash")} Hash */
21
+
22
+ const TYPES = new Set(["javascript"]);
23
+
24
+ class CssExportsGenerator extends Generator {
25
+ constructor() {
26
+ super();
27
+ }
28
+
29
+ // TODO add getConcatenationBailoutReason to allow concatenation
30
+ // but how to make it have a module id
31
+
32
+ /**
33
+ * @param {NormalModule} module module for which the code should be generated
34
+ * @param {GenerateContext} generateContext context for generate
35
+ * @returns {Source} generated code
36
+ */
37
+ generate(module, generateContext) {
38
+ const source = new ReplaceSource(new RawSource(""));
39
+ const initFragments = [];
40
+ const cssExports = new Map();
41
+
42
+ generateContext.runtimeRequirements.add(RuntimeGlobals.module);
43
+
44
+ const runtimeRequirements = new Set();
45
+
46
+ const templateContext = {
47
+ runtimeTemplate: generateContext.runtimeTemplate,
48
+ dependencyTemplates: generateContext.dependencyTemplates,
49
+ moduleGraph: generateContext.moduleGraph,
50
+ chunkGraph: generateContext.chunkGraph,
51
+ module,
52
+ runtime: generateContext.runtime,
53
+ runtimeRequirements: runtimeRequirements,
54
+ concatenationScope: generateContext.concatenationScope,
55
+ codeGenerationResults: generateContext.codeGenerationResults,
56
+ initFragments,
57
+ cssExports
58
+ };
59
+
60
+ const handleDependency = dependency => {
61
+ const constructor = /** @type {new (...args: any[]) => Dependency} */ (
62
+ dependency.constructor
63
+ );
64
+ const template = generateContext.dependencyTemplates.get(constructor);
65
+ if (!template) {
66
+ throw new Error(
67
+ "No template for dependency: " + dependency.constructor.name
68
+ );
69
+ }
70
+
71
+ template.apply(dependency, source, templateContext);
72
+ };
73
+ module.dependencies.forEach(handleDependency);
74
+
75
+ if (generateContext.concatenationScope) {
76
+ const source = new ConcatSource();
77
+ const usedIdentifiers = new Set();
78
+ for (const [k, v] of cssExports) {
79
+ let identifier = Template.toIdentifier(k);
80
+ let i = 0;
81
+ while (usedIdentifiers.has(identifier)) {
82
+ identifier = Template.toIdentifier(k + i);
83
+ }
84
+ usedIdentifiers.add(identifier);
85
+ generateContext.concatenationScope.registerExport(k, identifier);
86
+ source.add(
87
+ `${
88
+ generateContext.runtimeTemplate.supportsConst ? "const" : "var"
89
+ } ${identifier} = ${JSON.stringify(v)};\n`
90
+ );
91
+ }
92
+ return source;
93
+ } else {
94
+ const otherUsed =
95
+ generateContext.moduleGraph
96
+ .getExportsInfo(module)
97
+ .otherExportsInfo.getUsed(generateContext.runtime) !==
98
+ UsageState.Unused;
99
+ if (otherUsed) {
100
+ generateContext.runtimeRequirements.add(
101
+ RuntimeGlobals.makeNamespaceObject
102
+ );
103
+ }
104
+ return new RawSource(
105
+ `${otherUsed ? `${RuntimeGlobals.makeNamespaceObject}(` : ""}${
106
+ module.moduleArgument
107
+ }.exports = {\n${Array.from(
108
+ cssExports,
109
+ ([k, v]) => `\t${JSON.stringify(k)}: ${JSON.stringify(v)}`
110
+ ).join(",\n")}\n}${otherUsed ? ")" : ""};`
111
+ );
112
+ }
113
+ }
114
+
115
+ /**
116
+ * @param {NormalModule} module fresh module
117
+ * @returns {Set<string>} available types (do not mutate)
118
+ */
119
+ getTypes(module) {
120
+ return TYPES;
121
+ }
122
+
123
+ /**
124
+ * @param {NormalModule} module the module
125
+ * @param {string=} type source type
126
+ * @returns {number} estimate size of the module
127
+ */
128
+ getSize(module, type) {
129
+ return 42;
130
+ }
131
+
132
+ /**
133
+ * @param {Hash} hash hash that will be modified
134
+ * @param {UpdateHashContext} updateHashContext context for updating hash
135
+ */
136
+ updateHash(hash, { module }) {}
137
+ }
138
+
139
+ module.exports = CssExportsGenerator;