webpack 5.64.2 → 5.66.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 (84) hide show
  1. package/lib/CacheFacade.js +2 -9
  2. package/lib/Chunk.js +2 -0
  3. package/lib/Compilation.js +79 -38
  4. package/lib/Dependency.js +10 -0
  5. package/lib/DependencyTemplate.js +9 -0
  6. package/lib/ExternalModule.js +93 -53
  7. package/lib/Generator.js +2 -0
  8. package/lib/Module.js +24 -1
  9. package/lib/ModuleFilenameHelpers.js +5 -1
  10. package/lib/NormalModule.js +3 -1
  11. package/lib/RuntimeGlobals.js +11 -1
  12. package/lib/RuntimePlugin.js +25 -0
  13. package/lib/RuntimeTemplate.js +113 -2
  14. package/lib/Template.js +2 -1
  15. package/lib/WatchIgnorePlugin.js +14 -1
  16. package/lib/Watching.js +32 -18
  17. package/lib/WebpackOptionsApply.js +43 -2
  18. package/lib/asset/AssetGenerator.js +10 -7
  19. package/lib/asset/RawDataUrlModule.js +145 -0
  20. package/lib/config/browserslistTargetHandler.js +38 -1
  21. package/lib/config/defaults.js +60 -4
  22. package/lib/config/target.js +10 -0
  23. package/lib/container/ContainerEntryModule.js +4 -3
  24. package/lib/css/CssGenerator.js +106 -0
  25. package/lib/css/CssLoadingRuntimeModule.js +393 -0
  26. package/lib/css/CssModulesPlugin.js +444 -0
  27. package/lib/css/CssParser.js +618 -0
  28. package/lib/css/walkCssTokens.js +659 -0
  29. package/lib/dependencies/CssExportDependency.js +85 -0
  30. package/lib/dependencies/CssImportDependency.js +75 -0
  31. package/lib/dependencies/CssLocalIdentifierDependency.js +119 -0
  32. package/lib/dependencies/CssSelfLocalIdentifierDependency.js +101 -0
  33. package/lib/dependencies/CssUrlDependency.js +132 -0
  34. package/lib/dependencies/URLDependency.js +3 -8
  35. package/lib/esm/ModuleChunkFormatPlugin.js +74 -49
  36. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +1 -1
  37. package/lib/hmr/lazyCompilationBackend.js +3 -1
  38. package/lib/index.js +3 -0
  39. package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +2 -2
  40. package/lib/javascript/ChunkHelpers.js +33 -0
  41. package/lib/javascript/JavascriptGenerator.js +1 -0
  42. package/lib/javascript/JavascriptParser.js +16 -8
  43. package/lib/javascript/StartupHelpers.js +4 -28
  44. package/lib/library/AssignLibraryPlugin.js +31 -13
  45. package/lib/library/EnableLibraryPlugin.js +11 -0
  46. package/lib/node/NodeWatchFileSystem.js +85 -31
  47. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +1 -1
  48. package/lib/node/RequireChunkLoadingRuntimeModule.js +1 -1
  49. package/lib/optimize/ConcatenatedModule.js +10 -4
  50. package/lib/sharing/ConsumeSharedModule.js +4 -0
  51. package/lib/sharing/ConsumeSharedRuntimeModule.js +25 -4
  52. package/lib/stats/DefaultStatsPrinterPlugin.js +1 -1
  53. package/lib/util/create-schema-validation.js +9 -2
  54. package/lib/util/extractUrlAndGlobal.js +3 -0
  55. package/lib/util/fs.js +10 -0
  56. package/lib/util/hash/xxhash64.js +2 -2
  57. package/lib/util/internalSerializables.js +11 -0
  58. package/lib/web/JsonpChunkLoadingRuntimeModule.js +3 -3
  59. package/lib/webpack.js +9 -1
  60. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +3 -2
  61. package/package.json +4 -4
  62. package/schemas/WebpackOptions.check.js +1 -1
  63. package/schemas/WebpackOptions.json +63 -1
  64. package/schemas/plugins/DllReferencePlugin.check.js +1 -1
  65. package/schemas/plugins/HashedModuleIdsPlugin.check.js +1 -1
  66. package/schemas/plugins/ProgressPlugin.check.js +1 -1
  67. package/schemas/plugins/asset/AssetParserOptions.check.js +1 -1
  68. package/schemas/plugins/container/ContainerPlugin.check.js +1 -1
  69. package/schemas/plugins/container/ContainerPlugin.json +2 -1
  70. package/schemas/plugins/container/ContainerReferencePlugin.check.js +1 -1
  71. package/schemas/plugins/container/ContainerReferencePlugin.json +1 -0
  72. package/schemas/plugins/container/ExternalsType.check.js +1 -1
  73. package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
  74. package/schemas/plugins/container/ModuleFederationPlugin.json +3 -1
  75. package/schemas/plugins/css/CssGeneratorOptions.check.d.ts +7 -0
  76. package/schemas/plugins/css/CssGeneratorOptions.check.js +6 -0
  77. package/schemas/plugins/css/CssGeneratorOptions.json +3 -0
  78. package/schemas/plugins/css/CssParserOptions.check.d.ts +7 -0
  79. package/schemas/plugins/css/CssParserOptions.check.js +6 -0
  80. package/schemas/plugins/css/CssParserOptions.json +3 -0
  81. package/schemas/plugins/optimize/AggressiveSplittingPlugin.check.js +1 -1
  82. package/schemas/plugins/optimize/LimitChunkCountPlugin.check.js +1 -1
  83. package/schemas/plugins/optimize/MinChunkSizePlugin.check.js +1 -1
  84. package/types.d.ts +147 -21
@@ -184,6 +184,7 @@ const applyWebpackOptionsDefaults = options => {
184
184
  cache,
185
185
  syncWebAssembly: options.experiments.syncWebAssembly,
186
186
  asyncWebAssembly: options.experiments.asyncWebAssembly,
187
+ css: options.experiments.css,
187
188
  futureDefaults
188
189
  });
189
190
 
@@ -239,6 +240,7 @@ const applyWebpackOptionsDefaults = options => {
239
240
  applyOptimizationDefaults(options.optimization, {
240
241
  development,
241
242
  production,
243
+ css: options.experiments.css,
242
244
  records: !!(options.recordsInputPath || options.recordsOutputPath)
243
245
  });
244
246
 
@@ -276,6 +278,7 @@ const applyExperimentsDefaults = (experiments, { production, development }) => {
276
278
  D(experiments, "lazyCompilation", undefined);
277
279
  D(experiments, "buildHttp", undefined);
278
280
  D(experiments, "cacheUnaffected", experiments.futureDefaults);
281
+ D(experiments, "css", experiments.futureDefaults);
279
282
 
280
283
  if (typeof experiments.buildHttp === "object") {
281
284
  D(experiments.buildHttp, "frozen", production);
@@ -458,12 +461,13 @@ const applyJavascriptParserOptionsDefaults = (
458
461
  * @param {boolean} options.cache is caching enabled
459
462
  * @param {boolean} options.syncWebAssembly is syncWebAssembly enabled
460
463
  * @param {boolean} options.asyncWebAssembly is asyncWebAssembly enabled
464
+ * @param {boolean} options.css is css enabled
461
465
  * @param {boolean} options.futureDefaults is future defaults enabled
462
466
  * @returns {void}
463
467
  */
464
468
  const applyModuleDefaults = (
465
469
  module,
466
- { cache, syncWebAssembly, asyncWebAssembly, futureDefaults }
470
+ { cache, syncWebAssembly, asyncWebAssembly, css, futureDefaults }
467
471
  ) => {
468
472
  if (cache) {
469
473
  D(module, "unsafeCache", module => {
@@ -587,6 +591,41 @@ const applyModuleDefaults = (
587
591
  ...wasm
588
592
  });
589
593
  }
594
+ if (css) {
595
+ const cssRule = {
596
+ type: "css",
597
+ resolve: {
598
+ fullySpecified: true,
599
+ preferRelative: true
600
+ }
601
+ };
602
+ const cssModulesRule = {
603
+ type: "css/module",
604
+ resolve: {
605
+ fullySpecified: true
606
+ }
607
+ };
608
+ rules.push({
609
+ test: /\.css$/i,
610
+ oneOf: [
611
+ {
612
+ test: /\.module\.css$/i,
613
+ ...cssModulesRule
614
+ },
615
+ {
616
+ ...cssRule
617
+ }
618
+ ]
619
+ });
620
+ rules.push({
621
+ mimetype: "text/css+module",
622
+ ...cssModulesRule
623
+ });
624
+ rules.push({
625
+ mimetype: "text/css",
626
+ ...cssRule
627
+ });
628
+ }
590
629
  rules.push(
591
630
  {
592
631
  dependency: "url",
@@ -692,6 +731,20 @@ const applyOutputDefaults = (
692
731
  }
693
732
  return output.module ? "[id].mjs" : "[id].js";
694
733
  });
734
+ F(output, "cssFilename", () => {
735
+ const filename = output.filename;
736
+ if (typeof filename !== "function") {
737
+ return filename.replace(/\.[mc]?js(\?|$)/, ".css$1");
738
+ }
739
+ return "[id].css";
740
+ });
741
+ F(output, "cssChunkFilename", () => {
742
+ const chunkFilename = output.chunkFilename;
743
+ if (typeof chunkFilename !== "function") {
744
+ return chunkFilename.replace(/\.[mc]?js(\?|$)/, ".css$1");
745
+ }
746
+ return "[id].css";
747
+ });
695
748
  D(output, "assetModuleFilename", "[hash][ext][query]");
696
749
  D(output, "webassemblyModuleFilename", "[hash].module.wasm");
697
750
  D(output, "compareBeforeEmit", true);
@@ -832,7 +885,7 @@ const applyOutputDefaults = (
832
885
  D(output, "chunkLoadTimeout", 120000);
833
886
  D(output, "hashFunction", futureDefaults ? "xxhash64" : "md4");
834
887
  D(output, "hashDigest", "hex");
835
- D(output, "hashDigestLength", 20);
888
+ D(output, "hashDigestLength", futureDefaults ? 16 : 20);
836
889
  D(output, "strictModuleExceptionHandling", false);
837
890
 
838
891
  const optimistic = v => v || v === undefined;
@@ -1030,12 +1083,13 @@ const applyPerformanceDefaults = (performance, { production }) => {
1030
1083
  * @param {Object} options options
1031
1084
  * @param {boolean} options.production is production
1032
1085
  * @param {boolean} options.development is development
1086
+ * @param {boolean} options.css is css enabled
1033
1087
  * @param {boolean} options.records using records
1034
1088
  * @returns {void}
1035
1089
  */
1036
1090
  const applyOptimizationDefaults = (
1037
1091
  optimization,
1038
- { production, development, records }
1092
+ { production, development, css, records }
1039
1093
  ) => {
1040
1094
  D(optimization, "removeAvailableModules", false);
1041
1095
  D(optimization, "removeEmptyChunks", true);
@@ -1086,7 +1140,9 @@ const applyOptimizationDefaults = (
1086
1140
  });
1087
1141
  const { splitChunks } = optimization;
1088
1142
  if (splitChunks) {
1089
- A(splitChunks, "defaultSizeTypes", () => ["javascript", "unknown"]);
1143
+ A(splitChunks, "defaultSizeTypes", () =>
1144
+ css ? ["javascript", "css", "unknown"] : ["javascript", "unknown"]
1145
+ );
1090
1146
  D(splitChunks, "hidePathInfo", production);
1091
1147
  D(splitChunks, "chunks", "async");
1092
1148
  D(splitChunks, "usedExports", optimization.usedExports === true);
@@ -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,
@@ -10,6 +10,7 @@ const AsyncDependenciesBlock = require("../AsyncDependenciesBlock");
10
10
  const Module = require("../Module");
11
11
  const RuntimeGlobals = require("../RuntimeGlobals");
12
12
  const Template = require("../Template");
13
+ const StaticExportsDependency = require("../dependencies/StaticExportsDependency");
13
14
  const makeSerializable = require("../util/makeSerializable");
14
15
  const ContainerExposedDependency = require("./ContainerExposedDependency");
15
16
 
@@ -104,6 +105,7 @@ class ContainerEntryModule extends Module {
104
105
  strict: true,
105
106
  topLevelDeclarations: new Set(["moduleMap", "get", "init"])
106
107
  };
108
+ this.buildMeta.exportsType = "namespace";
107
109
 
108
110
  this.clearDependenciesAndBlocks();
109
111
 
@@ -127,6 +129,7 @@ class ContainerEntryModule extends Module {
127
129
  }
128
130
  this.addBlock(block);
129
131
  }
132
+ this.addDependency(new StaticExportsDependency(["get", "init"], false));
130
133
 
131
134
  callback();
132
135
  }
@@ -217,10 +220,8 @@ class ContainerEntryModule extends Module {
217
220
  ])};`,
218
221
  `var init = ${runtimeTemplate.basicFunction("shareScope, initScope", [
219
222
  `if (!${RuntimeGlobals.shareScopeMap}) return;`,
220
- `var oldScope = ${RuntimeGlobals.shareScopeMap}[${JSON.stringify(
221
- this._shareScope
222
- )}];`,
223
223
  `var name = ${JSON.stringify(this._shareScope)}`,
224
+ `var oldScope = ${RuntimeGlobals.shareScopeMap}[name];`,
224
225
  `if(oldScope && oldScope !== shareScope) throw new Error("Container initialization failed as it has already been initialized with a different share scope");`,
225
226
  `${RuntimeGlobals.shareScopeMap}[name] = shareScope;`,
226
227
  `return ${RuntimeGlobals.initializeSharing}(name, initScope);`
@@ -0,0 +1,106 @@
1
+ /*
2
+ MIT License http://www.opensource.org/licenses/mit-license.php
3
+ Author Sergey Melyukov @smelukov
4
+ */
5
+
6
+ "use strict";
7
+
8
+ const { ReplaceSource } = require("webpack-sources");
9
+ const Generator = require("../Generator");
10
+ const InitFragment = require("../InitFragment");
11
+
12
+ /** @typedef {import("webpack-sources").Source} Source */
13
+ /** @typedef {import("../Dependency")} Dependency */
14
+ /** @typedef {import("../Generator").GenerateContext} GenerateContext */
15
+ /** @typedef {import("../Generator").UpdateHashContext} UpdateHashContext */
16
+ /** @typedef {import("../NormalModule")} NormalModule */
17
+ /** @typedef {import("../util/Hash")} Hash */
18
+
19
+ const TYPES = new Set(["css"]);
20
+
21
+ class CssGenerator extends Generator {
22
+ constructor() {
23
+ super();
24
+ }
25
+
26
+ /**
27
+ * @param {NormalModule} module module for which the code should be generated
28
+ * @param {GenerateContext} generateContext context for generate
29
+ * @returns {Source} generated code
30
+ */
31
+ generate(module, generateContext) {
32
+ const originalSource = module.originalSource();
33
+ const source = new ReplaceSource(originalSource);
34
+ const initFragments = [];
35
+ const cssExports = new Map();
36
+
37
+ const templateContext = {
38
+ runtimeTemplate: generateContext.runtimeTemplate,
39
+ dependencyTemplates: generateContext.dependencyTemplates,
40
+ moduleGraph: generateContext.moduleGraph,
41
+ chunkGraph: generateContext.chunkGraph,
42
+ module,
43
+ runtime: generateContext.runtime,
44
+ runtimeRequirements: generateContext.runtimeRequirements,
45
+ concatenationScope: generateContext.concatenationScope,
46
+ codeGenerationResults: generateContext.codeGenerationResults,
47
+ initFragments,
48
+ cssExports
49
+ };
50
+
51
+ const handleDependency = dependency => {
52
+ const constructor = /** @type {new (...args: any[]) => Dependency} */ (
53
+ dependency.constructor
54
+ );
55
+ const template = generateContext.dependencyTemplates.get(constructor);
56
+ if (!template) {
57
+ throw new Error(
58
+ "No template for dependency: " + dependency.constructor.name
59
+ );
60
+ }
61
+
62
+ template.apply(dependency, source, templateContext);
63
+ };
64
+ module.dependencies.forEach(handleDependency);
65
+ if (module.presentationalDependencies !== undefined)
66
+ module.presentationalDependencies.forEach(handleDependency);
67
+
68
+ if (cssExports.size > 0) {
69
+ const data = generateContext.getData();
70
+ data.set("css-exports", cssExports);
71
+ }
72
+
73
+ return InitFragment.addToSource(source, initFragments, generateContext);
74
+ }
75
+
76
+ /**
77
+ * @param {NormalModule} module fresh module
78
+ * @returns {Set<string>} available types (do not mutate)
79
+ */
80
+ getTypes(module) {
81
+ return TYPES;
82
+ }
83
+
84
+ /**
85
+ * @param {NormalModule} module the module
86
+ * @param {string=} type source type
87
+ * @returns {number} estimate size of the module
88
+ */
89
+ getSize(module, type) {
90
+ const originalSource = module.originalSource();
91
+
92
+ if (!originalSource) {
93
+ return 0;
94
+ }
95
+
96
+ return originalSource.size();
97
+ }
98
+
99
+ /**
100
+ * @param {Hash} hash hash that will be modified
101
+ * @param {UpdateHashContext} updateHashContext context for updating hash
102
+ */
103
+ updateHash(hash, { module }) {}
104
+ }
105
+
106
+ module.exports = CssGenerator;