webpack 5.81.0 → 5.82.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.
- package/bin/webpack.js +13 -2
- package/lib/Compilation.js +2 -0
- package/lib/CssModule.js +39 -7
- package/lib/WebpackOptionsApply.js +33 -40
- package/lib/cache/MemoryWithGcCachePlugin.js +2 -0
- package/lib/config/defaults.js +1 -0
- package/lib/css/CssGenerator.js +4 -0
- package/lib/css/CssLoadingRuntimeModule.js +9 -2
- package/lib/css/CssModulesPlugin.js +136 -33
- package/lib/css/CssParser.js +144 -80
- package/lib/css/walkCssTokens.js +96 -20
- package/lib/debug/ProfilingPlugin.js +2 -0
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +1 -0
- package/lib/javascript/BasicEvaluatedExpression.js +108 -1
- package/lib/javascript/JavascriptParser.js +132 -11
- package/lib/json/JsonData.js +25 -0
- package/lib/json/JsonGenerator.js +15 -3
- package/lib/json/JsonModulesPlugin.js +1 -0
- package/lib/json/JsonParser.js +2 -1
- package/lib/library/ModuleLibraryPlugin.js +2 -1
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +4 -0
- package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +22 -3
- package/lib/schemes/DataUriPlugin.js +4 -0
- package/lib/schemes/HttpUriPlugin.js +38 -0
- package/lib/sharing/utils.js +293 -7
- package/lib/stats/DefaultStatsPrinterPlugin.js +25 -0
- package/lib/util/StackedCacheMap.js +6 -0
- package/lib/util/StringXor.js +51 -0
- package/lib/util/compileBooleanMatcher.js +31 -0
- package/lib/util/deprecation.js +8 -0
- package/lib/util/identifier.js +4 -0
- package/lib/util/numberHash.js +75 -21
- package/lib/util/propertyAccess.js +5 -0
- package/lib/wasm/EnableWasmLoadingPlugin.js +4 -0
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +1 -0
- package/lib/wasm-async/AsyncWebAssemblyParser.js +1 -1
- package/package.json +1 -1
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +25 -0
- package/types.d.ts +121 -26
package/bin/webpack.js
CHANGED
@@ -78,8 +78,19 @@ const runCli = cli => {
|
|
78
78
|
const pkgPath = require.resolve(`${cli.package}/package.json`);
|
79
79
|
// eslint-disable-next-line node/no-missing-require
|
80
80
|
const pkg = require(pkgPath);
|
81
|
-
|
82
|
-
|
81
|
+
|
82
|
+
if (pkg.type === "module" || /\.mjs/i.test(pkg.bin[cli.binName])) {
|
83
|
+
// eslint-disable-next-line node/no-unsupported-features/es-syntax
|
84
|
+
import(path.resolve(path.dirname(pkgPath), pkg.bin[cli.binName])).catch(
|
85
|
+
error => {
|
86
|
+
console.error(error);
|
87
|
+
process.exitCode = 1;
|
88
|
+
}
|
89
|
+
);
|
90
|
+
} else {
|
91
|
+
// eslint-disable-next-line node/no-missing-require
|
92
|
+
require(path.resolve(path.dirname(pkgPath), pkg.bin[cli.binName]));
|
93
|
+
}
|
83
94
|
};
|
84
95
|
|
85
96
|
/**
|
package/lib/Compilation.js
CHANGED
@@ -2578,6 +2578,8 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
|
|
2578
2578
|
p.calculate();
|
2579
2579
|
|
2580
2580
|
const logger = this.getLogger("webpack.Compilation.ModuleProfile");
|
2581
|
+
// Avoid coverage problems due indirect changes
|
2582
|
+
/* istanbul ignore next */
|
2581
2583
|
const logByValue = (value, msg) => {
|
2582
2584
|
if (value > 1000) {
|
2583
2585
|
logger.error(msg);
|
package/lib/CssModule.js
CHANGED
@@ -14,7 +14,13 @@ const makeSerializable = require("./util/makeSerializable");
|
|
14
14
|
/** @typedef {import("./serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
15
15
|
/** @typedef {import("./serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
16
16
|
|
17
|
-
/** @typedef {
|
17
|
+
/** @typedef {string|undefined} CssLayer */
|
18
|
+
/** @typedef {string|undefined} Supports */
|
19
|
+
/** @typedef {string|undefined} Media */
|
20
|
+
/** @typedef {[CssLayer?, Supports?, Media?]} InheritanceItem */
|
21
|
+
/** @typedef {Array<InheritanceItem>} Inheritance */
|
22
|
+
|
23
|
+
/** @typedef {NormalModuleCreateData & { cssLayer: CssLayer|null, supports: Supports|null, media: Media|null, inheritance: Inheritance|null }} CSSModuleCreateData */
|
18
24
|
|
19
25
|
class CssModule extends NormalModule {
|
20
26
|
/**
|
@@ -27,6 +33,7 @@ class CssModule extends NormalModule {
|
|
27
33
|
this.cssLayer = options.cssLayer;
|
28
34
|
this.supports = options.supports;
|
29
35
|
this.media = options.media;
|
36
|
+
this.inheritance = options.inheritance;
|
30
37
|
}
|
31
38
|
|
32
39
|
/**
|
@@ -47,6 +54,17 @@ class CssModule extends NormalModule {
|
|
47
54
|
identifier += `|${this.media}`;
|
48
55
|
}
|
49
56
|
|
57
|
+
if (this.inheritance) {
|
58
|
+
const inheritance = this.inheritance.map(
|
59
|
+
(item, index) =>
|
60
|
+
`inheritance_${index}|${item[0] || ""}|${item[1] || ""}|${
|
61
|
+
item[2] || ""
|
62
|
+
}`
|
63
|
+
);
|
64
|
+
|
65
|
+
identifier += `|${inheritance.join("|")}`;
|
66
|
+
}
|
67
|
+
|
50
68
|
return identifier;
|
51
69
|
}
|
52
70
|
|
@@ -57,11 +75,21 @@ class CssModule extends NormalModule {
|
|
57
75
|
readableIdentifier(requestShortener) {
|
58
76
|
const readableIdentifier = super.readableIdentifier(requestShortener);
|
59
77
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
}
|
78
|
+
let identifier = `css ${readableIdentifier}`;
|
79
|
+
|
80
|
+
if (this.cssLayer) {
|
81
|
+
identifier += ` (layer: ${this.cssLayer})`;
|
82
|
+
}
|
83
|
+
|
84
|
+
if (this.supports) {
|
85
|
+
identifier += ` (supports: ${this.supports})`;
|
86
|
+
}
|
87
|
+
|
88
|
+
if (this.media) {
|
89
|
+
identifier += ` (media: ${this.media})`;
|
90
|
+
}
|
91
|
+
|
92
|
+
return identifier;
|
65
93
|
}
|
66
94
|
|
67
95
|
/**
|
@@ -77,6 +105,7 @@ class CssModule extends NormalModule {
|
|
77
105
|
this.cssLayer = m.cssLayer;
|
78
106
|
this.supports = m.supports;
|
79
107
|
this.media = m.media;
|
108
|
+
this.inheritance = m.inheritance;
|
80
109
|
}
|
81
110
|
|
82
111
|
/**
|
@@ -87,6 +116,7 @@ class CssModule extends NormalModule {
|
|
87
116
|
write(this.cssLayer);
|
88
117
|
write(this.supports);
|
89
118
|
write(this.media);
|
119
|
+
write(this.inheritance);
|
90
120
|
super.serialize(context);
|
91
121
|
}
|
92
122
|
|
@@ -114,7 +144,8 @@ class CssModule extends NormalModule {
|
|
114
144
|
resolveOptions: null,
|
115
145
|
cssLayer: null,
|
116
146
|
supports: null,
|
117
|
-
media: null
|
147
|
+
media: null,
|
148
|
+
inheritance: null
|
118
149
|
});
|
119
150
|
obj.deserialize(context);
|
120
151
|
return obj;
|
@@ -128,6 +159,7 @@ class CssModule extends NormalModule {
|
|
128
159
|
this.cssLayer = read();
|
129
160
|
this.supports = read();
|
130
161
|
this.media = read();
|
162
|
+
this.inheritance = read();
|
131
163
|
super.deserialize(context);
|
132
164
|
}
|
133
165
|
}
|
@@ -119,47 +119,40 @@ class WebpackOptionsApply extends OptionsApply {
|
|
119
119
|
if (options.externalsPresets.webAsync) {
|
120
120
|
//@ts-expect-error https://github.com/microsoft/TypeScript/issues/41697
|
121
121
|
const ExternalsPlugin = require("./ExternalsPlugin");
|
122
|
-
new ExternalsPlugin(
|
123
|
-
"
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
: /^(\/\/|https?:\/\/|std:)/
|
140
|
-
).apply(compiler);
|
122
|
+
new ExternalsPlugin("import", ({ request, dependencyType }, callback) => {
|
123
|
+
if (dependencyType === "url") {
|
124
|
+
if (/^(\/\/|https?:\/\/|#)/.test(request))
|
125
|
+
return callback(null, `asset ${request}`);
|
126
|
+
} else if (options.experiments.css && dependencyType === "css-import") {
|
127
|
+
if (/^(\/\/|https?:\/\/|#)/.test(request))
|
128
|
+
return callback(null, `css-import ${request}`);
|
129
|
+
} else if (
|
130
|
+
options.experiments.css &&
|
131
|
+
/^(\/\/|https?:\/\/|std:)/.test(request)
|
132
|
+
) {
|
133
|
+
if (/^\.css(\?|$)/.test(request))
|
134
|
+
return callback(null, `css-import ${request}`);
|
135
|
+
return callback(null, `import ${request}`);
|
136
|
+
}
|
137
|
+
callback();
|
138
|
+
}).apply(compiler);
|
141
139
|
} else if (options.externalsPresets.web) {
|
142
140
|
//@ts-expect-error https://github.com/microsoft/TypeScript/issues/41697
|
143
141
|
const ExternalsPlugin = require("./ExternalsPlugin");
|
144
|
-
new ExternalsPlugin(
|
145
|
-
"
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
}
|
159
|
-
callback();
|
160
|
-
}
|
161
|
-
: /^(\/\/|https?:\/\/|std:)/
|
162
|
-
).apply(compiler);
|
142
|
+
new ExternalsPlugin("module", ({ request, dependencyType }, callback) => {
|
143
|
+
if (dependencyType === "url") {
|
144
|
+
if (/^(\/\/|https?:\/\/|#)/.test(request))
|
145
|
+
return callback(null, `asset ${request}`);
|
146
|
+
} else if (options.experiments.css && dependencyType === "css-import") {
|
147
|
+
if (/^(\/\/|https?:\/\/|#)/.test(request))
|
148
|
+
return callback(null, `css-import ${request}`);
|
149
|
+
} else if (/^(\/\/|https?:\/\/|std:)/.test(request)) {
|
150
|
+
if (options.experiments.css && /^\.css((\?)|$)/.test(request))
|
151
|
+
return callback(null, `css-import ${request}`);
|
152
|
+
return callback(null, `module ${request}`);
|
153
|
+
}
|
154
|
+
callback();
|
155
|
+
}).apply(compiler);
|
163
156
|
} else if (options.externalsPresets.node) {
|
164
157
|
if (options.experiments.css) {
|
165
158
|
//@ts-expect-error https://github.com/microsoft/TypeScript/issues/41697
|
@@ -168,10 +161,10 @@ class WebpackOptionsApply extends OptionsApply {
|
|
168
161
|
"module",
|
169
162
|
({ request, dependencyType }, callback) => {
|
170
163
|
if (dependencyType === "url") {
|
171
|
-
if (/^(\/\/|https
|
164
|
+
if (/^(\/\/|https?:\/\/|#)/.test(request))
|
172
165
|
return callback(null, `asset ${request}`);
|
173
166
|
} else if (dependencyType === "css-import") {
|
174
|
-
if (/^(\/\/|https
|
167
|
+
if (/^(\/\/|https?:\/\/|#)/.test(request))
|
175
168
|
return callback(null, `css-import ${request}`);
|
176
169
|
} else if (/^(\/\/|https?:\/\/|std:)/.test(request)) {
|
177
170
|
if (/^\.css(\?|$)/.test(request))
|
@@ -34,6 +34,8 @@ class MemoryWithGcCachePlugin {
|
|
34
34
|
generation++;
|
35
35
|
let clearedEntries = 0;
|
36
36
|
let lastClearedIdentifier;
|
37
|
+
// Avoid coverage problems due indirect changes
|
38
|
+
/* istanbul ignore next */
|
37
39
|
for (const [identifier, entry] of oldCache) {
|
38
40
|
if (entry.until > generation) break;
|
39
41
|
|
package/lib/config/defaults.js
CHANGED
package/lib/css/CssGenerator.js
CHANGED
@@ -32,6 +32,7 @@ class CssGenerator extends Generator {
|
|
32
32
|
generate(module, generateContext) {
|
33
33
|
const originalSource = module.originalSource();
|
34
34
|
const source = new ReplaceSource(originalSource);
|
35
|
+
/** @type {InitFragment[]} */
|
35
36
|
const initFragments = [];
|
36
37
|
const cssExports = new Map();
|
37
38
|
|
@@ -51,6 +52,9 @@ class CssGenerator extends Generator {
|
|
51
52
|
cssExports
|
52
53
|
};
|
53
54
|
|
55
|
+
/**
|
56
|
+
* @param {Dependency} dependency dependency
|
57
|
+
*/
|
54
58
|
const handleDependency = dependency => {
|
55
59
|
const constructor = /** @type {new (...args: any[]) => Dependency} */ (
|
56
60
|
dependency.constructor
|
@@ -14,6 +14,7 @@ const compileBooleanMatcher = require("../util/compileBooleanMatcher");
|
|
14
14
|
const { chunkHasCss } = require("./CssModulesPlugin");
|
15
15
|
|
16
16
|
/** @typedef {import("../Chunk")} Chunk */
|
17
|
+
/** @typedef {import("../Compilation").RuntimeRequirementsContext} RuntimeRequirementsContext */
|
17
18
|
|
18
19
|
/**
|
19
20
|
* @typedef {Object} JsonpCompilationPluginHooks
|
@@ -44,11 +45,13 @@ class CssLoadingRuntimeModule extends RuntimeModule {
|
|
44
45
|
return hooks;
|
45
46
|
}
|
46
47
|
|
47
|
-
|
48
|
+
/**
|
49
|
+
* @param {Set<string>} runtimeRequirements runtime requirements
|
50
|
+
*/
|
51
|
+
constructor(runtimeRequirements) {
|
48
52
|
super("css loading", 10);
|
49
53
|
|
50
54
|
this._runtimeRequirements = runtimeRequirements;
|
51
|
-
this.runtimeOptions = runtimeOptions;
|
52
55
|
}
|
53
56
|
|
54
57
|
/**
|
@@ -76,10 +79,13 @@ class CssLoadingRuntimeModule extends RuntimeModule {
|
|
76
79
|
const withLoading =
|
77
80
|
_runtimeRequirements.has(RuntimeGlobals.ensureChunkHandlers) &&
|
78
81
|
hasCssMatcher !== false;
|
82
|
+
/** @type {boolean} */
|
79
83
|
const withHmr = _runtimeRequirements.has(
|
80
84
|
RuntimeGlobals.hmrDownloadUpdateHandlers
|
81
85
|
);
|
86
|
+
/** @type {Set<number | string | null>} */
|
82
87
|
const initialChunkIdsWithCss = new Set();
|
88
|
+
/** @type {Set<number | string | null>} */
|
83
89
|
const initialChunkIdsWithoutCss = new Set();
|
84
90
|
for (const c of chunk.getAllInitialChunks()) {
|
85
91
|
(chunkHasCss(c, chunkGraph)
|
@@ -120,6 +126,7 @@ class CssLoadingRuntimeModule extends RuntimeModule {
|
|
120
126
|
: ""
|
121
127
|
]);
|
122
128
|
|
129
|
+
/** @type {(str: string) => number} */
|
123
130
|
const cc = str => str.charCodeAt(0);
|
124
131
|
|
125
132
|
return Template.asString([
|
@@ -15,6 +15,7 @@ const {
|
|
15
15
|
} = require("../ModuleTypeConstants");
|
16
16
|
const RuntimeGlobals = require("../RuntimeGlobals");
|
17
17
|
const SelfModuleFactory = require("../SelfModuleFactory");
|
18
|
+
const WebpackError = require("../WebpackError");
|
18
19
|
const CssExportDependency = require("../dependencies/CssExportDependency");
|
19
20
|
const CssImportDependency = require("../dependencies/CssImportDependency");
|
20
21
|
const CssLocalIdentifierDependency = require("../dependencies/CssLocalIdentifierDependency");
|
@@ -32,9 +33,14 @@ const CssParser = require("./CssParser");
|
|
32
33
|
|
33
34
|
/** @typedef {import("webpack-sources").Source} Source */
|
34
35
|
/** @typedef {import("../../declarations/WebpackOptions").CssExperimentOptions} CssExperimentOptions */
|
36
|
+
/** @typedef {import("../../declarations/WebpackOptions").Output} OutputOptions */
|
35
37
|
/** @typedef {import("../Chunk")} Chunk */
|
38
|
+
/** @typedef {import("../ChunkGraph")} ChunkGraph */
|
39
|
+
/** @typedef {import("../CodeGenerationResults")} CodeGenerationResults */
|
40
|
+
/** @typedef {import("../Compilation")} Compilation */
|
36
41
|
/** @typedef {import("../Compiler")} Compiler */
|
37
42
|
/** @typedef {import("../Module")} Module */
|
43
|
+
/** @typedef {import("../util/memoize")} Memoize */
|
38
44
|
|
39
45
|
const getCssLoadingRuntimeModule = memoize(() =>
|
40
46
|
require("./CssLoadingRuntimeModule")
|
@@ -65,6 +71,11 @@ const validateParserOptions = createSchemaValidation(
|
|
65
71
|
}
|
66
72
|
);
|
67
73
|
|
74
|
+
/**
|
75
|
+
* @param {string} str string
|
76
|
+
* @param {boolean=} omitOptionalUnderscore if true, optional underscore is not added
|
77
|
+
* @returns {string} escaped string
|
78
|
+
*/
|
68
79
|
const escapeCss = (str, omitOptionalUnderscore) => {
|
69
80
|
const escaped = `${str}`.replace(
|
70
81
|
// cspell:word uffff
|
@@ -170,12 +181,56 @@ class CssModulesPlugin {
|
|
170
181
|
// When CSS is imported from CSS there is only one dependency
|
171
182
|
const dependency = resolveData.dependencies[0];
|
172
183
|
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
184
|
+
if (dependency instanceof CssImportDependency) {
|
185
|
+
const parent =
|
186
|
+
/** @type {CssModule} */
|
187
|
+
(compilation.moduleGraph.getParentModule(dependency));
|
188
|
+
|
189
|
+
if (parent instanceof CssModule) {
|
190
|
+
/** @type {import("../CssModule").Inheritance | undefined} */
|
191
|
+
let inheritance;
|
192
|
+
|
193
|
+
if (
|
194
|
+
(parent.cssLayer !== null &&
|
195
|
+
parent.cssLayer !== undefined) ||
|
196
|
+
parent.supports ||
|
197
|
+
parent.media
|
198
|
+
) {
|
199
|
+
if (!inheritance) {
|
200
|
+
inheritance = [];
|
201
|
+
}
|
202
|
+
|
203
|
+
inheritance.push([
|
204
|
+
parent.cssLayer,
|
205
|
+
parent.supports,
|
206
|
+
parent.media
|
207
|
+
]);
|
208
|
+
}
|
209
|
+
|
210
|
+
if (parent.inheritance) {
|
211
|
+
if (!inheritance) {
|
212
|
+
inheritance = [];
|
213
|
+
}
|
214
|
+
|
215
|
+
inheritance.push(...parent.inheritance);
|
216
|
+
}
|
217
|
+
|
218
|
+
return new CssModule({
|
219
|
+
...createData,
|
220
|
+
cssLayer: dependency.layer,
|
221
|
+
supports: dependency.supports,
|
222
|
+
media: dependency.media,
|
223
|
+
inheritance
|
224
|
+
});
|
225
|
+
}
|
226
|
+
|
227
|
+
return new CssModule({
|
228
|
+
...createData,
|
229
|
+
cssLayer: dependency.layer,
|
230
|
+
supports: dependency.supports,
|
231
|
+
media: dependency.media
|
232
|
+
});
|
233
|
+
}
|
179
234
|
}
|
180
235
|
|
181
236
|
return new CssModule(createData);
|
@@ -219,6 +274,7 @@ class CssModulesPlugin {
|
|
219
274
|
|
220
275
|
if (chunk instanceof HotUpdateChunk) return result;
|
221
276
|
|
277
|
+
/** @type {CssModule[] | undefined} */
|
222
278
|
const modules = orderedCssModulesPerChunk.get(chunk);
|
223
279
|
if (modules !== undefined) {
|
224
280
|
result.push({
|
@@ -275,9 +331,16 @@ class CssModulesPlugin {
|
|
275
331
|
);
|
276
332
|
}
|
277
333
|
|
334
|
+
/**
|
335
|
+
* @param {Chunk} chunk chunk
|
336
|
+
* @param {Iterable<Module>} modules unordered modules
|
337
|
+
* @param {Compilation} compilation compilation
|
338
|
+
* @returns {Module[]} ordered modules
|
339
|
+
*/
|
278
340
|
getModulesInOrder(chunk, modules, compilation) {
|
279
341
|
if (!modules) return [];
|
280
342
|
|
343
|
+
/** @type {Module[]} */
|
281
344
|
const modulesList = [...modules];
|
282
345
|
|
283
346
|
// Get ordered list of modules per chunk group
|
@@ -311,6 +374,7 @@ class CssModulesPlugin {
|
|
311
374
|
|
312
375
|
modulesByChunkGroup.sort(compareModuleLists);
|
313
376
|
|
377
|
+
/** @type {Module[]} */
|
314
378
|
const finalModules = [];
|
315
379
|
|
316
380
|
for (;;) {
|
@@ -320,6 +384,7 @@ class CssModulesPlugin {
|
|
320
384
|
// done, everything empty
|
321
385
|
break;
|
322
386
|
}
|
387
|
+
/** @type {Module} */
|
323
388
|
let selectedModule = list[list.length - 1];
|
324
389
|
let hasFailed = undefined;
|
325
390
|
outer: for (;;) {
|
@@ -345,18 +410,17 @@ class CssModulesPlugin {
|
|
345
410
|
if (compilation) {
|
346
411
|
// TODO print better warning
|
347
412
|
compilation.warnings.push(
|
348
|
-
new
|
349
|
-
`chunk ${
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
)} and ${selectedModule.readableIdentifier(
|
413
|
+
new WebpackError(
|
414
|
+
`chunk ${chunk.name || chunk.id}\nConflicting order between ${
|
415
|
+
/** @type {Module} */
|
416
|
+
(hasFailed).readableIdentifier(compilation.requestShortener)
|
417
|
+
} and ${selectedModule.readableIdentifier(
|
354
418
|
compilation.requestShortener
|
355
419
|
)}`
|
356
420
|
)
|
357
421
|
);
|
358
422
|
}
|
359
|
-
selectedModule = hasFailed;
|
423
|
+
selectedModule = /** @type {Module} */ (hasFailed);
|
360
424
|
}
|
361
425
|
// Insert the selected module into the final modules list
|
362
426
|
finalModules.push(selectedModule);
|
@@ -374,6 +438,12 @@ class CssModulesPlugin {
|
|
374
438
|
return finalModules;
|
375
439
|
}
|
376
440
|
|
441
|
+
/**
|
442
|
+
* @param {Chunk} chunk chunk
|
443
|
+
* @param {ChunkGraph} chunkGraph chunk graph
|
444
|
+
* @param {Compilation} compilation compilation
|
445
|
+
* @returns {Module[]} ordered css modules
|
446
|
+
*/
|
377
447
|
getOrderedChunkCssModules(chunk, chunkGraph, compilation) {
|
378
448
|
return [
|
379
449
|
...this.getModulesInOrder(
|
@@ -397,6 +467,15 @@ class CssModulesPlugin {
|
|
397
467
|
];
|
398
468
|
}
|
399
469
|
|
470
|
+
/**
|
471
|
+
* @param {Object} options options
|
472
|
+
* @param {string | undefined} options.uniqueName unique name
|
473
|
+
* @param {Chunk} options.chunk chunk
|
474
|
+
* @param {ChunkGraph} options.chunkGraph chunk graph
|
475
|
+
* @param {CodeGenerationResults} options.codeGenerationResults code generation results
|
476
|
+
* @param {CssModule[]} options.modules ordered css modules
|
477
|
+
* @returns {Source} generated source
|
478
|
+
*/
|
400
479
|
renderChunk({
|
401
480
|
uniqueName,
|
402
481
|
chunk,
|
@@ -405,6 +484,7 @@ class CssModulesPlugin {
|
|
405
484
|
modules
|
406
485
|
}) {
|
407
486
|
const source = new ConcatSource();
|
487
|
+
/** @type {string[]} */
|
408
488
|
const metaData = [];
|
409
489
|
for (const module of modules) {
|
410
490
|
try {
|
@@ -414,35 +494,48 @@ class CssModulesPlugin {
|
|
414
494
|
codeGenResult.sources.get("css") ||
|
415
495
|
codeGenResult.sources.get("css-import");
|
416
496
|
|
417
|
-
|
418
|
-
moduleSource = new ConcatSource(
|
419
|
-
`@media ${module.media} {\n`,
|
420
|
-
new PrefixSource("\t", moduleSource),
|
421
|
-
"}"
|
422
|
-
);
|
423
|
-
}
|
497
|
+
let inheritance = [[module.cssLayer, module.supports, module.media]];
|
424
498
|
|
425
|
-
if (module.
|
426
|
-
|
427
|
-
`@supports (${module.supports}) {\n`,
|
428
|
-
new PrefixSource("\t", moduleSource),
|
429
|
-
"}"
|
430
|
-
);
|
499
|
+
if (module.inheritance) {
|
500
|
+
inheritance.push(...module.inheritance);
|
431
501
|
}
|
432
502
|
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
503
|
+
for (let i = 0; i < inheritance.length; i++) {
|
504
|
+
const layer = inheritance[i][0];
|
505
|
+
const supports = inheritance[i][1];
|
506
|
+
const media = inheritance[i][2];
|
507
|
+
|
508
|
+
if (media) {
|
509
|
+
moduleSource = new ConcatSource(
|
510
|
+
`@media ${media} {\n`,
|
511
|
+
new PrefixSource("\t", moduleSource),
|
512
|
+
"}\n"
|
513
|
+
);
|
514
|
+
}
|
515
|
+
|
516
|
+
if (supports) {
|
517
|
+
moduleSource = new ConcatSource(
|
518
|
+
`@supports (${supports}) {\n`,
|
519
|
+
new PrefixSource("\t", moduleSource),
|
520
|
+
"}\n"
|
521
|
+
);
|
522
|
+
}
|
523
|
+
|
524
|
+
// Layer can be anonymous
|
525
|
+
if (layer !== undefined && layer !== null) {
|
526
|
+
moduleSource = new ConcatSource(
|
527
|
+
`@layer${layer ? ` ${layer}` : ""} {\n`,
|
528
|
+
new PrefixSource("\t", moduleSource),
|
529
|
+
"}\n"
|
530
|
+
);
|
531
|
+
}
|
440
532
|
}
|
441
533
|
|
442
534
|
if (moduleSource) {
|
443
535
|
source.add(moduleSource);
|
444
536
|
source.add("\n");
|
445
537
|
}
|
538
|
+
/** @type {Map<string, string> | undefined} */
|
446
539
|
const exports =
|
447
540
|
codeGenResult.data && codeGenResult.data.get("css-exports");
|
448
541
|
let moduleId = chunkGraph.getModuleId(module) + "";
|
@@ -482,6 +575,11 @@ class CssModulesPlugin {
|
|
482
575
|
return source;
|
483
576
|
}
|
484
577
|
|
578
|
+
/**
|
579
|
+
* @param {Chunk} chunk chunk
|
580
|
+
* @param {OutputOptions} outputOptions output options
|
581
|
+
* @returns {Chunk["cssFilenameTemplate"] | OutputOptions["cssFilename"] | OutputOptions["cssChunkFilename"]} used filename template
|
582
|
+
*/
|
485
583
|
static getChunkFilenameTemplate(chunk, outputOptions) {
|
486
584
|
if (chunk.cssFilenameTemplate) {
|
487
585
|
return chunk.cssFilenameTemplate;
|
@@ -492,6 +590,11 @@ class CssModulesPlugin {
|
|
492
590
|
}
|
493
591
|
}
|
494
592
|
|
593
|
+
/**
|
594
|
+
* @param {Chunk} chunk chunk
|
595
|
+
* @param {ChunkGraph} chunkGraph chunk graph
|
596
|
+
* @returns {boolean} true, when the chunk has css
|
597
|
+
*/
|
495
598
|
static chunkHasCss(chunk, chunkGraph) {
|
496
599
|
return (
|
497
600
|
!!chunkGraph.getChunkModulesIterableBySourceType(chunk, "css") ||
|