webpack 5.102.1 → 5.103.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 (118) hide show
  1. package/README.md +121 -134
  2. package/lib/CompatibilityPlugin.js +25 -2
  3. package/lib/Compilation.js +25 -2
  4. package/lib/ConcatenationScope.js +0 -15
  5. package/lib/CssModule.js +6 -1
  6. package/lib/DefinePlugin.js +11 -11
  7. package/lib/Dependency.js +8 -1
  8. package/lib/DependencyTemplate.js +1 -0
  9. package/lib/DotenvPlugin.js +457 -0
  10. package/lib/EnvironmentPlugin.js +19 -16
  11. package/lib/EvalSourceMapDevToolPlugin.js +16 -0
  12. package/lib/ExportsInfo.js +6 -2
  13. package/lib/ExternalModule.js +20 -28
  14. package/lib/ExternalModuleFactoryPlugin.js +10 -8
  15. package/lib/ExternalsPlugin.js +2 -1
  16. package/lib/ManifestPlugin.js +235 -0
  17. package/lib/Module.js +3 -0
  18. package/lib/ModuleGraph.js +2 -1
  19. package/lib/ModuleSourceTypesConstants.js +0 -6
  20. package/lib/MultiCompiler.js +1 -1
  21. package/lib/NodeStuffPlugin.js +419 -121
  22. package/lib/NormalModule.js +17 -16
  23. package/lib/RuntimeGlobals.js +22 -4
  24. package/lib/RuntimePlugin.js +27 -6
  25. package/lib/RuntimeTemplate.js +115 -56
  26. package/lib/SourceMapDevToolPlugin.js +20 -0
  27. package/lib/WebpackOptionsApply.js +33 -9
  28. package/lib/asset/AssetBytesGenerator.js +1 -1
  29. package/lib/asset/AssetGenerator.js +1 -2
  30. package/lib/asset/AssetSourceGenerator.js +1 -1
  31. package/lib/config/browserslistTargetHandler.js +5 -0
  32. package/lib/config/defaults.js +98 -18
  33. package/lib/config/normalization.js +2 -1
  34. package/lib/config/target.js +6 -0
  35. package/lib/css/CssGenerator.js +283 -57
  36. package/lib/css/CssLoadingRuntimeModule.js +2 -0
  37. package/lib/css/CssMergeStyleSheetsRuntimeModule.js +56 -0
  38. package/lib/css/CssModulesPlugin.js +84 -34
  39. package/lib/css/CssParser.js +1174 -667
  40. package/lib/css/walkCssTokens.js +97 -0
  41. package/lib/dependencies/CommonJsImportsParserPlugin.js +0 -9
  42. package/lib/dependencies/CommonJsPlugin.js +12 -0
  43. package/lib/dependencies/CssIcssExportDependency.js +247 -8
  44. package/lib/dependencies/CssIcssFromIdentifierDependency.js +124 -0
  45. package/lib/dependencies/CssIcssGlobalIdentifierDependency.js +48 -0
  46. package/lib/dependencies/CssIcssImportDependency.js +60 -54
  47. package/lib/dependencies/CssIcssLocalIdentifierDependency.js +61 -0
  48. package/lib/dependencies/{CssSelfLocalIdentifierDependency.js → CssIcssSelfLocalIdentifierDependency.js} +88 -10
  49. package/lib/dependencies/CssIcssSymbolDependency.js +31 -29
  50. package/lib/dependencies/CssImportDependency.js +15 -5
  51. package/lib/dependencies/ExternalModuleInitFragment.js +1 -1
  52. package/lib/dependencies/ExternalModuleInitFragmentDependency.js +95 -0
  53. package/lib/dependencies/HarmonyAcceptDependency.js +6 -1
  54. package/lib/dependencies/HarmonyAcceptImportDependency.js +2 -1
  55. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +12 -1
  56. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +32 -21
  57. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +12 -8
  58. package/lib/dependencies/HarmonyImportDependency.js +23 -27
  59. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +28 -69
  60. package/lib/dependencies/HarmonyImportSideEffectDependency.js +4 -3
  61. package/lib/dependencies/HarmonyImportSpecifierDependency.js +10 -8
  62. package/lib/dependencies/ImportDependency.js +8 -2
  63. package/lib/dependencies/ImportEagerDependency.js +6 -3
  64. package/lib/dependencies/ImportMetaPlugin.js +97 -9
  65. package/lib/dependencies/ImportParserPlugin.js +19 -21
  66. package/lib/dependencies/ImportPhase.js +121 -0
  67. package/lib/dependencies/ImportWeakDependency.js +6 -3
  68. package/lib/dependencies/ModuleDependency.js +5 -1
  69. package/lib/dependencies/ModuleHotAcceptDependency.js +1 -1
  70. package/lib/esm/ExportWebpackRequireRuntimeModule.js +1 -8
  71. package/lib/hmr/LazyCompilationPlugin.js +1 -0
  72. package/lib/ids/IdHelpers.js +4 -1
  73. package/lib/index.js +6 -0
  74. package/lib/javascript/ChunkHelpers.js +16 -5
  75. package/lib/javascript/JavascriptGenerator.js +101 -101
  76. package/lib/javascript/JavascriptModulesPlugin.js +23 -13
  77. package/lib/javascript/JavascriptParser.js +142 -38
  78. package/lib/json/JsonParser.js +7 -1
  79. package/lib/library/ModuleLibraryPlugin.js +0 -10
  80. package/lib/library/SystemLibraryPlugin.js +4 -0
  81. package/lib/library/UmdLibraryPlugin.js +1 -1
  82. package/lib/node/NodeTargetPlugin.js +9 -1
  83. package/lib/node/ReadFileCompileWasmPlugin.js +0 -2
  84. package/lib/optimize/ConcatenatedModule.js +161 -135
  85. package/lib/runtime/AsyncModuleRuntimeModule.js +28 -18
  86. package/lib/runtime/AutoPublicPathRuntimeModule.js +8 -3
  87. package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +89 -55
  88. package/lib/util/comparators.js +4 -3
  89. package/lib/util/internalSerializables.js +4 -4
  90. package/lib/util/jsonParseEvenBetterErrors.js +10 -0
  91. package/lib/wasm/EnableWasmLoadingPlugin.js +10 -4
  92. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +8 -5
  93. package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +8 -4
  94. package/lib/web/FetchCompileWasmPlugin.js +0 -2
  95. package/lib/webpack.js +85 -82
  96. package/module.d.ts +5 -0
  97. package/package.json +16 -14
  98. package/schemas/WebpackOptions.check.js +1 -1
  99. package/schemas/WebpackOptions.json +109 -27
  100. package/schemas/plugins/ManifestPlugin.check.d.ts +7 -0
  101. package/schemas/plugins/ManifestPlugin.check.js +6 -0
  102. package/schemas/plugins/ManifestPlugin.json +98 -0
  103. package/schemas/plugins/SourceMapDevToolPlugin.check.js +1 -1
  104. package/schemas/plugins/SourceMapDevToolPlugin.json +16 -3
  105. package/schemas/plugins/container/ContainerReferencePlugin.check.js +1 -1
  106. package/schemas/plugins/container/ContainerReferencePlugin.json +4 -1
  107. package/schemas/plugins/container/ExternalsType.check.js +1 -1
  108. package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
  109. package/schemas/plugins/container/ModuleFederationPlugin.json +4 -1
  110. package/schemas/plugins/css/CssAutoParserOptions.check.js +1 -1
  111. package/schemas/plugins/css/CssGlobalGeneratorOptions.check.js +1 -1
  112. package/schemas/plugins/css/CssGlobalParserOptions.check.js +1 -1
  113. package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +1 -1
  114. package/schemas/plugins/css/CssModuleParserOptions.check.js +1 -1
  115. package/schemas/plugins/css/CssParserOptions.check.js +1 -1
  116. package/schemas/plugins/json/JsonModulesPluginParser.check.js +1 -1
  117. package/types.d.ts +560 -293
  118. package/lib/dependencies/CssLocalIdentifierDependency.js +0 -250
@@ -1,250 +0,0 @@
1
- /*
2
- MIT License http://www.opensource.org/licenses/mit-license.php
3
- Author Ivan Kopeykin @vankop
4
- */
5
-
6
- "use strict";
7
-
8
- const { cssExportConvention } = require("../util/conventions");
9
- const createHash = require("../util/createHash");
10
- const { makePathsRelative } = require("../util/identifier");
11
- const makeSerializable = require("../util/makeSerializable");
12
- const memoize = require("../util/memoize");
13
- const NullDependency = require("./NullDependency");
14
-
15
- /** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
16
- /** @typedef {import("../../declarations/WebpackOptions").CssGeneratorExportsConvention} CssGeneratorExportsConvention */
17
- /** @typedef {import("../../declarations/WebpackOptions").CssGeneratorLocalIdentName} CssGeneratorLocalIdentName */
18
- /** @typedef {import("../ChunkGraph")} ChunkGraph */
19
- /** @typedef {import("../CssModule")} CssModule */
20
- /** @typedef {import("../Dependency")} Dependency */
21
- /** @typedef {import("../Dependency").ExportsSpec} ExportsSpec */
22
- /** @typedef {import("../Dependency").UpdateHashContext} UpdateHashContext */
23
- /** @typedef {import("../DependencyTemplate").CssDependencyTemplateContext} DependencyTemplateContext */
24
- /** @typedef {import("../ModuleGraph")} ModuleGraph */
25
- /** @typedef {import("../RuntimeTemplate")} RuntimeTemplate */
26
- /** @typedef {import("../css/CssGenerator")} CssGenerator */
27
- /** @typedef {import("../css/CssParser").Range} Range */
28
- /** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
29
- /** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
30
- /** @typedef {import("../util/Hash")} Hash */
31
-
32
- const getCssParser = memoize(() => require("../css/CssParser"));
33
-
34
- /**
35
- * @param {string} local css local
36
- * @param {CssModule} module module
37
- * @param {ChunkGraph} chunkGraph chunk graph
38
- * @param {RuntimeTemplate} runtimeTemplate runtime template
39
- * @returns {string} local ident
40
- */
41
- const getLocalIdent = (local, module, chunkGraph, runtimeTemplate) => {
42
- const generator = /** @type {CssGenerator} */ (module.generator);
43
- const localIdentName =
44
- /** @type {CssGeneratorLocalIdentName} */
45
- (generator.localIdentName);
46
- const relativeResourcePath = makePathsRelative(
47
- /** @type {string} */
48
- (module.context),
49
- /** @type {string} */
50
- (module.getResource()),
51
- runtimeTemplate.compilation.compiler.root
52
- );
53
- const { hashFunction, hashDigest, hashDigestLength, hashSalt, uniqueName } =
54
- runtimeTemplate.outputOptions;
55
- const hash = createHash(hashFunction);
56
-
57
- if (hashSalt) {
58
- hash.update(hashSalt);
59
- }
60
-
61
- hash.update(relativeResourcePath);
62
-
63
- if (!/\[local\]/.test(localIdentName)) {
64
- hash.update(local);
65
- }
66
-
67
- const localIdentHash = hash.digest(hashDigest).slice(0, hashDigestLength);
68
-
69
- return runtimeTemplate.compilation
70
- .getPath(localIdentName, {
71
- filename: relativeResourcePath,
72
- hash: localIdentHash,
73
- contentHash: localIdentHash,
74
- chunkGraph,
75
- module
76
- })
77
- .replace(/\[local\]/g, local)
78
- .replace(/\[uniqueName\]/g, /** @type {string} */ (uniqueName))
79
- .replace(/^((-?[0-9])|--)/, "_$1");
80
- };
81
-
82
- class CssLocalIdentifierDependency extends NullDependency {
83
- /**
84
- * @param {string} name name
85
- * @param {Range} range range
86
- * @param {string=} prefix prefix
87
- */
88
- constructor(name, range, prefix = "") {
89
- super();
90
- this.name = name;
91
- this.range = range;
92
- this.prefix = prefix;
93
- this._conventionNames = undefined;
94
- this._hashUpdate = undefined;
95
- }
96
-
97
- get type() {
98
- return "css local identifier";
99
- }
100
-
101
- /**
102
- * @param {string} name export name
103
- * @param {CssGeneratorExportsConvention} convention convention of the export name
104
- * @returns {string[]} convention results
105
- */
106
- getExportsConventionNames(name, convention) {
107
- if (this._conventionNames) {
108
- return this._conventionNames;
109
- }
110
- this._conventionNames = cssExportConvention(this.name, convention);
111
- return this._conventionNames;
112
- }
113
-
114
- /**
115
- * Returns the exported names
116
- * @param {ModuleGraph} moduleGraph module graph
117
- * @returns {ExportsSpec | undefined} export names
118
- */
119
- getExports(moduleGraph) {
120
- const module = /** @type {CssModule} */ (moduleGraph.getParentModule(this));
121
- const generator = /** @type {CssGenerator} */ (module.generator);
122
- const names = this.getExportsConventionNames(
123
- this.name,
124
- /** @type {CssGeneratorExportsConvention} */ (generator.convention)
125
- );
126
- return {
127
- exports: names.map((name) => ({
128
- name,
129
- canMangle: true
130
- })),
131
- dependencies: undefined
132
- };
133
- }
134
-
135
- /**
136
- * Update the hash
137
- * @param {Hash} hash hash to be updated
138
- * @param {UpdateHashContext} context context
139
- * @returns {void}
140
- */
141
- updateHash(hash, { chunkGraph }) {
142
- if (this._hashUpdate === undefined) {
143
- const module =
144
- /** @type {CssModule} */
145
- (chunkGraph.moduleGraph.getParentModule(this));
146
- const generator = /** @type {CssGenerator} */ (module.generator);
147
- const names = this.getExportsConventionNames(
148
- this.name,
149
- /** @type {CssGeneratorExportsConvention} */
150
- (generator.convention)
151
- );
152
- this._hashUpdate = `exportsConvention|${JSON.stringify(names)}|localIdentName|${JSON.stringify(generator.localIdentName)}`;
153
- }
154
- hash.update(this._hashUpdate);
155
- }
156
-
157
- /**
158
- * @param {ObjectSerializerContext} context context
159
- */
160
- serialize(context) {
161
- const { write } = context;
162
- write(this.name);
163
- write(this.range);
164
- write(this.prefix);
165
- super.serialize(context);
166
- }
167
-
168
- /**
169
- * @param {ObjectDeserializerContext} context context
170
- */
171
- deserialize(context) {
172
- const { read } = context;
173
- this.name = read();
174
- this.range = read();
175
- this.prefix = read();
176
- super.deserialize(context);
177
- }
178
- }
179
-
180
- CssLocalIdentifierDependency.Template = class CssLocalIdentifierDependencyTemplate extends (
181
- NullDependency.Template
182
- ) {
183
- /**
184
- * @param {Dependency} dependency the dependency for which the template should be applied
185
- * @param {string} local local name
186
- * @param {DependencyTemplateContext} templateContext the context object
187
- * @returns {string} identifier
188
- */
189
- static getIdentifier(
190
- dependency,
191
- local,
192
- { module: m, chunkGraph, runtimeTemplate }
193
- ) {
194
- const dep = /** @type {CssLocalIdentifierDependency} */ (dependency);
195
- const module = /** @type {CssModule} */ (m);
196
-
197
- return (
198
- dep.prefix +
199
- getCssParser().escapeIdentifier(
200
- getLocalIdent(local, module, chunkGraph, runtimeTemplate)
201
- )
202
- );
203
- }
204
-
205
- /**
206
- * @param {Dependency} dependency the dependency for which the template should be applied
207
- * @param {ReplaceSource} source the current replace source which can be modified
208
- * @param {DependencyTemplateContext} templateContext the context object
209
- * @returns {void}
210
- */
211
- apply(dependency, source, templateContext) {
212
- const { module: m, moduleGraph, runtime, cssData } = templateContext;
213
- const dep = /** @type {CssLocalIdentifierDependency} */ (dependency);
214
- const module = /** @type {CssModule} */ (m);
215
- const generator = /** @type {CssGenerator} */ (module.generator);
216
- const names = dep.getExportsConventionNames(
217
- dep.name,
218
- /** @type {CssGeneratorExportsConvention} */
219
- (generator.convention)
220
- );
221
- const usedNames =
222
- /** @type {string[]} */
223
- (
224
- names
225
- .map((name) =>
226
- moduleGraph.getExportInfo(module, name).getUsedName(name, runtime)
227
- )
228
- .filter(Boolean)
229
- );
230
- const local = usedNames.length === 0 ? names[0] : usedNames[0];
231
- const identifier = CssLocalIdentifierDependencyTemplate.getIdentifier(
232
- dep,
233
- local,
234
- templateContext
235
- );
236
-
237
- source.replace(dep.range[0], dep.range[1] - 1, identifier);
238
-
239
- for (const used of [...usedNames, ...names]) {
240
- cssData.exports.set(used, getCssParser().unescapeIdentifier(identifier));
241
- }
242
- }
243
- };
244
-
245
- makeSerializable(
246
- CssLocalIdentifierDependency,
247
- "webpack/lib/dependencies/CssLocalIdentifierDependency"
248
- );
249
-
250
- module.exports = CssLocalIdentifierDependency;