webpack 5.59.0 → 5.71.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 (209) hide show
  1. package/README.md +1 -7
  2. package/hot/lazy-compilation-node.js +3 -1
  3. package/hot/poll.js +1 -1
  4. package/hot/signal.js +1 -1
  5. package/lib/APIPlugin.js +33 -0
  6. package/lib/BannerPlugin.js +10 -4
  7. package/lib/Cache.js +1 -1
  8. package/lib/CacheFacade.js +4 -11
  9. package/lib/Chunk.js +6 -3
  10. package/lib/ChunkGraph.js +1 -2
  11. package/lib/ChunkGroup.js +1 -1
  12. package/lib/CleanPlugin.js +81 -20
  13. package/lib/Compilation.js +179 -91
  14. package/lib/Compiler.js +86 -17
  15. package/lib/ConstPlugin.js +2 -2
  16. package/lib/ContextModule.js +142 -51
  17. package/lib/ContextModuleFactory.js +65 -25
  18. package/lib/DelegatedModule.js +1 -1
  19. package/lib/DelegatedModuleFactoryPlugin.js +1 -1
  20. package/lib/Dependency.js +17 -0
  21. package/lib/DependencyTemplate.js +9 -0
  22. package/lib/DependencyTemplates.js +1 -1
  23. package/lib/DllModule.js +1 -1
  24. package/lib/EntryOptionPlugin.js +2 -0
  25. package/lib/ErrorHelpers.js +2 -2
  26. package/lib/EvalDevToolModulePlugin.js +16 -1
  27. package/lib/EvalSourceMapDevToolPlugin.js +18 -1
  28. package/lib/ExportsInfo.js +4 -4
  29. package/lib/ExternalModule.js +94 -54
  30. package/lib/ExternalModuleFactoryPlugin.js +5 -5
  31. package/lib/FileSystemInfo.js +89 -44
  32. package/lib/Generator.js +3 -0
  33. package/lib/HookWebpackError.js +1 -1
  34. package/lib/HotModuleReplacementPlugin.js +3 -1
  35. package/lib/LoaderOptionsPlugin.js +1 -1
  36. package/lib/Module.js +27 -4
  37. package/lib/ModuleFilenameHelpers.js +8 -4
  38. package/lib/ModuleHashingError.js +29 -0
  39. package/lib/MultiCompiler.js +1 -1
  40. package/lib/MultiWatching.js +1 -1
  41. package/lib/NodeStuffPlugin.js +10 -0
  42. package/lib/NormalModule.js +41 -26
  43. package/lib/NormalModuleFactory.js +42 -37
  44. package/lib/ProgressPlugin.js +4 -5
  45. package/lib/RawModule.js +1 -1
  46. package/lib/RuntimeGlobals.js +29 -1
  47. package/lib/RuntimeModule.js +1 -1
  48. package/lib/RuntimePlugin.js +77 -1
  49. package/lib/RuntimeTemplate.js +114 -2
  50. package/lib/Template.js +2 -1
  51. package/lib/TemplatedPathPlugin.js +48 -23
  52. package/lib/WatchIgnorePlugin.js +19 -7
  53. package/lib/Watching.js +33 -19
  54. package/lib/WebpackOptionsApply.js +57 -11
  55. package/lib/asset/AssetGenerator.js +193 -63
  56. package/lib/asset/AssetModulesPlugin.js +3 -0
  57. package/lib/asset/RawDataUrlModule.js +148 -0
  58. package/lib/async-modules/AwaitDependenciesInitFragment.js +4 -4
  59. package/lib/buildChunkGraph.js +36 -6
  60. package/lib/cache/PackFileCacheStrategy.js +7 -4
  61. package/lib/cache/ResolverCachePlugin.js +90 -29
  62. package/lib/cli.js +44 -3
  63. package/lib/config/browserslistTargetHandler.js +41 -6
  64. package/lib/config/defaults.js +115 -19
  65. package/lib/config/normalization.js +9 -0
  66. package/lib/config/target.js +10 -0
  67. package/lib/container/ContainerEntryModule.js +8 -5
  68. package/lib/container/FallbackModule.js +4 -4
  69. package/lib/container/RemoteModule.js +4 -2
  70. package/lib/css/CssExportsGenerator.js +139 -0
  71. package/lib/css/CssGenerator.js +109 -0
  72. package/lib/css/CssLoadingRuntimeModule.js +440 -0
  73. package/lib/css/CssModulesPlugin.js +462 -0
  74. package/lib/css/CssParser.js +618 -0
  75. package/lib/css/walkCssTokens.js +659 -0
  76. package/lib/debug/ProfilingPlugin.js +24 -21
  77. package/lib/dependencies/AMDRequireDependency.js +6 -6
  78. package/lib/dependencies/CommonJsExportsParserPlugin.js +1 -2
  79. package/lib/dependencies/CommonJsFullRequireDependency.js +5 -1
  80. package/lib/dependencies/CommonJsImportsParserPlugin.js +5 -3
  81. package/lib/dependencies/CommonJsRequireContextDependency.js +5 -1
  82. package/lib/dependencies/ContextDependency.js +1 -0
  83. package/lib/dependencies/ContextDependencyHelpers.js +3 -3
  84. package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +4 -1
  85. package/lib/dependencies/ContextElementDependency.js +41 -3
  86. package/lib/dependencies/CreateScriptUrlDependency.js +12 -0
  87. package/lib/dependencies/CssExportDependency.js +85 -0
  88. package/lib/dependencies/CssImportDependency.js +75 -0
  89. package/lib/dependencies/CssLocalIdentifierDependency.js +119 -0
  90. package/lib/dependencies/CssSelfLocalIdentifierDependency.js +101 -0
  91. package/lib/dependencies/CssUrlDependency.js +132 -0
  92. package/lib/dependencies/ExportsInfoDependency.js +6 -0
  93. package/lib/dependencies/HarmonyAcceptImportDependency.js +5 -3
  94. package/lib/dependencies/HarmonyCompatibilityDependency.js +5 -5
  95. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +95 -0
  96. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +12 -3
  97. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +25 -17
  98. package/lib/dependencies/HarmonyExportInitFragment.js +4 -1
  99. package/lib/dependencies/HarmonyImportDependency.js +23 -0
  100. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +142 -45
  101. package/lib/dependencies/HarmonyImportSpecifierDependency.js +46 -22
  102. package/lib/dependencies/HarmonyModulesPlugin.js +10 -0
  103. package/lib/dependencies/ImportContextDependency.js +0 -2
  104. package/lib/dependencies/ImportMetaContextDependency.js +35 -0
  105. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +252 -0
  106. package/lib/dependencies/ImportMetaContextPlugin.js +59 -0
  107. package/lib/dependencies/ImportMetaPlugin.js +22 -3
  108. package/lib/dependencies/LoaderPlugin.js +4 -2
  109. package/lib/dependencies/RequireContextDependency.js +0 -16
  110. package/lib/dependencies/RequireEnsureDependency.js +2 -2
  111. package/lib/dependencies/URLDependency.js +3 -8
  112. package/lib/dependencies/URLPlugin.js +1 -1
  113. package/lib/esm/ModuleChunkFormatPlugin.js +74 -49
  114. package/lib/esm/ModuleChunkLoadingPlugin.js +3 -1
  115. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +25 -9
  116. package/lib/hmr/HotModuleReplacement.runtime.js +29 -14
  117. package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +4 -3
  118. package/lib/hmr/LazyCompilationPlugin.js +54 -26
  119. package/lib/hmr/lazyCompilationBackend.js +51 -12
  120. package/lib/ids/DeterministicModuleIdsPlugin.js +55 -35
  121. package/lib/ids/HashedModuleIdsPlugin.js +11 -14
  122. package/lib/ids/IdHelpers.js +25 -11
  123. package/lib/ids/NamedModuleIdsPlugin.js +6 -9
  124. package/lib/ids/NaturalModuleIdsPlugin.js +10 -13
  125. package/lib/ids/OccurrenceModuleIdsPlugin.js +13 -10
  126. package/lib/ids/SyncModuleIdsPlugin.js +140 -0
  127. package/lib/index.js +13 -0
  128. package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +2 -2
  129. package/lib/javascript/BasicEvaluatedExpression.js +5 -2
  130. package/lib/javascript/ChunkHelpers.js +33 -0
  131. package/lib/javascript/JavascriptGenerator.js +1 -0
  132. package/lib/javascript/JavascriptModulesPlugin.js +27 -2
  133. package/lib/javascript/JavascriptParser.js +82 -48
  134. package/lib/javascript/StartupHelpers.js +7 -30
  135. package/lib/library/AssignLibraryPlugin.js +39 -15
  136. package/lib/library/EnableLibraryPlugin.js +11 -0
  137. package/lib/library/UmdLibraryPlugin.js +5 -3
  138. package/lib/node/NodeTargetPlugin.js +3 -0
  139. package/lib/node/NodeWatchFileSystem.js +85 -31
  140. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +23 -8
  141. package/lib/node/RequireChunkLoadingRuntimeModule.js +24 -9
  142. package/lib/optimize/ConcatenatedModule.js +21 -9
  143. package/lib/optimize/ModuleConcatenationPlugin.js +5 -2
  144. package/lib/optimize/SplitChunksPlugin.js +8 -1
  145. package/lib/runtime/AsyncModuleRuntimeModule.js +27 -17
  146. package/lib/runtime/BaseUriRuntimeModule.js +31 -0
  147. package/lib/runtime/CreateScriptRuntimeModule.js +36 -0
  148. package/lib/runtime/CreateScriptUrlRuntimeModule.js +9 -34
  149. package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +76 -0
  150. package/lib/schemes/HttpUriPlugin.js +77 -14
  151. package/lib/serialization/FileMiddleware.js +44 -9
  152. package/lib/sharing/ConsumeSharedModule.js +8 -2
  153. package/lib/sharing/ConsumeSharedRuntimeModule.js +26 -5
  154. package/lib/sharing/ProvideSharedModule.js +4 -2
  155. package/lib/sharing/ShareRuntimeModule.js +1 -1
  156. package/lib/sharing/utils.js +1 -1
  157. package/lib/stats/DefaultStatsFactoryPlugin.js +113 -68
  158. package/lib/stats/DefaultStatsPrinterPlugin.js +89 -24
  159. package/lib/util/ArrayHelpers.js +30 -0
  160. package/lib/util/AsyncQueue.js +1 -1
  161. package/lib/util/compileBooleanMatcher.js +1 -1
  162. package/lib/util/create-schema-validation.js +9 -2
  163. package/lib/util/createHash.js +12 -0
  164. package/lib/util/deprecation.js +10 -2
  165. package/lib/util/deterministicGrouping.js +1 -1
  166. package/lib/util/extractUrlAndGlobal.js +3 -0
  167. package/lib/util/fs.js +11 -0
  168. package/lib/util/hash/BatchedHash.js +7 -4
  169. package/lib/util/hash/md4.js +20 -0
  170. package/lib/util/hash/wasm-hash.js +163 -0
  171. package/lib/util/hash/xxhash64.js +5 -139
  172. package/lib/util/identifier.js +65 -44
  173. package/lib/util/internalSerializables.js +15 -0
  174. package/lib/util/nonNumericOnlyHash.js +22 -0
  175. package/lib/util/semver.js +17 -10
  176. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +9 -3
  177. package/lib/web/JsonpChunkLoadingRuntimeModule.js +20 -9
  178. package/lib/webpack.js +10 -3
  179. package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +3 -11
  180. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +33 -22
  181. package/module.d.ts +215 -0
  182. package/package.json +23 -28
  183. package/schemas/WebpackOptions.check.js +1 -1
  184. package/schemas/WebpackOptions.json +254 -29
  185. package/schemas/plugins/DllReferencePlugin.check.js +1 -1
  186. package/schemas/plugins/HashedModuleIdsPlugin.check.js +1 -1
  187. package/schemas/plugins/ProgressPlugin.check.js +1 -1
  188. package/schemas/plugins/asset/AssetGeneratorOptions.check.js +1 -1
  189. package/schemas/plugins/asset/AssetParserOptions.check.js +1 -1
  190. package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.js +1 -1
  191. package/schemas/plugins/container/ContainerPlugin.check.js +1 -1
  192. package/schemas/plugins/container/ContainerPlugin.json +2 -1
  193. package/schemas/plugins/container/ContainerReferencePlugin.check.js +1 -1
  194. package/schemas/plugins/container/ContainerReferencePlugin.json +1 -0
  195. package/schemas/plugins/container/ExternalsType.check.js +1 -1
  196. package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
  197. package/schemas/plugins/container/ModuleFederationPlugin.json +3 -1
  198. package/schemas/plugins/css/CssGeneratorOptions.check.d.ts +7 -0
  199. package/schemas/plugins/css/CssGeneratorOptions.check.js +6 -0
  200. package/schemas/plugins/css/CssGeneratorOptions.json +3 -0
  201. package/schemas/plugins/css/CssParserOptions.check.d.ts +7 -0
  202. package/schemas/plugins/css/CssParserOptions.check.js +6 -0
  203. package/schemas/plugins/css/CssParserOptions.json +3 -0
  204. package/schemas/plugins/optimize/AggressiveSplittingPlugin.check.js +1 -1
  205. package/schemas/plugins/optimize/LimitChunkCountPlugin.check.js +1 -1
  206. package/schemas/plugins/optimize/MinChunkSizePlugin.check.js +1 -1
  207. package/schemas/plugins/schemes/HttpUriPlugin.check.js +1 -1
  208. package/schemas/plugins/schemes/HttpUriPlugin.json +4 -0
  209. package/types.d.ts +628 -179
@@ -106,7 +106,7 @@ class ResolverCachePlugin {
106
106
  * @param {Resolver} resolver the resolver
107
107
  * @param {Object} resolveContext context for resolving meta info
108
108
  * @param {Object} request the request info object
109
- * @param {function(Error=, Object=): void} callback callback function
109
+ * @param {function((Error | null)=, Object=): void} callback callback function
110
110
  * @returns {void}
111
111
  */
112
112
  const doRealResolve = (
@@ -128,6 +128,13 @@ class ResolverCachePlugin {
128
128
  fileDependencies: new LazySet(),
129
129
  contextDependencies: new LazySet()
130
130
  };
131
+ let yieldResult;
132
+ let withYield = false;
133
+ if (typeof newResolveContext.yield === "function") {
134
+ yieldResult = [];
135
+ withYield = true;
136
+ newResolveContext.yield = obj => yieldResult.push(obj);
137
+ }
131
138
  const propagate = key => {
132
139
  if (resolveContext[key]) {
133
140
  addAllToSet(resolveContext[key], newResolveContext[key]);
@@ -155,15 +162,22 @@ class ResolverCachePlugin {
155
162
  snapshotOptions,
156
163
  (err, snapshot) => {
157
164
  if (err) return callback(err);
165
+ const resolveResult = withYield ? yieldResult : result;
166
+ // since we intercept resolve hook
167
+ // we still can get result in callback
168
+ if (withYield && result) yieldResult.push(result);
158
169
  if (!snapshot) {
159
- if (result) return callback(null, result);
170
+ if (resolveResult) return callback(null, resolveResult);
160
171
  return callback();
161
172
  }
162
- itemCache.store(new CacheEntry(result, snapshot), storeErr => {
163
- if (storeErr) return callback(storeErr);
164
- if (result) return callback(null, result);
165
- callback();
166
- });
173
+ itemCache.store(
174
+ new CacheEntry(resolveResult, snapshot),
175
+ storeErr => {
176
+ if (storeErr) return callback(storeErr);
177
+ if (resolveResult) return callback(null, resolveResult);
178
+ callback();
179
+ }
180
+ );
167
181
  }
168
182
  );
169
183
  }
@@ -173,6 +187,8 @@ class ResolverCachePlugin {
173
187
  factory(type, hook) {
174
188
  /** @type {Map<string, (function(Error=, Object=): void)[]>} */
175
189
  const activeRequests = new Map();
190
+ /** @type {Map<string, [function(Error=, Object=): void, function(Error=, Object=): void][]>} */
191
+ const activeRequestsWithYield = new Map();
176
192
  hook.tap(
177
193
  "ResolverCachePlugin",
178
194
  /**
@@ -197,29 +213,67 @@ class ResolverCachePlugin {
197
213
  if (request._ResolverCachePluginCacheMiss || !fileSystemInfo) {
198
214
  return callback();
199
215
  }
200
- const identifier = `${type}${optionsIdent}${objectToString(
201
- request,
202
- !cacheWithContext
203
- )}`;
204
- const activeRequest = activeRequests.get(identifier);
205
- if (activeRequest) {
206
- activeRequest.push(callback);
207
- return;
216
+ const withYield = typeof resolveContext.yield === "function";
217
+ const identifier = `${type}${
218
+ withYield ? "|yield" : "|default"
219
+ }${optionsIdent}${objectToString(request, !cacheWithContext)}`;
220
+
221
+ if (withYield) {
222
+ const activeRequest = activeRequestsWithYield.get(identifier);
223
+ if (activeRequest) {
224
+ activeRequest[0].push(callback);
225
+ activeRequest[1].push(resolveContext.yield);
226
+ return;
227
+ }
228
+ } else {
229
+ const activeRequest = activeRequests.get(identifier);
230
+ if (activeRequest) {
231
+ activeRequest.push(callback);
232
+ return;
233
+ }
208
234
  }
209
235
  const itemCache = cache.getItemCache(identifier, null);
210
- let callbacks;
211
- const done = (err, result) => {
212
- if (callbacks === undefined) {
213
- callback(err, result);
214
- callbacks = false;
215
- } else {
216
- for (const callback of callbacks) {
217
- callback(err, result);
218
- }
219
- activeRequests.delete(identifier);
220
- callbacks = false;
221
- }
222
- };
236
+ let callbacks, yields;
237
+ const done = withYield
238
+ ? (err, result) => {
239
+ if (callbacks === undefined) {
240
+ if (err) {
241
+ callback(err);
242
+ } else {
243
+ if (result)
244
+ for (const r of result) resolveContext.yield(r);
245
+ callback(null, null);
246
+ }
247
+ yields = undefined;
248
+ callbacks = false;
249
+ } else {
250
+ if (err) {
251
+ for (const cb of callbacks) cb(err);
252
+ } else {
253
+ for (let i = 0; i < callbacks.length; i++) {
254
+ const cb = callbacks[i];
255
+ const yield_ = yields[i];
256
+ if (result) for (const r of result) yield_(r);
257
+ cb(null, null);
258
+ }
259
+ }
260
+ activeRequestsWithYield.delete(identifier);
261
+ yields = undefined;
262
+ callbacks = false;
263
+ }
264
+ }
265
+ : (err, result) => {
266
+ if (callbacks === undefined) {
267
+ callback(err, result);
268
+ callbacks = false;
269
+ } else {
270
+ for (const callback of callbacks) {
271
+ callback(err, result);
272
+ }
273
+ activeRequests.delete(identifier);
274
+ callbacks = false;
275
+ }
276
+ };
223
277
  /**
224
278
  * @param {Error=} err error if any
225
279
  * @param {CacheEntry=} cacheEntry cache entry
@@ -276,7 +330,14 @@ class ResolverCachePlugin {
276
330
  }
277
331
  };
278
332
  itemCache.get(processCacheResult);
279
- if (callbacks === undefined) {
333
+ if (withYield && callbacks === undefined) {
334
+ callbacks = [callback];
335
+ yields = [resolveContext.yield];
336
+ activeRequestsWithYield.set(
337
+ identifier,
338
+ /** @type {[any, any]} */ ([callbacks, yields])
339
+ );
340
+ } else if (callbacks === undefined) {
280
341
  callbacks = [callback];
281
342
  activeRequests.set(identifier, callbacks);
282
343
  }
package/lib/cli.js CHANGED
@@ -37,6 +37,7 @@ const webpackSchema = require("../schemas/WebpackOptions.json");
37
37
  /**
38
38
  * @typedef {Object} ArgumentConfig
39
39
  * @property {string} description
40
+ * @property {string} [negatedDescription]
40
41
  * @property {string} path
41
42
  * @property {boolean} multiple
42
43
  * @property {"enum"|"string"|"path"|"number"|"boolean"|"RegExp"|"reset"} type
@@ -96,11 +97,42 @@ const getArguments = (schema = webpackSchema) => {
96
97
  */
97
98
  const getDescription = path => {
98
99
  for (const { schema } of path) {
99
- if (schema.cli && schema.cli.helper) continue;
100
+ if (schema.cli) {
101
+ if (schema.cli.helper) continue;
102
+ if (schema.cli.description) return schema.cli.description;
103
+ }
100
104
  if (schema.description) return schema.description;
101
105
  }
102
106
  };
103
107
 
108
+ /**
109
+ *
110
+ * @param {PathItem[]} path path in the schema
111
+ * @returns {string | undefined} negative description
112
+ */
113
+ const getNegatedDescription = path => {
114
+ for (const { schema } of path) {
115
+ if (schema.cli) {
116
+ if (schema.cli.helper) continue;
117
+ if (schema.cli.negatedDescription) return schema.cli.negatedDescription;
118
+ }
119
+ }
120
+ };
121
+
122
+ /**
123
+ *
124
+ * @param {PathItem[]} path path in the schema
125
+ * @returns {string | undefined} reset description
126
+ */
127
+ const getResetDescription = path => {
128
+ for (const { schema } of path) {
129
+ if (schema.cli) {
130
+ if (schema.cli.helper) continue;
131
+ if (schema.cli.resetDescription) return schema.cli.resetDescription;
132
+ }
133
+ }
134
+ };
135
+
104
136
  /**
105
137
  *
106
138
  * @param {any} schemaPart schema
@@ -142,13 +174,17 @@ const getArguments = (schema = webpackSchema) => {
142
174
  const addResetFlag = path => {
143
175
  const schemaPath = path[0].path;
144
176
  const name = pathToArgumentName(`${schemaPath}.reset`);
145
- const description = getDescription(path);
177
+ const description =
178
+ getResetDescription(path) ||
179
+ `Clear all items provided in '${schemaPath}' configuration. ${getDescription(
180
+ path
181
+ )}`;
146
182
  flags[name] = {
147
183
  configs: [
148
184
  {
149
185
  type: "reset",
150
186
  multiple: false,
151
- description: `Clear all items provided in '${schemaPath}' configuration. ${description}`,
187
+ description,
152
188
  path: schemaPath
153
189
  }
154
190
  ],
@@ -167,6 +203,7 @@ const getArguments = (schema = webpackSchema) => {
167
203
  const argConfigBase = schemaToArgumentConfig(path[0].schema);
168
204
  if (!argConfigBase) return 0;
169
205
 
206
+ const negatedDescription = getNegatedDescription(path);
170
207
  const name = pathToArgumentName(path[0].path);
171
208
  /** @type {ArgumentConfig} */
172
209
  const argConfig = {
@@ -176,6 +213,10 @@ const getArguments = (schema = webpackSchema) => {
176
213
  path: path[0].path
177
214
  };
178
215
 
216
+ if (negatedDescription) {
217
+ argConfig.negatedDescription = negatedDescription;
218
+ }
219
+
179
220
  if (!flags[name]) {
180
221
  flags[name] = {
181
222
  configs: [],
@@ -121,8 +121,7 @@ const resolve = browsers => {
121
121
  // baidu: Not supported
122
122
  // and_uc: Not supported
123
123
  // kaios: Not supported
124
- // Since Node.js 13.14.0 no warning about usage, but it was added 8.5.0 with some limitations and it was improved in 12.0.0 and 13.2.0
125
- node: [13, 14]
124
+ node: [12, 17]
126
125
  });
127
126
 
128
127
  return {
@@ -248,8 +247,7 @@ const resolve = browsers => {
248
247
  // baidu: Not supported
249
248
  // and_uc: Not supported
250
249
  // kaios: Not supported
251
- // Since Node.js 13.14.0 no warning about usage, but it was added 8.5.0 with some limitations and it was improved in 12.0.0 and 13.2.0
252
- node: [13, 14]
250
+ node: [12, 17]
253
251
  }),
254
252
  dynamicImport: es6DynamicImport,
255
253
  dynamicImportInWorker: es6DynamicImport && !anyNode,
@@ -272,9 +270,46 @@ const resolve = browsers => {
272
270
  // baidu: Unknown support
273
271
  // and_uc: Unknown support
274
272
  // kaios: Unknown support
275
- node: [12, 0]
273
+ node: 12
274
+ }),
275
+ optionalChaining: rawChecker({
276
+ chrome: 80,
277
+ and_chr: 80,
278
+ edge: 80,
279
+ firefox: 74,
280
+ and_ff: 79,
281
+ // ie: Not supported,
282
+ opera: 67,
283
+ op_mob: 64,
284
+ safari: [13, 1],
285
+ ios_saf: [13, 4],
286
+ samsung: 13,
287
+ android: 80,
288
+ // and_qq: Not supported
289
+ // baidu: Not supported
290
+ // and_uc: Not supported
291
+ // kaios: Not supported
292
+ node: 14
293
+ }),
294
+ templateLiteral: rawChecker({
295
+ chrome: 41,
296
+ and_chr: 41,
297
+ edge: 13,
298
+ firefox: 34,
299
+ and_ff: 34,
300
+ // ie: Not supported,
301
+ opera: 29,
302
+ op_mob: 64,
303
+ safari: [9, 1],
304
+ ios_saf: 9,
305
+ samsung: 4,
306
+ android: 41,
307
+ and_qq: [10, 4],
308
+ baidu: [7, 12],
309
+ and_uc: [12, 12],
310
+ kaios: [2, 5],
311
+ node: 4
276
312
  }),
277
-
278
313
  browser: browserProperty,
279
314
  electron: false,
280
315
  node: nodeProperty,
@@ -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,9 @@ 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
187
194
  });
188
195
 
189
196
  applyOutputDefaults(options.output, {
@@ -238,6 +245,7 @@ const applyWebpackOptionsDefaults = options => {
238
245
  applyOptimizationDefaults(options.optimization, {
239
246
  development,
240
247
  production,
248
+ css: options.experiments.css,
241
249
  records: !!(options.recordsInputPath || options.recordsOutputPath)
242
250
  });
243
251
 
@@ -262,24 +270,37 @@ const applyWebpackOptionsDefaults = options => {
262
270
  * @param {Object} options options
263
271
  * @param {boolean} options.production is production
264
272
  * @param {boolean} options.development is development mode
273
+ * @param {TargetProperties | false} options.targetProperties target properties
265
274
  * @returns {void}
266
275
  */
267
- const applyExperimentsDefaults = (experiments, { production, development }) => {
268
- D(experiments, "topLevelAwait", false);
276
+ const applyExperimentsDefaults = (
277
+ experiments,
278
+ { production, development, targetProperties }
279
+ ) => {
280
+ D(experiments, "futureDefaults", false);
281
+ D(experiments, "backCompat", !experiments.futureDefaults);
282
+ D(experiments, "topLevelAwait", experiments.futureDefaults);
269
283
  D(experiments, "syncWebAssembly", false);
270
- D(experiments, "asyncWebAssembly", false);
284
+ D(experiments, "asyncWebAssembly", experiments.futureDefaults);
271
285
  D(experiments, "outputModule", false);
272
- D(experiments, "asset", false);
273
286
  D(experiments, "layers", false);
274
287
  D(experiments, "lazyCompilation", undefined);
275
288
  D(experiments, "buildHttp", undefined);
276
- D(experiments, "futureDefaults", false);
277
289
  D(experiments, "cacheUnaffected", experiments.futureDefaults);
290
+ F(experiments, "css", () => (experiments.futureDefaults ? {} : undefined));
278
291
 
279
292
  if (typeof experiments.buildHttp === "object") {
280
293
  D(experiments.buildHttp, "frozen", production);
281
294
  D(experiments.buildHttp, "upgrade", false);
282
295
  }
296
+
297
+ if (typeof experiments.css === "object") {
298
+ D(
299
+ experiments.css,
300
+ "exportsOnly",
301
+ !targetProperties || !targetProperties.document
302
+ );
303
+ }
283
304
  };
284
305
 
285
306
  /**
@@ -382,7 +403,7 @@ const applySnapshotDefaults = (snapshot, { production, futureDefaults }) => {
382
403
  return [path.resolve(match[1], "unplugged")];
383
404
  }
384
405
  } else {
385
- const match = /^(.+?[\\/]node_modules)[\\/]/.exec(
406
+ const match = /^(.+?[\\/]node_modules[\\/])/.exec(
386
407
  // eslint-disable-next-line node/no-extraneous-require
387
408
  require.resolve("watchpack")
388
409
  );
@@ -428,9 +449,14 @@ const applySnapshotDefaults = (snapshot, { production, futureDefaults }) => {
428
449
 
429
450
  /**
430
451
  * @param {JavascriptParserOptions} parserOptions parser options
452
+ * @param {Object} options options
453
+ * @param {boolean} options.futureDefaults is future defaults enabled
431
454
  * @returns {void}
432
455
  */
433
- const applyJavascriptParserOptionsDefaults = parserOptions => {
456
+ const applyJavascriptParserOptionsDefaults = (
457
+ parserOptions,
458
+ { futureDefaults }
459
+ ) => {
434
460
  D(parserOptions, "unknownContextRequest", ".");
435
461
  D(parserOptions, "unknownContextRegExp", false);
436
462
  D(parserOptions, "unknownContextRecursive", true);
@@ -442,9 +468,9 @@ const applyJavascriptParserOptionsDefaults = parserOptions => {
442
468
  D(parserOptions, "wrappedContextRegExp", /.*/);
443
469
  D(parserOptions, "wrappedContextRecursive", true);
444
470
  D(parserOptions, "wrappedContextCritical", false);
445
-
446
- D(parserOptions, "strictExportPresence", false);
447
471
  D(parserOptions, "strictThisContextOnImports", false);
472
+ D(parserOptions, "importMeta", true);
473
+ if (futureDefaults) D(parserOptions, "exportsPresence", "error");
448
474
  };
449
475
 
450
476
  /**
@@ -453,11 +479,13 @@ const applyJavascriptParserOptionsDefaults = parserOptions => {
453
479
  * @param {boolean} options.cache is caching enabled
454
480
  * @param {boolean} options.syncWebAssembly is syncWebAssembly enabled
455
481
  * @param {boolean} options.asyncWebAssembly is asyncWebAssembly enabled
482
+ * @param {CssExperimentOptions} options.css is css enabled
483
+ * @param {boolean} options.futureDefaults is future defaults enabled
456
484
  * @returns {void}
457
485
  */
458
486
  const applyModuleDefaults = (
459
487
  module,
460
- { cache, syncWebAssembly, asyncWebAssembly }
488
+ { cache, syncWebAssembly, asyncWebAssembly, css, futureDefaults }
461
489
  ) => {
462
490
  if (cache) {
463
491
  D(module, "unsafeCache", module => {
@@ -475,7 +503,9 @@ const applyModuleDefaults = (
475
503
  }
476
504
 
477
505
  F(module.parser, "javascript", () => ({}));
478
- applyJavascriptParserOptionsDefaults(module.parser.javascript);
506
+ applyJavascriptParserOptionsDefaults(module.parser.javascript, {
507
+ futureDefaults
508
+ });
479
509
 
480
510
  A(module, "defaultRules", () => {
481
511
  const esm = {
@@ -579,6 +609,41 @@ const applyModuleDefaults = (
579
609
  ...wasm
580
610
  });
581
611
  }
612
+ if (css) {
613
+ const cssRule = {
614
+ type: "css",
615
+ resolve: {
616
+ fullySpecified: true,
617
+ preferRelative: true
618
+ }
619
+ };
620
+ const cssModulesRule = {
621
+ type: "css/module",
622
+ resolve: {
623
+ fullySpecified: true
624
+ }
625
+ };
626
+ rules.push({
627
+ test: /\.css$/i,
628
+ oneOf: [
629
+ {
630
+ test: /\.module\.css$/i,
631
+ ...cssModulesRule
632
+ },
633
+ {
634
+ ...cssRule
635
+ }
636
+ ]
637
+ });
638
+ rules.push({
639
+ mimetype: "text/css+module",
640
+ ...cssModulesRule
641
+ });
642
+ rules.push({
643
+ mimetype: "text/css",
644
+ ...cssRule
645
+ });
646
+ }
582
647
  rules.push(
583
648
  {
584
649
  dependency: "url",
@@ -650,7 +715,15 @@ const applyOutputDefaults = (
650
715
  };
651
716
 
652
717
  F(output, "uniqueName", () => {
653
- const libraryName = getLibraryName(output.library);
718
+ const libraryName = getLibraryName(output.library).replace(
719
+ /^\[(\\*[\w:]+\\*)\](\.)|(\.)\[(\\*[\w:]+\\*)\](?=\.|$)|\[(\\*[\w:]+\\*)\]/g,
720
+ (m, a, d1, d2, b, c) => {
721
+ const content = a || b || c;
722
+ return content.startsWith("\\") && content.endsWith("\\")
723
+ ? `${d2 || ""}[${content.slice(1, -1)}]${d1 || ""}`
724
+ : "";
725
+ }
726
+ );
654
727
  if (libraryName) return libraryName;
655
728
  const pkgPath = path.resolve(context, "package.json");
656
729
  try {
@@ -684,6 +757,20 @@ const applyOutputDefaults = (
684
757
  }
685
758
  return output.module ? "[id].mjs" : "[id].js";
686
759
  });
760
+ F(output, "cssFilename", () => {
761
+ const filename = output.filename;
762
+ if (typeof filename !== "function") {
763
+ return filename.replace(/\.[mc]?js(\?|$)/, ".css$1");
764
+ }
765
+ return "[id].css";
766
+ });
767
+ F(output, "cssChunkFilename", () => {
768
+ const chunkFilename = output.chunkFilename;
769
+ if (typeof chunkFilename !== "function") {
770
+ return chunkFilename.replace(/\.[mc]?js(\?|$)/, ".css$1");
771
+ }
772
+ return "[id].css";
773
+ });
687
774
  D(output, "assetModuleFilename", "[hash][ext][query]");
688
775
  D(output, "webassemblyModuleFilename", "[hash].module.wasm");
689
776
  D(output, "compareBeforeEmit", true);
@@ -736,6 +823,7 @@ const applyOutputDefaults = (
736
823
  "Chunk format can't be selected by default when no target is specified"
737
824
  );
738
825
  });
826
+ D(output, "asyncChunks", true);
739
827
  F(output, "chunkLoading", () => {
740
828
  if (tp) {
741
829
  switch (output.chunkFormat) {
@@ -823,10 +911,11 @@ const applyOutputDefaults = (
823
911
  D(output, "chunkLoadTimeout", 120000);
824
912
  D(output, "hashFunction", futureDefaults ? "xxhash64" : "md4");
825
913
  D(output, "hashDigest", "hex");
826
- D(output, "hashDigestLength", 20);
914
+ D(output, "hashDigestLength", futureDefaults ? 16 : 20);
827
915
  D(output, "strictModuleExceptionHandling", false);
828
916
 
829
917
  const optimistic = v => v || v === undefined;
918
+ const conditionallyOptimistic = (v, c) => (v === undefined && c) || v;
830
919
  F(
831
920
  output.environment,
832
921
  "arrowFunction",
@@ -840,8 +929,12 @@ const applyOutputDefaults = (
840
929
  );
841
930
  F(output.environment, "forOf", () => tp && optimistic(tp.forOf));
842
931
  F(output.environment, "bigIntLiteral", () => tp && tp.bigIntLiteral);
843
- F(output.environment, "dynamicImport", () => tp && tp.dynamicImport);
844
- F(output.environment, "module", () => tp && tp.module);
932
+ F(output.environment, "dynamicImport", () =>
933
+ conditionallyOptimistic(tp && tp.dynamicImport, output.module)
934
+ );
935
+ F(output.environment, "module", () =>
936
+ conditionallyOptimistic(tp && tp.module, output.module)
937
+ );
845
938
 
846
939
  const { trustedTypes } = output;
847
940
  if (trustedTypes) {
@@ -1021,12 +1114,13 @@ const applyPerformanceDefaults = (performance, { production }) => {
1021
1114
  * @param {Object} options options
1022
1115
  * @param {boolean} options.production is production
1023
1116
  * @param {boolean} options.development is development
1117
+ * @param {CssExperimentOptions} options.css is css enabled
1024
1118
  * @param {boolean} options.records using records
1025
1119
  * @returns {void}
1026
1120
  */
1027
1121
  const applyOptimizationDefaults = (
1028
1122
  optimization,
1029
- { production, development, records }
1123
+ { production, development, css, records }
1030
1124
  ) => {
1031
1125
  D(optimization, "removeAvailableModules", false);
1032
1126
  D(optimization, "removeEmptyChunks", true);
@@ -1077,7 +1171,9 @@ const applyOptimizationDefaults = (
1077
1171
  });
1078
1172
  const { splitChunks } = optimization;
1079
1173
  if (splitChunks) {
1080
- A(splitChunks, "defaultSizeTypes", () => ["javascript", "unknown"]);
1174
+ A(splitChunks, "defaultSizeTypes", () =>
1175
+ css ? ["javascript", "css", "unknown"] : ["javascript", "unknown"]
1176
+ );
1081
1177
  D(splitChunks, "hidePathInfo", production);
1082
1178
  D(splitChunks, "chunks", "async");
1083
1179
  D(splitChunks, "usedExports", optimization.usedExports === true);
@@ -180,6 +180,9 @@ const getNormalizedWebpackOptions = config => {
180
180
  experiments.lazyCompilation,
181
181
  options =>
182
182
  options === true ? {} : options === false ? undefined : options
183
+ ),
184
+ css: optionalNestedConfig(experiments.css, options =>
185
+ options === true ? {} : options === false ? undefined : options
183
186
  )
184
187
  })),
185
188
  externals: config.externals,
@@ -229,6 +232,7 @@ const getNormalizedWebpackOptions = config => {
229
232
  wrappedContextRegExp: module.wrappedContextRegExp,
230
233
  wrappedContextRecursive: module.wrappedContextRecursive,
231
234
  wrappedContextCritical: module.wrappedContextCritical,
235
+ // TODO webpack 6 remove
232
236
  strictExportPresence: module.strictExportPresence,
233
237
  strictThisContextOnImports: module.strictThisContextOnImports,
234
238
  ...parserOptions
@@ -289,12 +293,15 @@ const getNormalizedWebpackOptions = config => {
289
293
  /** @type {OutputNormalized} */
290
294
  const result = {
291
295
  assetModuleFilename: output.assetModuleFilename,
296
+ asyncChunks: output.asyncChunks,
292
297
  charset: output.charset,
293
298
  chunkFilename: output.chunkFilename,
294
299
  chunkFormat: output.chunkFormat,
295
300
  chunkLoading: output.chunkLoading,
296
301
  chunkLoadingGlobal: output.chunkLoadingGlobal,
297
302
  chunkLoadTimeout: output.chunkLoadTimeout,
303
+ cssFilename: output.cssFilename,
304
+ cssChunkFilename: output.cssChunkFilename,
298
305
  clean: output.clean,
299
306
  compareBeforeEmit: output.compareBeforeEmit,
300
307
  crossOriginLoading: output.crossOriginLoading,
@@ -481,8 +488,10 @@ const getNormalizedEntryStatic = entry => {
481
488
  filename: value.filename,
482
489
  layer: value.layer,
483
490
  runtime: value.runtime,
491
+ baseUri: value.baseUri,
484
492
  publicPath: value.publicPath,
485
493
  chunkLoading: value.chunkLoading,
494
+ asyncChunks: value.asyncChunks,
486
495
  wasmLoading: value.wasmLoading,
487
496
  dependOn:
488
497
  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,