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
@@ -18,11 +18,13 @@ const DependencyTemplate = require("../DependencyTemplate");
18
18
  class ModuleDependency extends Dependency {
19
19
  /**
20
20
  * @param {string} request request path which needs resolving
21
+ * @param {number=} sourceOrder source order
21
22
  */
22
- constructor(request) {
23
+ constructor(request, sourceOrder) {
23
24
  super();
24
25
  this.request = request;
25
26
  this.userRequest = request;
27
+ this.sourceOrder = sourceOrder;
26
28
  /** @type {Range | undefined} */
27
29
  this.range = undefined;
28
30
  this._context = undefined;
@@ -74,6 +76,7 @@ class ModuleDependency extends Dependency {
74
76
  write(this.userRequest);
75
77
  write(this._context);
76
78
  write(this.range);
79
+ write(this.sourceOrder);
77
80
  super.serialize(context);
78
81
  }
79
82
 
@@ -86,6 +89,7 @@ class ModuleDependency extends Dependency {
86
89
  this.userRequest = read();
87
90
  this._context = read();
88
91
  this.range = read();
92
+ this.sourceOrder = read();
89
93
  super.deserialize(context);
90
94
  }
91
95
  }
@@ -17,7 +17,7 @@ class ModuleHotAcceptDependency extends ModuleDependency {
17
17
  * @param {Range} range location in source code
18
18
  */
19
19
  constructor(request, range) {
20
- super(request);
20
+ super(request, Infinity);
21
21
  this.range = range;
22
22
  this.weak = true;
23
23
  }
@@ -41,9 +41,9 @@ const WorkerDependency = require("./WorkerDependency");
41
41
  /** @typedef {import("../Dependency").DependencyLocation} DependencyLocation */
42
42
  /** @typedef {import("../Entrypoint").EntryOptions} EntryOptions */
43
43
  /** @typedef {import("../NormalModule")} NormalModule */
44
- /** @typedef {import("../Parser").ParserState} ParserState */
45
44
  /** @typedef {import("../javascript/JavascriptParser")} JavascriptParser */
46
45
  /** @typedef {import("../javascript/JavascriptParser")} Parser */
46
+ /** @typedef {import("../javascript/JavascriptParser").JavascriptParserState} JavascriptParserState */
47
47
  /** @typedef {import("../javascript/JavascriptParser").Range} Range */
48
48
  /** @typedef {import("./HarmonyImportDependencyParserPlugin").HarmonySettings} HarmonySettings */
49
49
 
@@ -62,7 +62,7 @@ const DEFAULT_SYNTAX = [
62
62
  "Worker from worker_threads"
63
63
  ];
64
64
 
65
- /** @type {WeakMap<ParserState, number>} */
65
+ /** @type {WeakMap<JavascriptParserState, number>} */
66
66
  const workerIndexMap = new WeakMap();
67
67
 
68
68
  const PLUGIN_NAME = "WorkerPlugin";
@@ -12,7 +12,7 @@
12
12
 
13
13
  /**
14
14
  * @param {Expression | SpreadElement} expr expressions
15
- * @returns {{fn: FunctionExpression | ArrowFunctionExpression, expressions: (Expression | SpreadElement)[], needThis: boolean | undefined } | undefined} function expression with additional information
15
+ * @returns {{ fn: FunctionExpression | ArrowFunctionExpression, expressions: (Expression | SpreadElement)[], needThis: boolean | undefined } | undefined} function expression with additional information
16
16
  */
17
17
  module.exports = (expr) => {
18
18
  // <FunctionExpression>
@@ -6,10 +6,6 @@
6
6
 
7
7
  const RuntimeGlobals = require("../RuntimeGlobals");
8
8
  const RuntimeModule = require("../RuntimeModule");
9
- const Template = require("../Template");
10
-
11
- // CompatibilityPlugin renames `__webpack_require__` but doesn’t account for `export { __webpack_require__ }`, so we create a temporary variable to handle it.
12
- const EXPORT_TEMP_NAME = "__webpack_require_temp__";
13
9
 
14
10
  class ExportWebpackRequireRuntimeModule extends RuntimeModule {
15
11
  constructor() {
@@ -27,10 +23,7 @@ class ExportWebpackRequireRuntimeModule extends RuntimeModule {
27
23
  * @returns {string | null} runtime code
28
24
  */
29
25
  generate() {
30
- return Template.asString([
31
- `var ${EXPORT_TEMP_NAME} = ${RuntimeGlobals.require};`,
32
- `export { ${EXPORT_TEMP_NAME} as ${RuntimeGlobals.require} };`
33
- ]);
26
+ return `export { ${RuntimeGlobals.require} };`;
34
27
  }
35
28
  }
36
29
 
@@ -7,6 +7,7 @@
7
7
 
8
8
  const { ConcatSource } = require("webpack-sources");
9
9
  const { HotUpdateChunk, RuntimeGlobals } = require("..");
10
+ const { JAVASCRIPT_TYPE } = require("../ModuleSourceTypeConstants");
10
11
  const Template = require("../Template");
11
12
  const {
12
13
  createChunkHashHandler,
@@ -110,10 +111,10 @@ class ModuleChunkFormatPlugin {
110
111
  );
111
112
  const hooks = getCompilationHooks(compilation);
112
113
  /**
113
- * @param {Set<Chunk>} chunks the chunks to render
114
+ * @param {Iterable<Chunk>} chunks the chunks to render
114
115
  * @param {ChunkGraph} chunkGraph the chunk graph
115
116
  * @param {Chunk=} runtimeChunk the runtime chunk
116
- * @returns {Source|undefined} the source
117
+ * @returns {Source | undefined} the source
117
118
  */
118
119
  const withDependentChunks = (chunks, chunkGraph, runtimeChunk) => {
119
120
  if (/** @type {Set<Chunk>} */ (chunks).size > 0) {
@@ -153,7 +154,7 @@ class ModuleChunkFormatPlugin {
153
154
  const entryDependentChunks =
154
155
  chunkGraph.getChunkEntryDependentChunksIterable(chunk);
155
156
  const sourceWithDependentChunks = withDependentChunks(
156
- /** @type {Set<Chunk>} */ (entryDependentChunks),
157
+ entryDependentChunks,
157
158
  chunkGraph,
158
159
  chunk
159
160
  );
@@ -214,7 +215,7 @@ class ModuleChunkFormatPlugin {
214
215
  const loadedChunks = new Set();
215
216
  for (let i = 0; i < entries.length; i++) {
216
217
  const [module, entrypoint] = entries[i];
217
- if (!chunkGraph.getModuleSourceTypes(module).has("javascript")) {
218
+ if (!chunkGraph.getModuleSourceTypes(module).has(JAVASCRIPT_TYPE)) {
218
219
  continue;
219
220
  }
220
221
  const final = i + 1 === entries.length;
@@ -285,7 +285,8 @@ module.exports = function () {
285
285
  update.m,
286
286
  promises,
287
287
  currentUpdateApplyHandlers,
288
- updatedModules
288
+ updatedModules,
289
+ update.css
289
290
  );
290
291
  return promises;
291
292
  }, [])
@@ -10,7 +10,8 @@ const AsyncDependenciesBlock = require("../AsyncDependenciesBlock");
10
10
  const Dependency = require("../Dependency");
11
11
  const Module = require("../Module");
12
12
  const ModuleFactory = require("../ModuleFactory");
13
- const { JS_TYPES } = require("../ModuleSourceTypesConstants");
13
+ const { JAVASCRIPT_TYPES } = require("../ModuleSourceTypeConstants");
14
+ const { JAVASCRIPT_TYPE } = require("../ModuleSourceTypeConstants");
14
15
  const {
15
16
  WEBPACK_MODULE_TYPE_LAZY_COMPILATION_PROXY
16
17
  } = require("../ModuleTypeConstants");
@@ -208,7 +209,7 @@ class LazyCompilationProxyModule extends Module {
208
209
  * @returns {SourceTypes} types available (do not mutate)
209
210
  */
210
211
  getSourceTypes() {
211
- return JS_TYPES;
212
+ return JAVASCRIPT_TYPES;
212
213
  }
213
214
 
214
215
  /**
@@ -257,6 +258,7 @@ class LazyCompilationProxyModule extends Module {
257
258
  block,
258
259
  module,
259
260
  request: this.request,
261
+ dependency: dep,
260
262
  strict: false, // TODO this should be inherited from the original module
261
263
  message: "import()",
262
264
  runtimeRequirements
@@ -289,7 +291,7 @@ class LazyCompilationProxyModule extends Module {
289
291
  keepActive
290
292
  ]);
291
293
  }
292
- sources.set("javascript", new RawSource(source));
294
+ sources.set(JAVASCRIPT_TYPE, new RawSource(source));
293
295
  return {
294
296
  sources,
295
297
  runtimeRequirements
@@ -15,6 +15,7 @@ const numberHash = require("../util/numberHash");
15
15
  /** @typedef {import("../Module")} Module */
16
16
  /** @typedef {typeof import("../util/Hash")} Hash */
17
17
  /** @typedef {import("../util/identifier").AssociatedObjectForCache} AssociatedObjectForCache */
18
+ /** @typedef {import("../Module").BuildMeta} BuildMeta */
18
19
 
19
20
  /**
20
21
  * @param {string} str string to hash
@@ -221,17 +222,19 @@ const addToMapOfItems = (map, key, value) => {
221
222
  array.push(value);
222
223
  };
223
224
 
225
+ /** @typedef {Set<string>} UsedModuleIds */
226
+
224
227
  /**
225
228
  * @param {Compilation} compilation the compilation
226
229
  * @param {((module: Module) => boolean)=} filter filter modules
227
- * @returns {[Set<string>, Module[]]} used module ids as strings and modules without id matching the filter
230
+ * @returns {[UsedModuleIds, Module[]]} used module ids as strings and modules without id matching the filter
228
231
  */
229
232
  const getUsedModuleIdsAndModules = (compilation, filter) => {
230
233
  const chunkGraph = compilation.chunkGraph;
231
234
 
232
235
  const modules = [];
233
236
 
234
- /** @type {Set<string>} */
237
+ /** @type {UsedModuleIds} */
235
238
  const usedIds = new Set();
236
239
  if (compilation.usedModuleIds) {
237
240
  for (const id of compilation.usedModuleIds) {
@@ -246,7 +249,9 @@ const getUsedModuleIdsAndModules = (compilation, filter) => {
246
249
  usedIds.add(String(moduleId));
247
250
  } else if (
248
251
  (!filter || filter(module)) &&
249
- chunkGraph.getNumberOfModuleChunks(module) !== 0
252
+ (chunkGraph.getNumberOfModuleChunks(module) !== 0 ||
253
+ // CSS modules need IDs even when not in chunks, for generating CSS class names(i.e. [id]-[local])
254
+ /** @type {BuildMeta} */ (module.buildMeta).isCSSModule)
250
255
  ) {
251
256
  modules.push(module);
252
257
  }
@@ -255,12 +260,14 @@ const getUsedModuleIdsAndModules = (compilation, filter) => {
255
260
  return [usedIds, modules];
256
261
  };
257
262
 
263
+ /** @typedef {Set<string>} UsedChunkIds */
264
+
258
265
  /**
259
266
  * @param {Compilation} compilation the compilation
260
- * @returns {Set<string>} used chunk ids as strings
267
+ * @returns {UsedChunkIds} used chunk ids as strings
261
268
  */
262
269
  const getUsedChunkIds = (compilation) => {
263
- /** @type {Set<string>} */
270
+ /** @type {UsedChunkIds} */
264
271
  const usedIds = new Set();
265
272
  if (compilation.usedChunkIds) {
266
273
  for (const id of compilation.usedChunkIds) {
@@ -296,7 +303,12 @@ const assignNames = (
296
303
  usedIds,
297
304
  assignName
298
305
  ) => {
299
- /** @type {Map<string, T[]>} */
306
+ /**
307
+ * @template T
308
+ * @typedef {Map<string, T[]>} MapToItem
309
+ */
310
+
311
+ /** @type {MapToItem<T>} */
300
312
  const nameToItems = new Map();
301
313
 
302
314
  for (const item of items) {
@@ -304,7 +316,7 @@ const assignNames = (
304
316
  addToMapOfItems(nameToItems, name, item);
305
317
  }
306
318
 
307
- /** @type {Map<string, T[]>} */
319
+ /** @type {MapToItem<T>} */
308
320
  const nameToItems2 = new Map();
309
321
 
310
322
  for (const [name, items] of nameToItems) {
@@ -399,7 +411,7 @@ const assignDeterministicIds = (
399
411
  };
400
412
 
401
413
  /**
402
- * @param {Set<string>} usedIds used ids
414
+ * @param {UsedModuleIds} usedIds used ids
403
415
  * @param {Iterable<Module>} modules the modules
404
416
  * @param {Compilation} compilation the compilation
405
417
  * @returns {void}
package/lib/index.js CHANGED
@@ -232,6 +232,9 @@ module.exports = mergeExports(fn, {
232
232
  get DynamicEntryPlugin() {
233
233
  return require("./DynamicEntryPlugin");
234
234
  },
235
+ get DotenvPlugin() {
236
+ return require("./DotenvPlugin");
237
+ },
235
238
  get EntryOptionPlugin() {
236
239
  return require("./EntryOptionPlugin");
237
240
  },
@@ -355,6 +358,9 @@ module.exports = mergeExports(fn, {
355
358
  get Stats() {
356
359
  return require("./Stats");
357
360
  },
361
+ get ManifestPlugin() {
362
+ return require("./ManifestPlugin");
363
+ },
358
364
  get Template() {
359
365
  return require("./Template");
360
366
  },
@@ -16,17 +16,28 @@ const Entrypoint = require("../Entrypoint");
16
16
  * @returns {Set<Chunk>} chunks
17
17
  */
18
18
  const getAllChunks = (entrypoint, excludedChunk1, excludedChunk2) => {
19
+ /** @type {Set<Entrypoint>} */
19
20
  const queue = new Set([entrypoint]);
21
+ /** @type {Set<Entrypoint>} */
22
+ const groups = new Set();
23
+ for (const group of queue) {
24
+ if (group !== entrypoint) {
25
+ groups.add(group);
26
+ }
27
+ for (const parent of group.parentsIterable) {
28
+ if (parent instanceof Entrypoint) queue.add(parent);
29
+ }
30
+ }
31
+ groups.add(entrypoint);
32
+
33
+ /** @type {Set<Chunk>} */
20
34
  const chunks = new Set();
21
- for (const entrypoint of queue) {
22
- for (const chunk of entrypoint.chunks) {
35
+ for (const group of groups) {
36
+ for (const chunk of group.chunks) {
23
37
  if (chunk === excludedChunk1) continue;
24
38
  if (chunk === excludedChunk2) continue;
25
39
  chunks.add(chunk);
26
40
  }
27
- for (const parent of entrypoint.parentsIterable) {
28
- if (parent instanceof Entrypoint) queue.add(parent);
29
- }
30
41
  }
31
42
  return chunks;
32
43
  };
@@ -9,7 +9,7 @@ const util = require("util");
9
9
  const { RawSource, ReplaceSource } = require("webpack-sources");
10
10
  const Generator = require("../Generator");
11
11
  const InitFragment = require("../InitFragment");
12
- const { JS_TYPES } = require("../ModuleSourceTypesConstants");
12
+ const { JAVASCRIPT_TYPES } = require("../ModuleSourceTypeConstants");
13
13
  const HarmonyCompatibilityDependency = require("../dependencies/HarmonyCompatibilityDependency");
14
14
 
15
15
  /** @typedef {import("webpack-sources").Source} Source */
@@ -21,6 +21,7 @@ const HarmonyCompatibilityDependency = require("../dependencies/HarmonyCompatibi
21
21
  /** @typedef {import("../Generator").GenerateContext} GenerateContext */
22
22
  /** @typedef {import("../Module")} Module */
23
23
  /** @typedef {import("../Module").ConcatenationBailoutReasonContext} ConcatenationBailoutReasonContext */
24
+ /** @typedef {import("../Module").SourceType} SourceType */
24
25
  /** @typedef {import("../Module").SourceTypes} SourceTypes */
25
26
  /** @typedef {import("../NormalModule")} NormalModule */
26
27
 
@@ -59,12 +60,12 @@ class JavascriptGenerator extends Generator {
59
60
  * @returns {SourceTypes} available types (do not mutate)
60
61
  */
61
62
  getTypes(module) {
62
- return JS_TYPES;
63
+ return JAVASCRIPT_TYPES;
63
64
  }
64
65
 
65
66
  /**
66
67
  * @param {NormalModule} module the module
67
- * @param {string=} type source type
68
+ * @param {SourceType=} type source type
68
69
  * @returns {number} estimate size of the module
69
70
  */
70
71
  getSize(module, type) {
@@ -101,107 +102,6 @@ class JavascriptGenerator extends Generator {
101
102
  }
102
103
  }
103
104
 
104
- /**
105
- * @param {NormalModule} module module for which the code should be generated
106
- * @param {GenerateContext} generateContext context for generate
107
- * @returns {Source | null} generated code
108
- */
109
- generate(module, generateContext) {
110
- const originalSource = module.originalSource();
111
- if (!originalSource) {
112
- return DEFAULT_SOURCE.source();
113
- }
114
-
115
- const source = new ReplaceSource(originalSource);
116
- /** @type {InitFragment<GenerateContext>[]} */
117
- const initFragments = [];
118
-
119
- this.sourceModule(module, initFragments, source, generateContext);
120
-
121
- return InitFragment.addToSource(source, initFragments, generateContext);
122
- }
123
-
124
- /**
125
- * @param {Error} error the error
126
- * @param {NormalModule} module module for which the code should be generated
127
- * @param {GenerateContext} generateContext context for generate
128
- * @returns {Source | null} generated code
129
- */
130
- generateError(error, module, generateContext) {
131
- return new RawSource(`throw new Error(${JSON.stringify(error.message)});`);
132
- }
133
-
134
- /**
135
- * @param {Module} module the module to generate
136
- * @param {InitFragment<GenerateContext>[]} initFragments mutable list of init fragments
137
- * @param {ReplaceSource} source the current replace source which can be modified
138
- * @param {GenerateContext} generateContext the generateContext
139
- * @returns {void}
140
- */
141
- sourceModule(module, initFragments, source, generateContext) {
142
- for (const dependency of module.dependencies) {
143
- this.sourceDependency(
144
- module,
145
- dependency,
146
- initFragments,
147
- source,
148
- generateContext
149
- );
150
- }
151
-
152
- if (module.presentationalDependencies !== undefined) {
153
- for (const dependency of module.presentationalDependencies) {
154
- this.sourceDependency(
155
- module,
156
- dependency,
157
- initFragments,
158
- source,
159
- generateContext
160
- );
161
- }
162
- }
163
-
164
- for (const childBlock of module.blocks) {
165
- this.sourceBlock(
166
- module,
167
- childBlock,
168
- initFragments,
169
- source,
170
- generateContext
171
- );
172
- }
173
- }
174
-
175
- /**
176
- * @param {Module} module the module to generate
177
- * @param {DependenciesBlock} block the dependencies block which will be processed
178
- * @param {InitFragment<GenerateContext>[]} initFragments mutable list of init fragments
179
- * @param {ReplaceSource} source the current replace source which can be modified
180
- * @param {GenerateContext} generateContext the generateContext
181
- * @returns {void}
182
- */
183
- sourceBlock(module, block, initFragments, source, generateContext) {
184
- for (const dependency of block.dependencies) {
185
- this.sourceDependency(
186
- module,
187
- dependency,
188
- initFragments,
189
- source,
190
- generateContext
191
- );
192
- }
193
-
194
- for (const childBlock of block.blocks) {
195
- this.sourceBlock(
196
- module,
197
- childBlock,
198
- initFragments,
199
- source,
200
- generateContext
201
- );
202
- }
203
- }
204
-
205
105
  /**
206
106
  * @param {Module} module the current module
207
107
  * @param {Dependency} dependency the dependency to generate
@@ -271,6 +171,107 @@ class JavascriptGenerator extends Generator {
271
171
  }
272
172
  }
273
173
  }
174
+
175
+ /**
176
+ * @param {Module} module the module to generate
177
+ * @param {DependenciesBlock} block the dependencies block which will be processed
178
+ * @param {InitFragment<GenerateContext>[]} initFragments mutable list of init fragments
179
+ * @param {ReplaceSource} source the current replace source which can be modified
180
+ * @param {GenerateContext} generateContext the generateContext
181
+ * @returns {void}
182
+ */
183
+ sourceBlock(module, block, initFragments, source, generateContext) {
184
+ for (const dependency of block.dependencies) {
185
+ this.sourceDependency(
186
+ module,
187
+ dependency,
188
+ initFragments,
189
+ source,
190
+ generateContext
191
+ );
192
+ }
193
+
194
+ for (const childBlock of block.blocks) {
195
+ this.sourceBlock(
196
+ module,
197
+ childBlock,
198
+ initFragments,
199
+ source,
200
+ generateContext
201
+ );
202
+ }
203
+ }
204
+
205
+ /**
206
+ * @param {Module} module the module to generate
207
+ * @param {InitFragment<GenerateContext>[]} initFragments mutable list of init fragments
208
+ * @param {ReplaceSource} source the current replace source which can be modified
209
+ * @param {GenerateContext} generateContext the generateContext
210
+ * @returns {void}
211
+ */
212
+ sourceModule(module, initFragments, source, generateContext) {
213
+ for (const dependency of module.dependencies) {
214
+ this.sourceDependency(
215
+ module,
216
+ dependency,
217
+ initFragments,
218
+ source,
219
+ generateContext
220
+ );
221
+ }
222
+
223
+ if (module.presentationalDependencies !== undefined) {
224
+ for (const dependency of module.presentationalDependencies) {
225
+ this.sourceDependency(
226
+ module,
227
+ dependency,
228
+ initFragments,
229
+ source,
230
+ generateContext
231
+ );
232
+ }
233
+ }
234
+
235
+ for (const childBlock of module.blocks) {
236
+ this.sourceBlock(
237
+ module,
238
+ childBlock,
239
+ initFragments,
240
+ source,
241
+ generateContext
242
+ );
243
+ }
244
+ }
245
+
246
+ /**
247
+ * @param {NormalModule} module module for which the code should be generated
248
+ * @param {GenerateContext} generateContext context for generate
249
+ * @returns {Source | null} generated code
250
+ */
251
+ generate(module, generateContext) {
252
+ const originalSource = module.originalSource();
253
+ if (!originalSource) {
254
+ return DEFAULT_SOURCE.source();
255
+ }
256
+
257
+ const source = new ReplaceSource(originalSource);
258
+ /** @type {InitFragment<GenerateContext>[]} */
259
+ const initFragments = [];
260
+
261
+ this.sourceModule(module, initFragments, source, generateContext);
262
+
263
+ return InitFragment.addToSource(source, initFragments, generateContext);
264
+ }
265
+
266
+ /**
267
+ * @param {Error} error the error
268
+ * @param {NormalModule} module module for which the code should be generated
269
+ * @param {GenerateContext} generateContext context for generate
270
+ * @returns {Source | null} generated code
271
+ */
272
+ generateError(error, module, generateContext) {
273
+ return new RawSource(`throw new Error(${JSON.stringify(error.message)});`);
274
+ }
274
275
  }
275
276
 
276
277
  module.exports = JavascriptGenerator;