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
@@ -9,7 +9,7 @@ const { RawSource } = require("webpack-sources");
9
9
  const ConcatenationScope = require("../ConcatenationScope");
10
10
  const { UsageState } = require("../ExportsInfo");
11
11
  const Generator = require("../Generator");
12
- const { JS_TYPES } = require("../ModuleSourceTypesConstants");
12
+ const { JAVASCRIPT_TYPES } = require("../ModuleSourceTypeConstants");
13
13
  const RuntimeGlobals = require("../RuntimeGlobals");
14
14
 
15
15
  /** @typedef {import("webpack-sources").Source} Source */
@@ -17,6 +17,7 @@ const RuntimeGlobals = require("../RuntimeGlobals");
17
17
  /** @typedef {import("../ExportsInfo")} ExportsInfo */
18
18
  /** @typedef {import("../Generator").GenerateContext} GenerateContext */
19
19
  /** @typedef {import("../Module").ConcatenationBailoutReasonContext} ConcatenationBailoutReasonContext */
20
+ /** @typedef {import("../Module").SourceType} SourceType */
20
21
  /** @typedef {import("../Module").SourceTypes} SourceTypes */
21
22
  /** @typedef {import("../NormalModule")} NormalModule */
22
23
  /** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
@@ -26,7 +27,7 @@ const RuntimeGlobals = require("../RuntimeGlobals");
26
27
 
27
28
  /**
28
29
  * @param {JsonValue} data Raw JSON data
29
- * @returns {undefined|string} stringified data
30
+ * @returns {undefined | string} stringified data
30
31
  */
31
32
  const stringifySafe = (data) => {
32
33
  const stringified = JSON.stringify(data);
@@ -132,12 +133,12 @@ class JsonGenerator extends Generator {
132
133
  * @returns {SourceTypes} available types (do not mutate)
133
134
  */
134
135
  getTypes(module) {
135
- return JS_TYPES;
136
+ return JAVASCRIPT_TYPES;
136
137
  }
137
138
 
138
139
  /**
139
140
  * @param {NormalModule} module the module
140
- * @param {string=} type source type
141
+ * @param {SourceType=} type source type
141
142
  * @returns {number} estimate size of the module
142
143
  */
143
144
  getSize(module, type) {
@@ -54,7 +54,8 @@ class JsonParser extends Parser {
54
54
  : parseFn(source[0] === "\uFEFF" ? source.slice(1) : source);
55
55
  } catch (err) {
56
56
  throw new Error(
57
- `Cannot parse JSON: ${/** @type {Error} */ (err).message}`
57
+ `Cannot parse JSON: ${/** @type {Error} */ (err).message}`,
58
+ { cause: err }
58
59
  );
59
60
  }
60
61
  const jsonData = new JsonData(/** @type {Buffer | JsonValue} */ (data));
@@ -64,7 +65,13 @@ class JsonParser extends Parser {
64
65
  const buildMeta = /** @type {BuildMeta} */ (state.module.buildMeta);
65
66
  buildMeta.exportsType = "default";
66
67
  buildMeta.defaultObject =
67
- typeof data === "object" ? "redirect-warn" : false;
68
+ typeof data === "object"
69
+ ? this.options.namedExports === false
70
+ ? false
71
+ : this.options.namedExports === true
72
+ ? "redirect"
73
+ : "redirect-warn"
74
+ : false;
68
75
  state.module.addDependency(
69
76
  new JsonExportsDependency(
70
77
  jsonData,
@@ -308,7 +308,7 @@ class AbstractLibraryPlugin {
308
308
  * @param {Source} source source
309
309
  * @param {Module} module module
310
310
  * @param {ModuleRenderContext} renderContext render context
311
- * @param {Omit<LibraryContext<T>, 'options'>} libraryContext context
311
+ * @param {Omit<LibraryContext<T>, "options">} libraryContext context
312
312
  * @returns {Source} source with library export
313
313
  */
314
314
  renderModuleContent(source, module, renderContext, libraryContext) {
@@ -17,7 +17,10 @@ const AbstractLibraryPlugin = require("./AbstractLibraryPlugin");
17
17
  /** @typedef {import("../Compilation").ChunkHashContext} ChunkHashContext */
18
18
  /** @typedef {import("../javascript/JavascriptModulesPlugin").RenderContext} RenderContext */
19
19
  /** @typedef {import("../util/Hash")} Hash */
20
- /** @template T @typedef {import("./AbstractLibraryPlugin").LibraryContext<T>} LibraryContext<T> */
20
+ /**
21
+ * @template T
22
+ * @typedef {import("./AbstractLibraryPlugin").LibraryContext<T>} LibraryContext<T>
23
+ */
21
24
 
22
25
  /**
23
26
  * @typedef {object} AmdLibraryPluginOptions
@@ -20,7 +20,10 @@ const AbstractLibraryPlugin = require("./AbstractLibraryPlugin");
20
20
  /** @typedef {import("../Module")} Module */
21
21
  /** @typedef {import("../Module").RuntimeRequirements} RuntimeRequirements */
22
22
  /** @typedef {import("../javascript/JavascriptModulesPlugin").StartupRenderContext} StartupRenderContext */
23
- /** @template T @typedef {import("./AbstractLibraryPlugin").LibraryContext<T>} LibraryContext<T> */
23
+ /**
24
+ * @template T
25
+ * @typedef {import("./AbstractLibraryPlugin").LibraryContext<T>} LibraryContext<T>
26
+ */
24
27
 
25
28
  /**
26
29
  * @typedef {object} ExportPropertyLibraryPluginParsed
@@ -21,6 +21,7 @@ const AbstractLibraryPlugin = require("./AbstractLibraryPlugin");
21
21
  /** @typedef {import("../Chunk")} Chunk */
22
22
  /** @typedef {import("../Compiler")} Compiler */
23
23
  /** @typedef {import("../Module")} Module */
24
+ /** @typedef {import("../Module").BuildMeta} BuildMeta */
24
25
  /** @typedef {import("../Module").RuntimeRequirements} RuntimeRequirements */
25
26
  /** @typedef {import("../javascript/JavascriptModulesPlugin").StartupRenderContext} StartupRenderContext */
26
27
  /** @typedef {import("../javascript/JavascriptModulesPlugin").ModuleRenderContext} ModuleRenderContext */
@@ -69,7 +70,28 @@ class ModuleLibraryPlugin extends AbstractLibraryPlugin {
69
70
  compiler.hooks.thisCompilation.tap(PLUGIN_NAME, (compilation) => {
70
71
  const { onDemandExportsGeneration } =
71
72
  ConcatenatedModule.getCompilationHooks(compilation);
72
- onDemandExportsGeneration.tap(PLUGIN_NAME, (_module) => true);
73
+ onDemandExportsGeneration.tap(
74
+ PLUGIN_NAME,
75
+ (module, runtimes, source, finalName) => {
76
+ /** @type {BuildMeta} */
77
+ const buildMeta = module.buildMeta || (module.buildMeta = {});
78
+
79
+ const exportsSourceByRuntime =
80
+ buildMeta.exportsSourceByRuntime ||
81
+ (buildMeta.exportsSourceByRuntime = new Map());
82
+
83
+ const exportsFinalNameByRuntime =
84
+ buildMeta.exportsFinalNameByRuntime ||
85
+ (buildMeta.exportsFinalNameByRuntime = new Map());
86
+
87
+ for (const runtime of runtimes) {
88
+ exportsSourceByRuntime.set(runtime, source);
89
+ exportsFinalNameByRuntime.set(runtime, finalName);
90
+ }
91
+
92
+ return true;
93
+ }
94
+ );
73
95
  });
74
96
  }
75
97
 
@@ -104,16 +126,6 @@ class ModuleLibraryPlugin extends AbstractLibraryPlugin {
104
126
  moduleGraph.addExtraReason(module, "used as library export");
105
127
  }
106
128
 
107
- /**
108
- * @param {Chunk} chunk the chunk
109
- * @param {RuntimeRequirements} set runtime requirements
110
- * @param {LibraryContext<T>} libraryContext context
111
- * @returns {void}
112
- */
113
- runtimeRequirements(chunk, set, libraryContext) {
114
- set.add(RuntimeGlobals.exports);
115
- }
116
-
117
129
  /**
118
130
  * @param {LibraryOptions} library normalized library option
119
131
  * @returns {T | false} preprocess as needed by overriding
@@ -162,10 +174,16 @@ class ModuleLibraryPlugin extends AbstractLibraryPlugin {
162
174
  )
163
175
  ]
164
176
  : moduleGraph.getExportsInfo(module).orderedExports;
177
+
178
+ const exportsFinalNameByRuntime =
179
+ (module.buildMeta &&
180
+ module.buildMeta.exportsFinalNameByRuntime &&
181
+ module.buildMeta.exportsFinalNameByRuntime.get(chunk.runtime)) ||
182
+ {};
183
+
165
184
  const definitions =
166
- inlined && !inlinedInIIFE
167
- ? (module.buildMeta && module.buildMeta.exportsFinalName) || {}
168
- : {};
185
+ inlined && !inlinedInIIFE ? exportsFinalNameByRuntime : {};
186
+
169
187
  /** @type {string[]} */
170
188
  const shortHandedExports = [];
171
189
  /** @type {[string, string][]} */
@@ -278,23 +296,23 @@ class ModuleLibraryPlugin extends AbstractLibraryPlugin {
278
296
  * @param {Source} source source
279
297
  * @param {Module} module module
280
298
  * @param {ModuleRenderContext} renderContext render context
281
- * @param {Omit<LibraryContext<T>, 'options'>} libraryContext context
299
+ * @param {Omit<LibraryContext<T>, "options">} libraryContext context
282
300
  * @returns {Source} source with library export
283
301
  */
284
302
  renderModuleContent(
285
303
  source,
286
304
  module,
287
- { factory, inlinedInIIFE },
305
+ { factory, inlinedInIIFE, chunk },
288
306
  libraryContext
289
307
  ) {
290
- // Re-add `factoryExportsBinding` to the source
291
- // when the module is rendered as a factory or treated as an inlined (startup) module but wrapped in an IIFE
292
- if (
293
- (inlinedInIIFE || factory) &&
308
+ const exportsSource =
294
309
  module.buildMeta &&
295
- module.buildMeta.factoryExportsBinding
296
- ) {
297
- return new ConcatSource(module.buildMeta.factoryExportsBinding, source);
310
+ module.buildMeta.exportsSourceByRuntime &&
311
+ module.buildMeta.exportsSourceByRuntime.get(chunk.runtime);
312
+
313
+ // Re-add the module's exports source when rendered in factory or as an inlined startup module wrapped in an IIFE
314
+ if ((inlinedInIIFE || factory) && exportsSource) {
315
+ return new ConcatSource(exportsSource, source);
298
316
  }
299
317
  return source;
300
318
  }
@@ -19,7 +19,10 @@ const AbstractLibraryPlugin = require("./AbstractLibraryPlugin");
19
19
  /** @typedef {import("../Compilation").ChunkHashContext} ChunkHashContext */
20
20
  /** @typedef {import("../javascript/JavascriptModulesPlugin").RenderContext} RenderContext */
21
21
  /** @typedef {import("../util/Hash")} Hash */
22
- /** @template T @typedef {import("./AbstractLibraryPlugin").LibraryContext<T>} LibraryContext<T> */
22
+ /**
23
+ * @template T
24
+ * @typedef {import("./AbstractLibraryPlugin").LibraryContext<T>} LibraryContext<T>
25
+ */
23
26
 
24
27
  /**
25
28
  * @typedef {object} SystemLibraryPluginOptions
@@ -164,6 +167,10 @@ class SystemLibraryPlugin extends AbstractLibraryPlugin {
164
167
  `Object.defineProperty(${external}, "__esModule", { value: true });`
165
168
  );
166
169
  }
170
+ // See comment above
171
+ instructions.push(
172
+ `${external}["default"] = module["default"] || module;`
173
+ );
167
174
  if (handledNames.length > 0) {
168
175
  const name = `${external}handledNames`;
169
176
  externalVarInitialization.push(
@@ -34,7 +34,7 @@ const accessorToObjectAccess = (accessor) =>
34
34
  /** @typedef {string | string[]} Accessor */
35
35
 
36
36
  /**
37
- * @param {string|undefined} base the path prefix
37
+ * @param {string | undefined} base the path prefix
38
38
  * @param {Accessor} accessor the accessor
39
39
  * @param {string=} joinWith the element separator
40
40
  * @returns {string} the path
@@ -338,7 +338,7 @@ class UmdLibraryPlugin extends AbstractLibraryPlugin {
338
338
  : " var a = factory();\n"
339
339
  } for(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i];\n` +
340
340
  " }\n"
341
- }})(${runtimeTemplate.outputOptions.globalObject}, ${
341
+ }})(${runtimeTemplate.globalObject}, ${
342
342
  runtimeTemplate.supportsArrowFunction()
343
343
  ? `(${externalsArguments(externals)}) =>`
344
344
  : `function(${externalsArguments(externals)})`
@@ -30,6 +30,7 @@ const LogType = Object.freeze({
30
30
  module.exports.LogType = LogType;
31
31
 
32
32
  /** @typedef {typeof LogType[keyof typeof LogType]} LogTypeEnum */
33
+ /** @typedef {Map<string | undefined, [number, number]>} TimersMap */
33
34
 
34
35
  const LOG_SYMBOL = Symbol("webpack logger raw log method");
35
36
  const TIMERS_SYMBOL = Symbol("webpack logger times");
@@ -143,7 +144,7 @@ class WebpackLogger {
143
144
  * @param {string} label label
144
145
  */
145
146
  time(label) {
146
- /** @type {Map<string | undefined, [number, number]>} */
147
+ /** @type {TimersMap} */
147
148
  this[TIMERS_SYMBOL] = this[TIMERS_SYMBOL] || new Map();
148
149
  this[TIMERS_SYMBOL].set(label, process.hrtime());
149
150
  }
@@ -169,7 +170,7 @@ class WebpackLogger {
169
170
  throw new Error(`No such label '${label}' for WebpackLogger.timeEnd()`);
170
171
  }
171
172
  const time = process.hrtime(prev);
172
- /** @type {Map<string | undefined, [number, number]>} */
173
+ /** @type {TimersMap} */
173
174
  (this[TIMERS_SYMBOL]).delete(label);
174
175
  this[LOG_SYMBOL](LogType.time, [label, ...time]);
175
176
  }
@@ -185,9 +186,9 @@ class WebpackLogger {
185
186
  );
186
187
  }
187
188
  const time = process.hrtime(prev);
188
- /** @type {Map<string | undefined, [number, number]>} */
189
+ /** @type {TimersMap} */
189
190
  (this[TIMERS_SYMBOL]).delete(label);
190
- /** @type {Map<string | undefined, [number, number]>} */
191
+ /** @type {TimersMap} */
191
192
  this[TIMERS_AGGREGATES_SYMBOL] =
192
193
  this[TIMERS_AGGREGATES_SYMBOL] || new Map();
193
194
  const current = this[TIMERS_AGGREGATES_SYMBOL].get(label);
@@ -35,8 +35,8 @@ const { LogType } = require("./Logger");
35
35
 
36
36
  /**
37
37
  * @typedef {object} LoggerOptions
38
- * @property {false|true|"none"|"error"|"warn"|"info"|"log"|"verbose"} level loglevel
39
- * @property {FilterTypes|boolean} debug filter for debug logging
38
+ * @property {false | true | "none" | "error" | "warn" | "info" | "log" | "verbose"} level loglevel
39
+ * @property {FilterTypes | boolean} debug filter for debug logging
40
40
  * @property {LoggerConsole} console the console to log to
41
41
  */
42
42
 
@@ -7,6 +7,7 @@
7
7
 
8
8
  const ExternalsPlugin = require("../ExternalsPlugin");
9
9
 
10
+ /** @typedef {import("../../declarations/WebpackOptions").ExternalsType} ExternalsType */
10
11
  /** @typedef {import("../Compiler")} Compiler */
11
12
 
12
13
  const builtins = [
@@ -72,13 +73,20 @@ const builtins = [
72
73
  ];
73
74
 
74
75
  class NodeTargetPlugin {
76
+ /**
77
+ * @param {ExternalsType} type default external type
78
+ */
79
+ constructor(type = "node-commonjs") {
80
+ this.type = type;
81
+ }
82
+
75
83
  /**
76
84
  * Apply the plugin
77
85
  * @param {Compiler} compiler the compiler instance
78
86
  * @returns {void}
79
87
  */
80
88
  apply(compiler) {
81
- new ExternalsPlugin("node-commonjs", builtins).apply(compiler);
89
+ new ExternalsPlugin(this.type, builtins).apply(compiler);
82
90
  }
83
91
  }
84
92
 
@@ -19,8 +19,6 @@ const WasmChunkLoadingRuntimeModule = require("../wasm-sync/WasmChunkLoadingRunt
19
19
  * @property {boolean=} import use import?
20
20
  */
21
21
 
22
- // TODO webpack 6 remove
23
-
24
22
  const PLUGIN_NAME = "ReadFileCompileWasmPlugin";
25
23
 
26
24
  class ReadFileCompileWasmPlugin {