webpack 5.64.4 → 5.68.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 (123) hide show
  1. package/README.md +1 -1
  2. package/lib/APIPlugin.js +33 -0
  3. package/lib/Cache.js +1 -1
  4. package/lib/CacheFacade.js +4 -11
  5. package/lib/Chunk.js +2 -0
  6. package/lib/CleanPlugin.js +1 -1
  7. package/lib/Compilation.js +91 -47
  8. package/lib/Compiler.js +57 -3
  9. package/lib/ContextModule.js +21 -17
  10. package/lib/DelegatedModule.js +1 -1
  11. package/lib/Dependency.js +10 -0
  12. package/lib/DependencyTemplate.js +9 -0
  13. package/lib/DependencyTemplates.js +1 -1
  14. package/lib/DllModule.js +1 -1
  15. package/lib/EvalDevToolModulePlugin.js +16 -1
  16. package/lib/EvalSourceMapDevToolPlugin.js +18 -1
  17. package/lib/ExternalModule.js +94 -54
  18. package/lib/ExternalModuleFactoryPlugin.js +1 -1
  19. package/lib/FileSystemInfo.js +29 -25
  20. package/lib/Generator.js +2 -0
  21. package/lib/HookWebpackError.js +1 -1
  22. package/lib/Module.js +25 -4
  23. package/lib/ModuleFilenameHelpers.js +5 -1
  24. package/lib/MultiCompiler.js +1 -1
  25. package/lib/MultiWatching.js +1 -1
  26. package/lib/NormalModule.js +9 -5
  27. package/lib/RawModule.js +1 -1
  28. package/lib/RuntimeGlobals.js +29 -1
  29. package/lib/RuntimeModule.js +1 -1
  30. package/lib/RuntimePlugin.js +50 -0
  31. package/lib/RuntimeTemplate.js +113 -2
  32. package/lib/Template.js +2 -1
  33. package/lib/Watching.js +2 -2
  34. package/lib/WebpackOptionsApply.js +43 -2
  35. package/lib/asset/AssetGenerator.js +71 -30
  36. package/lib/asset/AssetModulesPlugin.js +3 -0
  37. package/lib/asset/RawDataUrlModule.js +148 -0
  38. package/lib/async-modules/AwaitDependenciesInitFragment.js +4 -4
  39. package/lib/cache/ResolverCachePlugin.js +1 -1
  40. package/lib/cli.js +44 -3
  41. package/lib/config/browserslistTargetHandler.js +38 -1
  42. package/lib/config/defaults.js +80 -6
  43. package/lib/config/normalization.js +5 -0
  44. package/lib/config/target.js +10 -0
  45. package/lib/container/ContainerEntryModule.js +5 -5
  46. package/lib/container/FallbackModule.js +4 -4
  47. package/lib/container/RemoteModule.js +4 -2
  48. package/lib/css/CssExportsGenerator.js +139 -0
  49. package/lib/css/CssGenerator.js +109 -0
  50. package/lib/css/CssLoadingRuntimeModule.js +447 -0
  51. package/lib/css/CssModulesPlugin.js +461 -0
  52. package/lib/css/CssParser.js +618 -0
  53. package/lib/css/walkCssTokens.js +659 -0
  54. package/lib/debug/ProfilingPlugin.js +12 -10
  55. package/lib/dependencies/CreateScriptUrlDependency.js +12 -0
  56. package/lib/dependencies/CssExportDependency.js +85 -0
  57. package/lib/dependencies/CssImportDependency.js +75 -0
  58. package/lib/dependencies/CssLocalIdentifierDependency.js +119 -0
  59. package/lib/dependencies/CssSelfLocalIdentifierDependency.js +101 -0
  60. package/lib/dependencies/CssUrlDependency.js +132 -0
  61. package/lib/dependencies/HarmonyCompatibilityDependency.js +5 -5
  62. package/lib/dependencies/ImportMetaPlugin.js +22 -3
  63. package/lib/dependencies/LoaderPlugin.js +2 -2
  64. package/lib/dependencies/URLDependency.js +3 -8
  65. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +1 -1
  66. package/lib/hmr/LazyCompilationPlugin.js +45 -21
  67. package/lib/hmr/lazyCompilationBackend.js +4 -2
  68. package/lib/ids/DeterministicModuleIdsPlugin.js +55 -35
  69. package/lib/ids/HashedModuleIdsPlugin.js +9 -12
  70. package/lib/ids/IdHelpers.js +24 -10
  71. package/lib/ids/NamedModuleIdsPlugin.js +6 -9
  72. package/lib/ids/NaturalModuleIdsPlugin.js +10 -13
  73. package/lib/ids/OccurrenceModuleIdsPlugin.js +13 -10
  74. package/lib/ids/SyncModuleIdsPlugin.js +140 -0
  75. package/lib/index.js +8 -0
  76. package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +2 -2
  77. package/lib/javascript/JavascriptGenerator.js +1 -0
  78. package/lib/javascript/JavascriptParser.js +7 -0
  79. package/lib/javascript/StartupHelpers.js +3 -3
  80. package/lib/library/AssignLibraryPlugin.js +31 -13
  81. package/lib/library/EnableLibraryPlugin.js +11 -0
  82. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +1 -1
  83. package/lib/node/RequireChunkLoadingRuntimeModule.js +1 -1
  84. package/lib/optimize/ConcatenatedModule.js +11 -5
  85. package/lib/runtime/AsyncModuleRuntimeModule.js +25 -15
  86. package/lib/runtime/CreateScriptRuntimeModule.js +36 -0
  87. package/lib/runtime/CreateScriptUrlRuntimeModule.js +9 -34
  88. package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +76 -0
  89. package/lib/schemes/HttpUriPlugin.js +8 -8
  90. package/lib/sharing/ConsumeSharedModule.js +8 -2
  91. package/lib/sharing/ConsumeSharedRuntimeModule.js +21 -0
  92. package/lib/sharing/ProvideSharedModule.js +4 -2
  93. package/lib/sharing/utils.js +1 -1
  94. package/lib/stats/DefaultStatsFactoryPlugin.js +112 -67
  95. package/lib/stats/DefaultStatsPrinterPlugin.js +89 -24
  96. package/lib/util/ArrayHelpers.js +18 -4
  97. package/lib/util/AsyncQueue.js +1 -1
  98. package/lib/util/extractUrlAndGlobal.js +3 -0
  99. package/lib/util/hash/xxhash64.js +2 -2
  100. package/lib/util/internalSerializables.js +11 -0
  101. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +9 -3
  102. package/lib/web/JsonpChunkLoadingRuntimeModule.js +3 -3
  103. package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +3 -11
  104. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +3 -2
  105. package/package.json +5 -12
  106. package/schemas/WebpackOptions.check.js +1 -1
  107. package/schemas/WebpackOptions.json +104 -1
  108. package/schemas/plugins/asset/AssetGeneratorOptions.check.js +1 -1
  109. package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.js +1 -1
  110. package/schemas/plugins/container/ContainerPlugin.check.js +1 -1
  111. package/schemas/plugins/container/ContainerPlugin.json +2 -1
  112. package/schemas/plugins/container/ContainerReferencePlugin.check.js +1 -1
  113. package/schemas/plugins/container/ContainerReferencePlugin.json +1 -0
  114. package/schemas/plugins/container/ExternalsType.check.js +1 -1
  115. package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
  116. package/schemas/plugins/container/ModuleFederationPlugin.json +3 -1
  117. package/schemas/plugins/css/CssGeneratorOptions.check.d.ts +7 -0
  118. package/schemas/plugins/css/CssGeneratorOptions.check.js +6 -0
  119. package/schemas/plugins/css/CssGeneratorOptions.json +3 -0
  120. package/schemas/plugins/css/CssParserOptions.check.d.ts +7 -0
  121. package/schemas/plugins/css/CssParserOptions.check.js +6 -0
  122. package/schemas/plugins/css/CssParserOptions.json +3 -0
  123. package/types.d.ts +284 -58
@@ -0,0 +1,148 @@
1
+ /*
2
+ MIT License http://www.opensource.org/licenses/mit-license.php
3
+ Author Tobias Koppers @sokra
4
+ */
5
+
6
+ "use strict";
7
+
8
+ const { RawSource } = require("webpack-sources");
9
+ const Module = require("../Module");
10
+ const RuntimeGlobals = require("../RuntimeGlobals");
11
+ const makeSerializable = require("../util/makeSerializable");
12
+
13
+ /** @typedef {import("../../declarations/WebpackOptions").WebpackOptionsNormalized} WebpackOptions */
14
+ /** @typedef {import("../Compilation")} Compilation */
15
+ /** @typedef {import("../Dependency").UpdateHashContext} UpdateHashContext */
16
+ /** @typedef {import("../Module").CodeGenerationContext} CodeGenerationContext */
17
+ /** @typedef {import("../Module").CodeGenerationResult} CodeGenerationResult */
18
+ /** @typedef {import("../Module").NeedBuildContext} NeedBuildContext */
19
+ /** @typedef {import("../RequestShortener")} RequestShortener */
20
+ /** @typedef {import("../ResolverFactory").ResolverWithOptions} ResolverWithOptions */
21
+ /** @typedef {import("../WebpackError")} WebpackError */
22
+ /** @typedef {import("../util/Hash")} Hash */
23
+ /** @typedef {import("../util/fs").InputFileSystem} InputFileSystem */
24
+
25
+ const TYPES = new Set(["javascript"]);
26
+
27
+ class RawDataUrlModule extends Module {
28
+ /**
29
+ * @param {string} url raw url
30
+ * @param {string} identifier unique identifier
31
+ * @param {string=} readableIdentifier readable identifier
32
+ */
33
+ constructor(url, identifier, readableIdentifier) {
34
+ super("asset/raw-data-url", null);
35
+ this.url = url;
36
+ this.urlBuffer = url ? Buffer.from(url) : undefined;
37
+ this.identifierStr = identifier || this.url;
38
+ this.readableIdentifierStr = readableIdentifier || this.identifierStr;
39
+ }
40
+
41
+ /**
42
+ * @returns {Set<string>} types available (do not mutate)
43
+ */
44
+ getSourceTypes() {
45
+ return TYPES;
46
+ }
47
+
48
+ /**
49
+ * @returns {string} a unique identifier of the module
50
+ */
51
+ identifier() {
52
+ return this.identifierStr;
53
+ }
54
+
55
+ /**
56
+ * @param {string=} type the source type for which the size should be estimated
57
+ * @returns {number} the estimated size of the module (must be non-zero)
58
+ */
59
+ size(type) {
60
+ if (this.url === undefined) this.url = this.urlBuffer.toString();
61
+ return Math.max(1, this.url.length);
62
+ }
63
+
64
+ /**
65
+ * @param {RequestShortener} requestShortener the request shortener
66
+ * @returns {string} a user readable identifier of the module
67
+ */
68
+ readableIdentifier(requestShortener) {
69
+ return requestShortener.shorten(this.readableIdentifierStr);
70
+ }
71
+
72
+ /**
73
+ * @param {NeedBuildContext} context context info
74
+ * @param {function((WebpackError | null)=, boolean=): void} callback callback function, returns true, if the module needs a rebuild
75
+ * @returns {void}
76
+ */
77
+ needBuild(context, callback) {
78
+ return callback(null, !this.buildMeta);
79
+ }
80
+
81
+ /**
82
+ * @param {WebpackOptions} options webpack options
83
+ * @param {Compilation} compilation the compilation
84
+ * @param {ResolverWithOptions} resolver the resolver
85
+ * @param {InputFileSystem} fs the file system
86
+ * @param {function(WebpackError=): void} callback callback function
87
+ * @returns {void}
88
+ */
89
+ build(options, compilation, resolver, fs, callback) {
90
+ this.buildMeta = {};
91
+ this.buildInfo = {
92
+ cacheable: true
93
+ };
94
+ callback();
95
+ }
96
+
97
+ /**
98
+ * @param {CodeGenerationContext} context context for code generation
99
+ * @returns {CodeGenerationResult} result
100
+ */
101
+ codeGeneration(context) {
102
+ if (this.url === undefined) this.url = this.urlBuffer.toString();
103
+ const sources = new Map();
104
+ sources.set(
105
+ "javascript",
106
+ new RawSource(`module.exports = ${JSON.stringify(this.url)};`)
107
+ );
108
+ const data = new Map();
109
+ data.set("url", this.urlBuffer);
110
+ const runtimeRequirements = new Set();
111
+ runtimeRequirements.add(RuntimeGlobals.module);
112
+ return { sources, runtimeRequirements, data };
113
+ }
114
+
115
+ /**
116
+ * @param {Hash} hash the hash used to track dependencies
117
+ * @param {UpdateHashContext} context context
118
+ * @returns {void}
119
+ */
120
+ updateHash(hash, context) {
121
+ hash.update(this.urlBuffer);
122
+ super.updateHash(hash, context);
123
+ }
124
+
125
+ serialize(context) {
126
+ const { write } = context;
127
+
128
+ write(this.urlBuffer);
129
+ write(this.identifierStr);
130
+ write(this.readableIdentifierStr);
131
+
132
+ super.serialize(context);
133
+ }
134
+
135
+ deserialize(context) {
136
+ const { read } = context;
137
+
138
+ this.urlBuffer = read();
139
+ this.identifierStr = read();
140
+ this.readableIdentifierStr = read();
141
+
142
+ super.deserialize(context);
143
+ }
144
+ }
145
+
146
+ makeSerializable(RawDataUrlModule, "webpack/lib/asset/RawDataUrlModule");
147
+
148
+ module.exports = RawDataUrlModule;
@@ -30,8 +30,8 @@ class AwaitDependenciesInitFragment extends InitFragment {
30
30
  }
31
31
 
32
32
  merge(other) {
33
- const promises = new Set(this.promises);
34
- for (const p of other.promises) {
33
+ const promises = new Set(other.promises);
34
+ for (const p of this.promises) {
35
35
  promises.add(p);
36
36
  }
37
37
  return new AwaitDependenciesInitFragment(promises);
@@ -51,7 +51,7 @@ class AwaitDependenciesInitFragment extends InitFragment {
51
51
  for (const p of promises) {
52
52
  return Template.asString([
53
53
  `var __webpack_async_dependencies__ = __webpack_handle_async_dependencies__([${p}]);`,
54
- `${p} = (__webpack_async_dependencies__.then ? await __webpack_async_dependencies__ : __webpack_async_dependencies__)[0];`,
54
+ `${p} = (__webpack_async_dependencies__.then ? (await __webpack_async_dependencies__)() : __webpack_async_dependencies__)[0];`,
55
55
  ""
56
56
  ]);
57
57
  }
@@ -60,7 +60,7 @@ class AwaitDependenciesInitFragment extends InitFragment {
60
60
  // TODO check if destructuring is supported
61
61
  return Template.asString([
62
62
  `var __webpack_async_dependencies__ = __webpack_handle_async_dependencies__([${sepPromises}]);`,
63
- `([${sepPromises}] = __webpack_async_dependencies__.then ? await __webpack_async_dependencies__ : __webpack_async_dependencies__);`,
63
+ `([${sepPromises}] = __webpack_async_dependencies__.then ? (await __webpack_async_dependencies__)() : __webpack_async_dependencies__);`,
64
64
  ""
65
65
  ]);
66
66
  }
@@ -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 = (
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: [],
@@ -274,7 +274,44 @@ const resolve = browsers => {
274
274
  // kaios: Unknown support
275
275
  node: [12, 0]
276
276
  }),
277
-
277
+ optionalChaining: rawChecker({
278
+ chrome: 80,
279
+ and_chr: 80,
280
+ edge: 80,
281
+ firefox: 74,
282
+ and_ff: 79,
283
+ // ie: Not supported,
284
+ opera: 67,
285
+ op_mob: 64,
286
+ safari: [13, 1],
287
+ ios_saf: [13, 4],
288
+ samsung: 13,
289
+ android: 80,
290
+ // and_qq: Not supported
291
+ // baidu: Not supported
292
+ // and_uc: Not supported
293
+ // kaios: Not supported
294
+ node: 14
295
+ }),
296
+ templateLiteral: rawChecker({
297
+ chrome: 41,
298
+ and_chr: 41,
299
+ edge: 13,
300
+ firefox: 34,
301
+ and_ff: 34,
302
+ // ie: Not supported,
303
+ opera: 29,
304
+ op_mob: 64,
305
+ safari: [9, 1],
306
+ ios_saf: 9,
307
+ samsung: 4,
308
+ android: 41,
309
+ and_qq: [10, 4],
310
+ baidu: [7, 12],
311
+ and_uc: [12, 12],
312
+ kaios: [2, 5],
313
+ node: 4
314
+ }),
278
315
  browser: browserProperty,
279
316
  electron: false,
280
317
  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
 
@@ -184,6 +189,7 @@ const applyWebpackOptionsDefaults = options => {
184
189
  cache,
185
190
  syncWebAssembly: options.experiments.syncWebAssembly,
186
191
  asyncWebAssembly: options.experiments.asyncWebAssembly,
192
+ css: options.experiments.css,
187
193
  futureDefaults
188
194
  });
189
195
 
@@ -239,6 +245,7 @@ const applyWebpackOptionsDefaults = options => {
239
245
  applyOptimizationDefaults(options.optimization, {
240
246
  development,
241
247
  production,
248
+ css: options.experiments.css,
242
249
  records: !!(options.recordsInputPath || options.recordsOutputPath)
243
250
  });
244
251
 
@@ -263,9 +270,13 @@ const applyWebpackOptionsDefaults = options => {
263
270
  * @param {Object} options options
264
271
  * @param {boolean} options.production is production
265
272
  * @param {boolean} options.development is development mode
273
+ * @param {TargetProperties | false} options.targetProperties target properties
266
274
  * @returns {void}
267
275
  */
268
- const applyExperimentsDefaults = (experiments, { production, development }) => {
276
+ const applyExperimentsDefaults = (
277
+ experiments,
278
+ { production, development, targetProperties }
279
+ ) => {
269
280
  D(experiments, "futureDefaults", false);
270
281
  D(experiments, "backCompat", !experiments.futureDefaults);
271
282
  D(experiments, "topLevelAwait", experiments.futureDefaults);
@@ -276,11 +287,20 @@ const applyExperimentsDefaults = (experiments, { production, development }) => {
276
287
  D(experiments, "lazyCompilation", undefined);
277
288
  D(experiments, "buildHttp", undefined);
278
289
  D(experiments, "cacheUnaffected", experiments.futureDefaults);
290
+ F(experiments, "css", () => (experiments.futureDefaults ? {} : undefined));
279
291
 
280
292
  if (typeof experiments.buildHttp === "object") {
281
293
  D(experiments.buildHttp, "frozen", production);
282
294
  D(experiments.buildHttp, "upgrade", false);
283
295
  }
296
+
297
+ if (typeof experiments.css === "object") {
298
+ D(
299
+ experiments.css,
300
+ "exportsOnly",
301
+ !targetProperties || !targetProperties.document
302
+ );
303
+ }
284
304
  };
285
305
 
286
306
  /**
@@ -449,6 +469,7 @@ const applyJavascriptParserOptionsDefaults = (
449
469
  D(parserOptions, "wrappedContextRecursive", true);
450
470
  D(parserOptions, "wrappedContextCritical", false);
451
471
  D(parserOptions, "strictThisContextOnImports", false);
472
+ D(parserOptions, "importMeta", true);
452
473
  if (futureDefaults) D(parserOptions, "exportsPresence", "error");
453
474
  };
454
475
 
@@ -458,12 +479,13 @@ const applyJavascriptParserOptionsDefaults = (
458
479
  * @param {boolean} options.cache is caching enabled
459
480
  * @param {boolean} options.syncWebAssembly is syncWebAssembly enabled
460
481
  * @param {boolean} options.asyncWebAssembly is asyncWebAssembly enabled
482
+ * @param {CssExperimentOptions} options.css is css enabled
461
483
  * @param {boolean} options.futureDefaults is future defaults enabled
462
484
  * @returns {void}
463
485
  */
464
486
  const applyModuleDefaults = (
465
487
  module,
466
- { cache, syncWebAssembly, asyncWebAssembly, futureDefaults }
488
+ { cache, syncWebAssembly, asyncWebAssembly, css, futureDefaults }
467
489
  ) => {
468
490
  if (cache) {
469
491
  D(module, "unsafeCache", module => {
@@ -587,6 +609,41 @@ const applyModuleDefaults = (
587
609
  ...wasm
588
610
  });
589
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
+ }
590
647
  rules.push(
591
648
  {
592
649
  dependency: "url",
@@ -692,6 +749,20 @@ const applyOutputDefaults = (
692
749
  }
693
750
  return output.module ? "[id].mjs" : "[id].js";
694
751
  });
752
+ F(output, "cssFilename", () => {
753
+ const filename = output.filename;
754
+ if (typeof filename !== "function") {
755
+ return filename.replace(/\.[mc]?js(\?|$)/, ".css$1");
756
+ }
757
+ return "[id].css";
758
+ });
759
+ F(output, "cssChunkFilename", () => {
760
+ const chunkFilename = output.chunkFilename;
761
+ if (typeof chunkFilename !== "function") {
762
+ return chunkFilename.replace(/\.[mc]?js(\?|$)/, ".css$1");
763
+ }
764
+ return "[id].css";
765
+ });
695
766
  D(output, "assetModuleFilename", "[hash][ext][query]");
696
767
  D(output, "webassemblyModuleFilename", "[hash].module.wasm");
697
768
  D(output, "compareBeforeEmit", true);
@@ -832,7 +903,7 @@ const applyOutputDefaults = (
832
903
  D(output, "chunkLoadTimeout", 120000);
833
904
  D(output, "hashFunction", futureDefaults ? "xxhash64" : "md4");
834
905
  D(output, "hashDigest", "hex");
835
- D(output, "hashDigestLength", 20);
906
+ D(output, "hashDigestLength", futureDefaults ? 16 : 20);
836
907
  D(output, "strictModuleExceptionHandling", false);
837
908
 
838
909
  const optimistic = v => v || v === undefined;
@@ -1030,12 +1101,13 @@ const applyPerformanceDefaults = (performance, { production }) => {
1030
1101
  * @param {Object} options options
1031
1102
  * @param {boolean} options.production is production
1032
1103
  * @param {boolean} options.development is development
1104
+ * @param {CssExperimentOptions} options.css is css enabled
1033
1105
  * @param {boolean} options.records using records
1034
1106
  * @returns {void}
1035
1107
  */
1036
1108
  const applyOptimizationDefaults = (
1037
1109
  optimization,
1038
- { production, development, records }
1110
+ { production, development, css, records }
1039
1111
  ) => {
1040
1112
  D(optimization, "removeAvailableModules", false);
1041
1113
  D(optimization, "removeEmptyChunks", true);
@@ -1086,7 +1158,9 @@ const applyOptimizationDefaults = (
1086
1158
  });
1087
1159
  const { splitChunks } = optimization;
1088
1160
  if (splitChunks) {
1089
- A(splitChunks, "defaultSizeTypes", () => ["javascript", "unknown"]);
1161
+ A(splitChunks, "defaultSizeTypes", () =>
1162
+ css ? ["javascript", "css", "unknown"] : ["javascript", "unknown"]
1163
+ );
1090
1164
  D(splitChunks, "hidePathInfo", production);
1091
1165
  D(splitChunks, "chunks", "async");
1092
1166
  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,
@@ -297,6 +300,8 @@ const getNormalizedWebpackOptions = config => {
297
300
  chunkLoading: output.chunkLoading,
298
301
  chunkLoadingGlobal: output.chunkLoadingGlobal,
299
302
  chunkLoadTimeout: output.chunkLoadTimeout,
303
+ cssFilename: output.cssFilename,
304
+ cssChunkFilename: output.cssChunkFilename,
300
305
  clean: output.clean,
301
306
  compareBeforeEmit: output.compareBeforeEmit,
302
307
  crossOriginLoading: output.crossOriginLoading,
@@ -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,
@@ -79,12 +79,14 @@ class ContainerEntryModule extends Module {
79
79
  * @returns {string | null} an identifier for library inclusion
80
80
  */
81
81
  libIdent(options) {
82
- return `webpack/container/entry/${this._name}`;
82
+ return `${this.layer ? `(${this.layer})/` : ""}webpack/container/entry/${
83
+ this._name
84
+ }`;
83
85
  }
84
86
 
85
87
  /**
86
88
  * @param {NeedBuildContext} context context info
87
- * @param {function(WebpackError=, boolean=): void} callback callback function, returns true, if the module needs a rebuild
89
+ * @param {function((WebpackError | null)=, boolean=): void} callback callback function, returns true, if the module needs a rebuild
88
90
  * @returns {void}
89
91
  */
90
92
  needBuild(context, callback) {
@@ -220,10 +222,8 @@ class ContainerEntryModule extends Module {
220
222
  ])};`,
221
223
  `var init = ${runtimeTemplate.basicFunction("shareScope, initScope", [
222
224
  `if (!${RuntimeGlobals.shareScopeMap}) return;`,
223
- `var oldScope = ${RuntimeGlobals.shareScopeMap}[${JSON.stringify(
224
- this._shareScope
225
- )}];`,
226
225
  `var name = ${JSON.stringify(this._shareScope)}`,
226
+ `var oldScope = ${RuntimeGlobals.shareScopeMap}[name];`,
227
227
  `if(oldScope && oldScope !== shareScope) throw new Error("Container initialization failed as it has already been initialized with a different share scope");`,
228
228
  `${RuntimeGlobals.shareScopeMap}[name] = shareScope;`,
229
229
  `return ${RuntimeGlobals.initializeSharing}(name, initScope);`
@@ -60,9 +60,9 @@ class FallbackModule extends Module {
60
60
  * @returns {string | null} an identifier for library inclusion
61
61
  */
62
62
  libIdent(options) {
63
- return `webpack/container/fallback/${this.requests[0]}/and ${
64
- this.requests.length - 1
65
- } more`;
63
+ return `${this.layer ? `(${this.layer})/` : ""}webpack/container/fallback/${
64
+ this.requests[0]
65
+ }/and ${this.requests.length - 1} more`;
66
66
  }
67
67
 
68
68
  /**
@@ -76,7 +76,7 @@ class FallbackModule extends Module {
76
76
 
77
77
  /**
78
78
  * @param {NeedBuildContext} context context info
79
- * @param {function(WebpackError=, boolean=): void} callback callback function, returns true, if the module needs a rebuild
79
+ * @param {function((WebpackError | null)=, boolean=): void} callback callback function, returns true, if the module needs a rebuild
80
80
  * @returns {void}
81
81
  */
82
82
  needBuild(context, callback) {
@@ -67,12 +67,14 @@ class RemoteModule extends Module {
67
67
  * @returns {string | null} an identifier for library inclusion
68
68
  */
69
69
  libIdent(options) {
70
- return `webpack/container/remote/${this.request}`;
70
+ return `${this.layer ? `(${this.layer})/` : ""}webpack/container/remote/${
71
+ this.request
72
+ }`;
71
73
  }
72
74
 
73
75
  /**
74
76
  * @param {NeedBuildContext} context context info
75
- * @param {function(WebpackError=, boolean=): void} callback callback function, returns true, if the module needs a rebuild
77
+ * @param {function((WebpackError | null)=, boolean=): void} callback callback function, returns true, if the module needs a rebuild
76
78
  * @returns {void}
77
79
  */
78
80
  needBuild(context, callback) {