webpack 5.102.1 → 5.104.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (220) hide show
  1. package/README.md +121 -134
  2. package/hot/dev-server.js +18 -3
  3. package/hot/emitter-event-target.js +7 -0
  4. package/hot/lazy-compilation-node.js +45 -29
  5. package/hot/lazy-compilation-universal.js +18 -0
  6. package/hot/lazy-compilation-web.js +15 -5
  7. package/hot/load-http.js +7 -0
  8. package/hot/only-dev-server.js +19 -4
  9. package/lib/APIPlugin.js +6 -0
  10. package/lib/Chunk.js +1 -1
  11. package/lib/ChunkGraph.js +9 -7
  12. package/lib/ChunkGroup.js +8 -5
  13. package/lib/CleanPlugin.js +6 -3
  14. package/lib/CodeGenerationResults.js +2 -1
  15. package/lib/CompatibilityPlugin.js +28 -2
  16. package/lib/Compilation.js +58 -21
  17. package/lib/Compiler.js +3 -3
  18. package/lib/ConcatenationScope.js +0 -15
  19. package/lib/ContextModule.js +6 -3
  20. package/lib/ContextModuleFactory.js +6 -4
  21. package/lib/CssModule.js +6 -1
  22. package/lib/DefinePlugin.js +45 -14
  23. package/lib/DelegatedModule.js +7 -4
  24. package/lib/Dependency.js +8 -1
  25. package/lib/DependencyTemplate.js +1 -0
  26. package/lib/DllModule.js +6 -3
  27. package/lib/DotenvPlugin.js +462 -0
  28. package/lib/EnvironmentPlugin.js +19 -16
  29. package/lib/EvalSourceMapDevToolPlugin.js +16 -0
  30. package/lib/ExportsInfo.js +6 -2
  31. package/lib/ExternalModule.js +28 -35
  32. package/lib/ExternalModuleFactoryPlugin.js +11 -9
  33. package/lib/ExternalsPlugin.js +2 -1
  34. package/lib/FileSystemInfo.js +1 -1
  35. package/lib/Generator.js +10 -7
  36. package/lib/HookWebpackError.js +33 -4
  37. package/lib/HotModuleReplacementPlugin.js +22 -0
  38. package/lib/ManifestPlugin.js +235 -0
  39. package/lib/Module.js +27 -15
  40. package/lib/ModuleBuildError.js +1 -1
  41. package/lib/ModuleError.js +1 -1
  42. package/lib/ModuleFilenameHelpers.js +1 -1
  43. package/lib/ModuleGraph.js +29 -13
  44. package/lib/ModuleGraphConnection.js +2 -2
  45. package/lib/ModuleSourceTypeConstants.js +189 -0
  46. package/lib/ModuleTypeConstants.js +1 -4
  47. package/lib/ModuleWarning.js +1 -1
  48. package/lib/MultiCompiler.js +1 -1
  49. package/lib/NodeStuffPlugin.js +424 -116
  50. package/lib/NormalModule.js +23 -20
  51. package/lib/NormalModuleFactory.js +7 -10
  52. package/lib/Parser.js +1 -1
  53. package/lib/RawModule.js +7 -4
  54. package/lib/RuntimeGlobals.js +22 -4
  55. package/lib/RuntimeModule.js +1 -1
  56. package/lib/RuntimePlugin.js +27 -6
  57. package/lib/RuntimeTemplate.js +120 -57
  58. package/lib/SourceMapDevToolPlugin.js +26 -1
  59. package/lib/Template.js +17 -6
  60. package/lib/TemplatedPathPlugin.js +5 -6
  61. package/lib/WebpackError.js +0 -1
  62. package/lib/WebpackOptionsApply.js +67 -15
  63. package/lib/asset/AssetBytesGenerator.js +16 -12
  64. package/lib/asset/AssetGenerator.js +31 -26
  65. package/lib/asset/AssetSourceGenerator.js +16 -12
  66. package/lib/asset/RawDataUrlModule.js +6 -3
  67. package/lib/buildChunkGraph.js +4 -2
  68. package/lib/cache/PackFileCacheStrategy.js +6 -5
  69. package/lib/cli.js +2 -43
  70. package/lib/config/browserslistTargetHandler.js +24 -0
  71. package/lib/config/defaults.js +226 -61
  72. package/lib/config/normalization.js +4 -3
  73. package/lib/config/target.js +11 -0
  74. package/lib/container/ContainerEntryModule.js +6 -3
  75. package/lib/container/FallbackModule.js +6 -3
  76. package/lib/container/RemoteModule.js +1 -3
  77. package/lib/css/CssGenerator.js +304 -76
  78. package/lib/css/CssLoadingRuntimeModule.js +14 -4
  79. package/lib/css/CssMergeStyleSheetsRuntimeModule.js +56 -0
  80. package/lib/css/CssModulesPlugin.js +72 -67
  81. package/lib/css/CssParser.js +1726 -732
  82. package/lib/css/walkCssTokens.js +128 -11
  83. package/lib/dependencies/CachedConstDependency.js +24 -10
  84. package/lib/dependencies/CommonJsImportsParserPlugin.js +0 -9
  85. package/lib/dependencies/CommonJsPlugin.js +12 -0
  86. package/lib/dependencies/CommonJsRequireContextDependency.js +1 -1
  87. package/lib/dependencies/ContextDependencyHelpers.js +2 -2
  88. package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +3 -1
  89. package/lib/dependencies/CssIcssExportDependency.js +389 -12
  90. package/lib/dependencies/CssIcssImportDependency.js +114 -51
  91. package/lib/dependencies/CssIcssSymbolDependency.js +31 -33
  92. package/lib/dependencies/CssImportDependency.js +17 -6
  93. package/lib/dependencies/CssUrlDependency.js +3 -2
  94. package/lib/dependencies/DynamicExports.js +7 -7
  95. package/lib/dependencies/ExternalModuleDependency.js +7 -4
  96. package/lib/dependencies/ExternalModuleInitFragment.js +3 -2
  97. package/lib/dependencies/ExternalModuleInitFragmentDependency.js +96 -0
  98. package/lib/dependencies/HarmonyAcceptDependency.js +6 -1
  99. package/lib/dependencies/HarmonyAcceptImportDependency.js +2 -1
  100. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +12 -1
  101. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +35 -23
  102. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +13 -9
  103. package/lib/dependencies/HarmonyExports.js +4 -4
  104. package/lib/dependencies/HarmonyImportDependency.js +28 -27
  105. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +28 -69
  106. package/lib/dependencies/HarmonyImportSideEffectDependency.js +4 -3
  107. package/lib/dependencies/HarmonyImportSpecifierDependency.js +10 -8
  108. package/lib/dependencies/ImportDependency.js +8 -2
  109. package/lib/dependencies/ImportEagerDependency.js +6 -3
  110. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +1 -1
  111. package/lib/dependencies/ImportMetaPlugin.js +154 -9
  112. package/lib/dependencies/ImportParserPlugin.js +21 -23
  113. package/lib/dependencies/ImportPhase.js +121 -0
  114. package/lib/dependencies/ImportWeakDependency.js +6 -3
  115. package/lib/dependencies/LocalModulesHelpers.js +3 -3
  116. package/lib/dependencies/ModuleDependency.js +5 -1
  117. package/lib/dependencies/ModuleHotAcceptDependency.js +1 -1
  118. package/lib/dependencies/WorkerPlugin.js +2 -2
  119. package/lib/dependencies/getFunctionExpression.js +1 -1
  120. package/lib/esm/ExportWebpackRequireRuntimeModule.js +1 -8
  121. package/lib/esm/ModuleChunkFormatPlugin.js +5 -4
  122. package/lib/hmr/HotModuleReplacement.runtime.js +2 -1
  123. package/lib/hmr/LazyCompilationPlugin.js +5 -3
  124. package/lib/ids/IdHelpers.js +20 -8
  125. package/lib/index.js +6 -0
  126. package/lib/javascript/ChunkHelpers.js +16 -5
  127. package/lib/javascript/JavascriptGenerator.js +105 -104
  128. package/lib/javascript/JavascriptModulesPlugin.js +80 -37
  129. package/lib/javascript/JavascriptParser.js +161 -44
  130. package/lib/json/JsonGenerator.js +5 -4
  131. package/lib/json/JsonParser.js +9 -2
  132. package/lib/library/AbstractLibraryPlugin.js +1 -1
  133. package/lib/library/AmdLibraryPlugin.js +4 -1
  134. package/lib/library/ExportPropertyLibraryPlugin.js +4 -1
  135. package/lib/library/ModuleLibraryPlugin.js +41 -23
  136. package/lib/library/SystemLibraryPlugin.js +8 -1
  137. package/lib/library/UmdLibraryPlugin.js +2 -2
  138. package/lib/logging/Logger.js +5 -4
  139. package/lib/logging/createConsoleLogger.js +2 -2
  140. package/lib/node/NodeTargetPlugin.js +9 -1
  141. package/lib/node/ReadFileCompileWasmPlugin.js +0 -2
  142. package/lib/optimize/ConcatenatedModule.js +208 -167
  143. package/lib/optimize/ModuleConcatenationPlugin.js +5 -4
  144. package/lib/optimize/SideEffectsFlagPlugin.js +3 -2
  145. package/lib/optimize/SplitChunksPlugin.js +60 -46
  146. package/lib/rules/RuleSetCompiler.js +1 -1
  147. package/lib/runtime/AsyncModuleRuntimeModule.js +28 -18
  148. package/lib/runtime/AutoPublicPathRuntimeModule.js +8 -3
  149. package/lib/runtime/GetChunkFilenameRuntimeModule.js +3 -2
  150. package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +89 -55
  151. package/lib/schemes/HttpUriPlugin.js +78 -7
  152. package/lib/serialization/AggregateErrorSerializer.js +1 -2
  153. package/lib/serialization/ObjectMiddleware.js +0 -2
  154. package/lib/serialization/SingleItemMiddleware.js +1 -1
  155. package/lib/sharing/ConsumeSharedModule.js +1 -1
  156. package/lib/sharing/ConsumeSharedPlugin.js +5 -3
  157. package/lib/sharing/ProvideSharedModule.js +1 -1
  158. package/lib/sharing/resolveMatchedConfigs.js +15 -9
  159. package/lib/sharing/utils.js +1 -1
  160. package/lib/stats/DefaultStatsFactoryPlugin.js +8 -5
  161. package/lib/stats/DefaultStatsPresetPlugin.js +1 -1
  162. package/lib/stats/DefaultStatsPrinterPlugin.js +1 -1
  163. package/lib/util/StringXor.js +1 -1
  164. package/lib/util/URLAbsoluteSpecifier.js +2 -2
  165. package/lib/util/binarySearchBounds.js +2 -2
  166. package/lib/util/comparators.js +54 -76
  167. package/lib/util/compileBooleanMatcher.js +78 -6
  168. package/lib/util/createHash.js +20 -199
  169. package/lib/util/deprecation.js +1 -1
  170. package/lib/util/deterministicGrouping.js +6 -3
  171. package/lib/util/fs.js +75 -75
  172. package/lib/util/hash/BatchedHash.js +10 -9
  173. package/lib/util/hash/BulkUpdateHash.js +138 -0
  174. package/lib/util/hash/DebugHash.js +75 -0
  175. package/lib/util/hash/hash-digest.js +216 -0
  176. package/lib/util/identifier.js +82 -17
  177. package/lib/util/internalSerializables.js +2 -6
  178. package/lib/util/runtime.js +3 -3
  179. package/lib/util/source.js +2 -2
  180. package/lib/wasm/EnableWasmLoadingPlugin.js +10 -4
  181. package/lib/wasm-async/AsyncWebAssemblyGenerator.js +3 -2
  182. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +11 -7
  183. package/lib/wasm-sync/WebAssemblyGenerator.js +9 -6
  184. package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +11 -6
  185. package/lib/wasm-sync/WebAssemblyModulesPlugin.js +6 -2
  186. package/lib/web/FetchCompileWasmPlugin.js +0 -2
  187. package/lib/webpack.js +85 -82
  188. package/module.d.ts +5 -0
  189. package/package.json +34 -28
  190. package/schemas/WebpackOptions.check.js +1 -1
  191. package/schemas/WebpackOptions.json +160 -101
  192. package/schemas/plugins/{css/CssAutoParserOptions.check.d.ts → ManifestPlugin.check.d.ts} +1 -1
  193. package/schemas/plugins/ManifestPlugin.check.js +6 -0
  194. package/schemas/plugins/ManifestPlugin.json +98 -0
  195. package/schemas/plugins/SourceMapDevToolPlugin.check.js +1 -1
  196. package/schemas/plugins/SourceMapDevToolPlugin.json +16 -3
  197. package/schemas/plugins/container/ContainerReferencePlugin.check.js +1 -1
  198. package/schemas/plugins/container/ContainerReferencePlugin.json +4 -1
  199. package/schemas/plugins/container/ExternalsType.check.js +1 -1
  200. package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
  201. package/schemas/plugins/container/ModuleFederationPlugin.json +4 -1
  202. package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +1 -1
  203. package/schemas/plugins/css/CssModuleParserOptions.check.js +1 -1
  204. package/schemas/plugins/css/CssParserOptions.check.js +1 -1
  205. package/schemas/plugins/json/JsonModulesPluginParser.check.js +1 -1
  206. package/types.d.ts +771 -436
  207. package/lib/ModuleSourceTypesConstants.js +0 -123
  208. package/lib/dependencies/CssLocalIdentifierDependency.js +0 -250
  209. package/lib/dependencies/CssSelfLocalIdentifierDependency.js +0 -112
  210. package/schemas/plugins/css/CssAutoGeneratorOptions.check.d.ts +0 -7
  211. package/schemas/plugins/css/CssAutoGeneratorOptions.check.js +0 -6
  212. package/schemas/plugins/css/CssAutoGeneratorOptions.json +0 -3
  213. package/schemas/plugins/css/CssAutoParserOptions.check.js +0 -6
  214. package/schemas/plugins/css/CssAutoParserOptions.json +0 -3
  215. package/schemas/plugins/css/CssGlobalGeneratorOptions.check.d.ts +0 -7
  216. package/schemas/plugins/css/CssGlobalGeneratorOptions.check.js +0 -6
  217. package/schemas/plugins/css/CssGlobalGeneratorOptions.json +0 -3
  218. package/schemas/plugins/css/CssGlobalParserOptions.check.d.ts +0 -7
  219. package/schemas/plugins/css/CssGlobalParserOptions.check.js +0 -6
  220. package/schemas/plugins/css/CssGlobalParserOptions.json +0 -3
@@ -79,7 +79,8 @@ const memoize = require("./util/memoize");
79
79
  /** @typedef {import("./Module").NeedBuildCallback} NeedBuildCallback */
80
80
  /** @typedef {import("./Module").BuildCallback} BuildCallback */
81
81
  /** @typedef {import("./Module").RuntimeRequirements} RuntimeRequirements */
82
- /** @typedef {import("./Generator").SourceTypes} SourceTypes */
82
+ /** @typedef {import("./Module").SourceType} SourceType */
83
+ /** @typedef {import("./Module").SourceTypes} SourceTypes */
83
84
  /** @typedef {import("./Module").UnsafeCacheData} UnsafeCacheData */
84
85
  /** @typedef {import("./ModuleGraph")} ModuleGraph */
85
86
  /** @typedef {import("./ModuleGraphConnection").ConnectionState} ConnectionState */
@@ -96,7 +97,6 @@ const memoize = require("./util/memoize");
96
97
  /** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */
97
98
  /** @typedef {import("../declarations/WebpackOptions").HashFunction} HashFunction */
98
99
  /** @typedef {import("./util/identifier").AssociatedObjectForCache} AssociatedObjectForCache */
99
- /** @typedef {import("../declarations/WebpackOptions").RuleSetRule["extractSourceMap"]} ExtractSourceMapOptions */
100
100
  /**
101
101
  * @template T
102
102
  * @typedef {import("./util/deprecation").FakeHook<T>} FakeHook
@@ -255,7 +255,7 @@ makeSerializable(
255
255
  * @property {Generator} generator the generator used
256
256
  * @property {GeneratorOptions=} generatorOptions the options of the generator used
257
257
  * @property {ResolveOptions=} resolveOptions options used for resolving requests from this module
258
- * @property {boolean=} extractSourceMap enable/disable extracting source map
258
+ * @property {boolean} extractSourceMap enable/disable extracting source map
259
259
  */
260
260
 
261
261
  /**
@@ -353,34 +353,36 @@ class NormalModule extends Module {
353
353
  super(type, context || getContext(resource), layer);
354
354
 
355
355
  // Info from Factory
356
- /** @type {string} */
356
+ /** @type {NormalModuleCreateData['request']} */
357
357
  this.request = request;
358
- /** @type {string} */
358
+ /** @type {NormalModuleCreateData['userRequest']} */
359
359
  this.userRequest = userRequest;
360
- /** @type {string} */
360
+ /** @type {NormalModuleCreateData['rawRequest']} */
361
361
  this.rawRequest = rawRequest;
362
362
  /** @type {boolean} */
363
363
  this.binary = /^(asset|webassembly)\b/.test(type);
364
- /** @type {undefined | Parser} */
364
+ /** @type {NormalModuleCreateData['parser'] | undefined} */
365
365
  this.parser = parser;
366
- /** @type {undefined | ParserOptions} */
366
+ /** @type {NormalModuleCreateData['parserOptions']} */
367
367
  this.parserOptions = parserOptions;
368
- /** @type {undefined | Generator} */
368
+ /** @type {NormalModuleCreateData['generator'] | undefined} */
369
369
  this.generator = generator;
370
- /** @type {undefined | GeneratorOptions} */
370
+ /** @type {NormalModuleCreateData['generatorOptions']} */
371
371
  this.generatorOptions = generatorOptions;
372
- /** @type {string} */
372
+ /** @type {NormalModuleCreateData['resource']} */
373
373
  this.resource = resource;
374
+ /** @type {NormalModuleCreateData['resourceResolveData']} */
374
375
  this.resourceResolveData = resourceResolveData;
375
- /** @type {string | undefined} */
376
+ /** @type {NormalModuleCreateData['matchResource']} */
376
377
  this.matchResource = matchResource;
377
- /** @type {LoaderItem[]} */
378
+ /** @type {NormalModuleCreateData['loaders']} */
378
379
  this.loaders = loaders;
379
380
  if (resolveOptions !== undefined) {
380
381
  // already declared in super class
382
+ /** @type {NormalModuleCreateData['resolveOptions']} */
381
383
  this.resolveOptions = resolveOptions;
382
384
  }
383
- /** @type {ExtractSourceMapOptions} */
385
+ /** @type {NormalModuleCreateData['extractSourceMap']} */
384
386
  this.extractSourceMap = extractSourceMap;
385
387
 
386
388
  // Info from Build
@@ -393,7 +395,7 @@ class NormalModule extends Module {
393
395
  this._source = null;
394
396
  /**
395
397
  * @private
396
- * @type {Map<string | undefined, number> | undefined}
398
+ * @type {Map<undefined | SourceType, number> | undefined}
397
399
  */
398
400
  this._sourceSizes = undefined;
399
401
  /**
@@ -487,6 +489,7 @@ class NormalModule extends Module {
487
489
  this.context = m.context;
488
490
  this.matchResource = m.matchResource;
489
491
  this.loaders = m.loaders;
492
+ this.extractSourceMap = m.extractSourceMap;
490
493
  }
491
494
 
492
495
  /**
@@ -697,7 +700,8 @@ class NormalModule extends Module {
697
700
  options = parseJson(options);
698
701
  } catch (err) {
699
702
  throw new Error(
700
- `Cannot parse string options: ${/** @type {Error} */ (err).message}`
703
+ `Cannot parse string options: ${/** @type {Error} */ (err).message}`,
704
+ { cause: err }
701
705
  );
702
706
  }
703
707
  } else {
@@ -1305,7 +1309,7 @@ class NormalModule extends Module {
1305
1309
  /** @type {undefined | Set<string>} */
1306
1310
  let nonAbsoluteDependencies;
1307
1311
  /**
1308
- * @param {LazySet<string>} deps deps
1312
+ * @param {FileSystemDependencies} deps deps
1309
1313
  */
1310
1314
  const checkDependencies = (deps) => {
1311
1315
  for (const dep of deps) {
@@ -1721,7 +1725,6 @@ class NormalModule extends Module {
1721
1725
  write(this._lastSuccessfulBuildMeta);
1722
1726
  write(this._forceBuild);
1723
1727
  write(this._codeGeneratorData);
1724
- write(this.extractSourceMap);
1725
1728
  super.serialize(context);
1726
1729
  }
1727
1730
 
@@ -1746,7 +1749,8 @@ class NormalModule extends Module {
1746
1749
  parserOptions: /** @type {EXPECTED_ANY} */ (null),
1747
1750
  generator: /** @type {EXPECTED_ANY} */ (null),
1748
1751
  generatorOptions: /** @type {EXPECTED_ANY} */ (null),
1749
- resolveOptions: /** @type {EXPECTED_ANY} */ (null)
1752
+ resolveOptions: /** @type {EXPECTED_ANY} */ (null),
1753
+ extractSourceMap: /** @type {EXPECTED_ANY} */ (null)
1750
1754
  });
1751
1755
  obj.deserialize(context);
1752
1756
  return obj;
@@ -1762,7 +1766,6 @@ class NormalModule extends Module {
1762
1766
  this._lastSuccessfulBuildMeta = read();
1763
1767
  this._forceBuild = read();
1764
1768
  this._codeGeneratorData = read();
1765
- this.extractSourceMap = read();
1766
1769
  super.deserialize(context);
1767
1770
  }
1768
1771
  }
@@ -38,6 +38,7 @@ const {
38
38
  /** @typedef {import("enhanced-resolve").ResolveRequest} ResolveRequest */
39
39
  /** @typedef {import("../declarations/WebpackOptions").ModuleOptionsNormalized} ModuleOptions */
40
40
  /** @typedef {import("../declarations/WebpackOptions").RuleSetRule} RuleSetRule */
41
+ /** @typedef {import("./Compilation").FileSystemDependencies} FileSystemDependencies */
41
42
  /** @typedef {import("./Generator")} Generator */
42
43
  /** @typedef {import("./ModuleFactory").ModuleFactoryCallback} ModuleFactoryCallback */
43
44
  /** @typedef {import("./ModuleFactory").ModuleFactoryCreateData} ModuleFactoryCreateData */
@@ -61,7 +62,7 @@ const {
61
62
  * @typedef {import("./Compiler").Callback<T>} Callback
62
63
  */
63
64
 
64
- /** @typedef {Pick<RuleSetRule, 'type' | 'sideEffects' | 'parser' | 'generator' | 'resolve' | 'layer' | 'extractSourceMap'>} ModuleSettings */
65
+ /** @typedef {Pick<RuleSetRule, "type" | "sideEffects" | "parser" | "generator" | "resolve" | "layer" | "extractSourceMap">} ModuleSettings */
65
66
  /** @typedef {Partial<NormalModuleCreateData & { settings: ModuleSettings }>} CreateData */
66
67
 
67
68
  /**
@@ -74,9 +75,9 @@ const {
74
75
  * @property {ModuleDependency[]} dependencies
75
76
  * @property {string} dependencyType
76
77
  * @property {CreateData} createData
77
- * @property {LazySet<string>} fileDependencies
78
- * @property {LazySet<string>} missingDependencies
79
- * @property {LazySet<string>} contextDependencies
78
+ * @property {FileSystemDependencies} fileDependencies
79
+ * @property {FileSystemDependencies} missingDependencies
80
+ * @property {FileSystemDependencies} contextDependencies
80
81
  * @property {Module=} ignoredModule
81
82
  * @property {boolean} cacheable allow to use the unsafe cache
82
83
  */
@@ -296,14 +297,10 @@ const ruleSetCompiler = new RuleSetCompiler([
296
297
 
297
298
  /** @typedef {import("./css/CssParser")} CssParser */
298
299
  /** @typedef {import("../declarations/WebpackOptions").CssParserOptions} CssParserOptions */
299
- /** @typedef {import("../declarations/WebpackOptions").CssAutoParserOptions} CssAutoParserOptions */
300
- /** @typedef {import("../declarations/WebpackOptions").CssGlobalParserOptions} CssGlobalParserOptions */
301
300
  /** @typedef {import("../declarations/WebpackOptions").CssModuleParserOptions} CssModuleParserOptions */
302
301
  /** @typedef {import("./css/CssGenerator")} CssGenerator */
303
302
  /** @typedef {import("../declarations/WebpackOptions").CssGeneratorOptions} CssGeneratorOptions */
304
- /** @typedef {import("../declarations/WebpackOptions").CssGlobalGeneratorOptions} CssGlobalGeneratorOptions */
305
303
  /** @typedef {import("../declarations/WebpackOptions").CssModuleGeneratorOptions} CssModuleGeneratorOptions */
306
- /** @typedef {import("../declarations/WebpackOptions").CssAutoGeneratorOptions} CssAutoGeneratorOptions */
307
304
 
308
305
  /**
309
306
  * @typedef {[
@@ -319,9 +316,9 @@ const ruleSetCompiler = new RuleSetCompiler([
319
316
  * [WEBASSEMBLY_MODULE_TYPE_ASYNC, AsyncWebAssemblyParser, EmptyParserOptions, Generator, EmptyParserOptions],
320
317
  * [WEBASSEMBLY_MODULE_TYPE_SYNC, WebAssemblyParser, EmptyParserOptions, Generator, EmptyParserOptions],
321
318
  * [CSS_MODULE_TYPE, CssParser, CssParserOptions, CssGenerator, CssGeneratorOptions],
322
- * [CSS_MODULE_TYPE_AUTO, CssParser, CssAutoParserOptions, CssGenerator, CssAutoGeneratorOptions],
319
+ * [CSS_MODULE_TYPE_AUTO, CssParser, CssModuleParserOptions, CssGenerator, CssModuleGeneratorOptions],
323
320
  * [CSS_MODULE_TYPE_MODULE, CssParser, CssModuleParserOptions, CssGenerator, CssModuleGeneratorOptions],
324
- * [CSS_MODULE_TYPE_GLOBAL, CssParser, CssGlobalParserOptions, CssGenerator, CssGlobalGeneratorOptions],
321
+ * [CSS_MODULE_TYPE_GLOBAL, CssParser, CssModuleParserOptions, CssGenerator, CssModuleGeneratorOptions],
325
322
  * [string, Parser, ParserOptions, Generator, GeneratorOptions],
326
323
  * ]} ParsersAndGeneratorsByTypes
327
324
  */
package/lib/Parser.js CHANGED
@@ -20,7 +20,7 @@
20
20
  * @property {WebpackOptions} options
21
21
  */
22
22
 
23
- /** @typedef {Record<string, EXPECTED_ANY> & ParserStateBase} ParserState */
23
+ /** @typedef {ParserStateBase & Record<string, EXPECTED_ANY>} ParserState */
24
24
 
25
25
  class Parser {
26
26
  /* istanbul ignore next */
package/lib/RawModule.js CHANGED
@@ -7,7 +7,10 @@
7
7
 
8
8
  const { OriginalSource, RawSource } = require("webpack-sources");
9
9
  const Module = require("./Module");
10
- const { JS_TYPES } = require("./ModuleSourceTypesConstants");
10
+ const {
11
+ JAVASCRIPT_TYPE,
12
+ JAVASCRIPT_TYPES
13
+ } = require("./ModuleSourceTypeConstants");
11
14
  const { JAVASCRIPT_MODULE_TYPE_DYNAMIC } = require("./ModuleTypeConstants");
12
15
  const makeSerializable = require("./util/makeSerializable");
13
16
 
@@ -49,7 +52,7 @@ class RawModule extends Module {
49
52
  * @returns {SourceTypes} types available (do not mutate)
50
53
  */
51
54
  getSourceTypes() {
52
- return JS_TYPES;
55
+ return JAVASCRIPT_TYPES;
53
56
  }
54
57
 
55
58
  /**
@@ -122,11 +125,11 @@ class RawModule extends Module {
122
125
  const sources = new Map();
123
126
  if (this.useSourceMap || this.useSimpleSourceMap) {
124
127
  sources.set(
125
- "javascript",
128
+ JAVASCRIPT_TYPE,
126
129
  new OriginalSource(this.sourceStr, this.identifier())
127
130
  );
128
131
  } else {
129
- sources.set("javascript", new RawSource(this.sourceStr));
132
+ sources.set(JAVASCRIPT_TYPE, new RawSource(this.sourceStr));
130
133
  }
131
134
  return { sources, runtimeRequirements: this.runtimeRequirements };
132
135
  }
@@ -78,11 +78,29 @@ module.exports.createScript = "__webpack_require__.ts";
78
78
  */
79
79
  module.exports.createScriptUrl = "__webpack_require__.tu";
80
80
 
81
+ /**
82
+ * merge multiple CSS stylesheets (CSSStyleSheet or string) into one CSS text string
83
+ * Arguments: (sheets: Array<CSSStyleSheet | string> | CSSStyleSheet | string) => string
84
+ */
85
+ module.exports.cssMergeStyleSheets = "__webpack_require__.mcs";
86
+
81
87
  /**
82
88
  * The current scope when getting a module from a remote
83
89
  */
84
90
  module.exports.currentRemoteGetScope = "__webpack_require__.R";
85
91
 
92
+ /**
93
+ * resolve async transitive dependencies for deferred module
94
+ */
95
+ module.exports.deferredModuleAsyncTransitiveDependencies =
96
+ "__webpack_require__.zT";
97
+
98
+ /**
99
+ * the internal symbol for getting the async transitive dependencies for deferred module
100
+ */
101
+ module.exports.deferredModuleAsyncTransitiveDependenciesSymbol =
102
+ "__webpack_require__.zS";
103
+
86
104
  /**
87
105
  * the exported property define getters function
88
106
  */
@@ -258,14 +276,14 @@ module.exports.loadScript = "__webpack_require__.l";
258
276
  module.exports.makeDeferredNamespaceObject = "__webpack_require__.z";
259
277
 
260
278
  /**
261
- * the internal symbol that makeDeferredNamespaceObject is using.
279
+ * define compatibility on export
262
280
  */
263
- module.exports.makeDeferredNamespaceObjectSymbol = "__webpack_require__.zS";
281
+ module.exports.makeNamespaceObject = "__webpack_require__.r";
264
282
 
265
283
  /**
266
- * define compatibility on export
284
+ * make a optimized deferred namespace object
267
285
  */
268
- module.exports.makeNamespaceObject = "__webpack_require__.r";
286
+ module.exports.makeOptimizedDeferredNamespaceObject = "__webpack_require__.zO";
269
287
 
270
288
  /**
271
289
  * the internal module object
@@ -8,7 +8,7 @@
8
8
  const { RawSource } = require("webpack-sources");
9
9
  const OriginalSource = require("webpack-sources").OriginalSource;
10
10
  const Module = require("./Module");
11
- const { RUNTIME_TYPES } = require("./ModuleSourceTypesConstants");
11
+ const { RUNTIME_TYPES } = require("./ModuleSourceTypeConstants");
12
12
  const { WEBPACK_MODULE_TYPE_RUNTIME } = require("./ModuleTypeConstants");
13
13
 
14
14
  /** @typedef {import("./config/defaults").WebpackOptionsNormalizedWithDefaults} WebpackOptions */
@@ -24,7 +24,10 @@ const GetTrustedTypesPolicyRuntimeModule = require("./runtime/GetTrustedTypesPol
24
24
  const GlobalRuntimeModule = require("./runtime/GlobalRuntimeModule");
25
25
  const HasOwnPropertyRuntimeModule = require("./runtime/HasOwnPropertyRuntimeModule");
26
26
  const LoadScriptRuntimeModule = require("./runtime/LoadScriptRuntimeModule");
27
- const MakeDeferredNamespaceObjectRuntime = require("./runtime/MakeDeferredNamespaceObjectRuntime");
27
+ const {
28
+ MakeDeferredNamespaceObjectRuntimeModule,
29
+ MakeOptimizedDeferredNamespaceObjectRuntimeModule
30
+ } = require("./runtime/MakeDeferredNamespaceObjectRuntime");
28
31
  const MakeNamespaceObjectRuntimeModule = require("./runtime/MakeNamespaceObjectRuntimeModule");
29
32
  const NonceRuntimeModule = require("./runtime/NonceRuntimeModule");
30
33
  const OnChunksLoadedRuntimeModule = require("./runtime/OnChunksLoadedRuntimeModule");
@@ -78,6 +81,7 @@ const GLOBALS_ON_REQUIRE = [
78
81
  RuntimeGlobals.loadScript,
79
82
  RuntimeGlobals.systemContext,
80
83
  RuntimeGlobals.onChunksLoaded,
84
+ RuntimeGlobals.makeOptimizedDeferredNamespaceObject,
81
85
  RuntimeGlobals.makeDeferredNamespaceObject
82
86
  ];
83
87
 
@@ -96,11 +100,11 @@ const TREE_DEPENDENCIES = {
96
100
  RuntimeGlobals.makeNamespaceObject,
97
101
  RuntimeGlobals.require
98
102
  ],
103
+ [RuntimeGlobals.makeOptimizedDeferredNamespaceObject]: [
104
+ RuntimeGlobals.require
105
+ ],
99
106
  [RuntimeGlobals.makeDeferredNamespaceObject]: [
100
- RuntimeGlobals.definePropertyGetters,
101
- RuntimeGlobals.makeNamespaceObject,
102
107
  RuntimeGlobals.createFakeNamespaceObject,
103
- RuntimeGlobals.hasOwnProperty,
104
108
  RuntimeGlobals.require
105
109
  ],
106
110
  [RuntimeGlobals.initializeSharing]: [RuntimeGlobals.shareScopeMap],
@@ -190,12 +194,23 @@ class RuntimePlugin {
190
194
  );
191
195
  return true;
192
196
  });
197
+ compilation.hooks.runtimeRequirementInTree
198
+ .for(RuntimeGlobals.makeOptimizedDeferredNamespaceObject)
199
+ .tap("RuntimePlugin", (chunk, runtimeRequirement) => {
200
+ compilation.addRuntimeModule(
201
+ chunk,
202
+ new MakeOptimizedDeferredNamespaceObjectRuntimeModule(
203
+ runtimeRequirement.has(RuntimeGlobals.asyncModule)
204
+ )
205
+ );
206
+ return true;
207
+ });
193
208
  compilation.hooks.runtimeRequirementInTree
194
209
  .for(RuntimeGlobals.makeDeferredNamespaceObject)
195
210
  .tap("RuntimePlugin", (chunk, runtimeRequirement) => {
196
211
  compilation.addRuntimeModule(
197
212
  chunk,
198
- new MakeDeferredNamespaceObjectRuntime(
213
+ new MakeDeferredNamespaceObjectRuntimeModule(
199
214
  runtimeRequirement.has(RuntimeGlobals.asyncModule)
200
215
  )
201
216
  );
@@ -238,7 +253,13 @@ class RuntimePlugin {
238
253
 
239
254
  if (publicPath === "auto") {
240
255
  const module = new AutoPublicPathRuntimeModule();
241
- if (scriptType !== "module") set.add(RuntimeGlobals.global);
256
+ if (
257
+ scriptType !== "module" &&
258
+ !outputOptions.environment.globalThis
259
+ ) {
260
+ set.add(RuntimeGlobals.global);
261
+ }
262
+
242
263
  compilation.addRuntimeModule(chunk, module);
243
264
  } else {
244
265
  const module = new PublicPathRuntimeModule(publicPath);