webpack 5.80.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/AsyncDependenciesBlock.js +8 -0
- package/lib/CodeGenerationResults.js +2 -2
- package/lib/Compilation.js +4 -2
- package/lib/ContextModule.js +8 -0
- package/lib/CssModule.js +169 -0
- package/lib/DefinePlugin.js +81 -44
- package/lib/DelegatedModule.js +5 -0
- package/lib/DependenciesBlock.js +8 -0
- package/lib/Dependency.js +8 -0
- package/lib/DllModule.js +8 -0
- package/lib/ExportsInfo.js +3 -0
- package/lib/ExternalModule.js +8 -0
- package/lib/FileSystemInfo.js +8 -0
- package/lib/LoaderOptionsPlugin.js +12 -2
- package/lib/Module.js +8 -0
- package/lib/ModuleBuildError.js +9 -0
- package/lib/ModuleError.js +9 -0
- package/lib/ModuleFilenameHelpers.js +113 -4
- package/lib/ModuleParseError.js +9 -0
- package/lib/ModuleTypeConstants.js +21 -0
- package/lib/ModuleWarning.js +9 -0
- package/lib/NormalModule.js +8 -0
- package/lib/NormalModuleFactory.js +15 -3
- package/lib/RawModule.js +8 -0
- package/lib/WebpackError.js +8 -0
- package/lib/WebpackOptionsApply.js +33 -40
- package/lib/asset/RawDataUrlModule.js +8 -0
- package/lib/cache/MemoryWithGcCachePlugin.js +2 -0
- package/lib/cache/ResolverCachePlugin.js +3 -0
- package/lib/config/defaults.js +1 -0
- package/lib/config/normalization.js +1 -0
- package/lib/container/ContainerEntryModule.js +5 -0
- package/lib/container/ContainerExposedDependency.js +9 -0
- package/lib/container/FallbackDependency.js +6 -0
- package/lib/container/FallbackModule.js +5 -0
- package/lib/container/RemoteModule.js +5 -0
- package/lib/css/CssGenerator.js +4 -0
- package/lib/css/CssLoadingRuntimeModule.js +9 -2
- package/lib/css/CssModulesPlugin.js +201 -57
- package/lib/css/CssParser.js +270 -147
- package/lib/css/walkCssTokens.js +121 -65
- package/lib/debug/ProfilingPlugin.js +2 -0
- package/lib/dependencies/AMDDefineDependency.js +8 -0
- package/lib/dependencies/AMDRequireArrayDependency.js +8 -0
- package/lib/dependencies/AMDRequireContextDependency.js +9 -0
- package/lib/dependencies/AMDRequireDependency.js +8 -0
- package/lib/dependencies/CachedConstDependency.js +8 -0
- package/lib/dependencies/CommonJsDependencyHelpers.js +9 -0
- package/lib/dependencies/CommonJsExportRequireDependency.js +8 -0
- package/lib/dependencies/CommonJsExportsDependency.js +8 -0
- package/lib/dependencies/CommonJsExportsParserPlugin.js +65 -3
- package/lib/dependencies/CommonJsFullRequireDependency.js +8 -0
- package/lib/dependencies/CommonJsRequireContextDependency.js +9 -0
- package/lib/dependencies/CommonJsSelfReferenceDependency.js +8 -0
- package/lib/dependencies/ConstDependency.js +8 -0
- package/lib/dependencies/ContextDependency.js +8 -0
- package/lib/dependencies/ContextElementDependency.js +8 -0
- package/lib/dependencies/CreateScriptUrlDependency.js +8 -0
- package/lib/dependencies/CssExportDependency.js +8 -0
- package/lib/dependencies/CssImportDependency.js +52 -1
- package/lib/dependencies/CssLocalIdentifierDependency.js +8 -0
- package/lib/dependencies/CssSelfLocalIdentifierDependency.js +8 -0
- package/lib/dependencies/CssUrlDependency.js +8 -0
- package/lib/dependencies/DllEntryDependency.js +9 -0
- package/lib/dependencies/ExportsInfoDependency.js +5 -0
- package/lib/dependencies/HarmonyAcceptDependency.js +8 -0
- package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +8 -0
- package/lib/dependencies/HarmonyExportExpressionDependency.js +8 -0
- package/lib/dependencies/HarmonyExportHeaderDependency.js +8 -0
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +14 -0
- package/lib/dependencies/HarmonyExportSpecifierDependency.js +8 -0
- package/lib/dependencies/HarmonyImportDependency.js +8 -0
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +1 -0
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +8 -0
- package/lib/dependencies/ImportContextDependency.js +9 -0
- package/lib/dependencies/ImportDependency.js +8 -0
- package/lib/dependencies/JsonExportsDependency.js +8 -0
- package/lib/dependencies/LocalModuleDependency.js +8 -0
- package/lib/dependencies/ModuleDecoratorDependency.js +8 -0
- package/lib/dependencies/ModuleDependency.js +8 -0
- package/lib/dependencies/ProvidedDependency.js +8 -0
- package/lib/dependencies/PureExpressionDependency.js +8 -0
- package/lib/dependencies/RequireEnsureDependency.js +8 -0
- package/lib/dependencies/RequireHeaderDependency.js +5 -0
- package/lib/dependencies/RequireResolveContextDependency.js +9 -0
- package/lib/dependencies/RequireResolveHeaderDependency.js +5 -0
- package/lib/dependencies/RuntimeRequirementsDependency.js +8 -0
- package/lib/dependencies/StaticExportsDependency.js +8 -0
- package/lib/dependencies/URLDependency.js +8 -0
- package/lib/dependencies/UnsupportedDependency.js +8 -0
- package/lib/dependencies/WebAssemblyExportImportedDependency.js +8 -0
- package/lib/dependencies/WebAssemblyImportDependency.js +8 -0
- package/lib/dependencies/WorkerDependency.js +8 -0
- package/lib/index.js +1 -0
- package/lib/javascript/BasicEvaluatedExpression.js +108 -1
- package/lib/javascript/JavascriptParser.js +133 -12
- 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/optimize/RealContentHashPlugin.js +6 -0
- package/lib/runtime/AutoPublicPathRuntimeModule.js +6 -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/serialization/ObjectMiddleware.js +2 -0
- package/lib/sharing/ConsumeSharedModule.js +8 -0
- package/lib/sharing/ConsumeSharedRuntimeModule.js +9 -3
- package/lib/sharing/ProvideSharedDependency.js +6 -0
- package/lib/sharing/ProvideSharedModule.js +5 -0
- package/lib/sharing/ShareRuntimeModule.js +7 -4
- package/lib/sharing/utils.js +293 -7
- package/lib/stats/DefaultStatsPrinterPlugin.js +25 -0
- package/lib/util/LazySet.js +10 -2
- package/lib/util/MapHelpers.js +19 -5
- package/lib/util/StackedCacheMap.js +6 -0
- package/lib/util/StringXor.js +51 -0
- package/lib/util/binarySearchBounds.js +49 -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/internalSerializables.js +1 -0
- package/lib/util/numberHash.js +75 -21
- package/lib/util/propertyAccess.js +5 -0
- package/lib/util/semver.js +1 -1
- 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 +4 -5
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +33 -0
- package/types.d.ts +176 -48
@@ -124,8 +124,11 @@ class ResolverCachePlugin {
|
|
124
124
|
const newResolveContext = {
|
125
125
|
...resolveContext,
|
126
126
|
stack: new Set(),
|
127
|
+
/** @type {LazySet<string>} */
|
127
128
|
missingDependencies: new LazySet(),
|
129
|
+
/** @type {LazySet<string>} */
|
128
130
|
fileDependencies: new LazySet(),
|
131
|
+
/** @type {LazySet<string>} */
|
129
132
|
contextDependencies: new LazySet()
|
130
133
|
};
|
131
134
|
let yieldResult;
|
package/lib/config/defaults.js
CHANGED
@@ -327,6 +327,7 @@ const getNormalizedWebpackOptions = config => {
|
|
327
327
|
hotUpdateChunkFilename: output.hotUpdateChunkFilename,
|
328
328
|
hotUpdateGlobal: output.hotUpdateGlobal,
|
329
329
|
hotUpdateMainFilename: output.hotUpdateMainFilename,
|
330
|
+
ignoreBrowserWarnings: output.ignoreBrowserWarnings,
|
330
331
|
iife: output.iife,
|
331
332
|
importFunctionName: output.importFunctionName,
|
332
333
|
importMetaName: output.importMetaName,
|
@@ -26,6 +26,8 @@ const ContainerExposedDependency = require("./ContainerExposedDependency");
|
|
26
26
|
/** @typedef {import("../RequestShortener")} RequestShortener */
|
27
27
|
/** @typedef {import("../ResolverFactory").ResolverWithOptions} ResolverWithOptions */
|
28
28
|
/** @typedef {import("../WebpackError")} WebpackError */
|
29
|
+
/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
30
|
+
/** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
29
31
|
/** @typedef {import("../util/Hash")} Hash */
|
30
32
|
/** @typedef {import("../util/fs").InputFileSystem} InputFileSystem */
|
31
33
|
/** @typedef {import("./ContainerEntryDependency")} ContainerEntryDependency */
|
@@ -260,6 +262,9 @@ class ContainerEntryModule extends Module {
|
|
260
262
|
return 42;
|
261
263
|
}
|
262
264
|
|
265
|
+
/**
|
266
|
+
* @param {ObjectSerializerContext} context context
|
267
|
+
*/
|
263
268
|
serialize(context) {
|
264
269
|
const { write } = context;
|
265
270
|
write(this._name);
|
@@ -8,6 +8,9 @@
|
|
8
8
|
const ModuleDependency = require("../dependencies/ModuleDependency");
|
9
9
|
const makeSerializable = require("../util/makeSerializable");
|
10
10
|
|
11
|
+
/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
12
|
+
/** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
13
|
+
|
11
14
|
class ContainerExposedDependency extends ModuleDependency {
|
12
15
|
/**
|
13
16
|
* @param {string} exposedName public name
|
@@ -33,11 +36,17 @@ class ContainerExposedDependency extends ModuleDependency {
|
|
33
36
|
return `exposed dependency ${this.exposedName}=${this.request}`;
|
34
37
|
}
|
35
38
|
|
39
|
+
/**
|
40
|
+
* @param {ObjectSerializerContext} context context
|
41
|
+
*/
|
36
42
|
serialize(context) {
|
37
43
|
context.write(this.exposedName);
|
38
44
|
super.serialize(context);
|
39
45
|
}
|
40
46
|
|
47
|
+
/**
|
48
|
+
* @param {ObjectDeserializerContext} context context
|
49
|
+
*/
|
41
50
|
deserialize(context) {
|
42
51
|
this.exposedName = context.read();
|
43
52
|
super.deserialize(context);
|
@@ -8,6 +8,9 @@
|
|
8
8
|
const Dependency = require("../Dependency");
|
9
9
|
const makeSerializable = require("../util/makeSerializable");
|
10
10
|
|
11
|
+
/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
12
|
+
/** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
13
|
+
|
11
14
|
class FallbackDependency extends Dependency {
|
12
15
|
constructor(requests) {
|
13
16
|
super();
|
@@ -29,6 +32,9 @@ class FallbackDependency extends Dependency {
|
|
29
32
|
return "esm";
|
30
33
|
}
|
31
34
|
|
35
|
+
/**
|
36
|
+
* @param {ObjectSerializerContext} context context
|
37
|
+
*/
|
32
38
|
serialize(context) {
|
33
39
|
const { write } = context;
|
34
40
|
write(this.requests);
|
@@ -24,6 +24,8 @@ const FallbackItemDependency = require("./FallbackItemDependency");
|
|
24
24
|
/** @typedef {import("../RequestShortener")} RequestShortener */
|
25
25
|
/** @typedef {import("../ResolverFactory").ResolverWithOptions} ResolverWithOptions */
|
26
26
|
/** @typedef {import("../WebpackError")} WebpackError */
|
27
|
+
/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
28
|
+
/** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
27
29
|
/** @typedef {import("../util/Hash")} Hash */
|
28
30
|
/** @typedef {import("../util/fs").InputFileSystem} InputFileSystem */
|
29
31
|
|
@@ -154,6 +156,9 @@ class FallbackModule extends Module {
|
|
154
156
|
return { sources, runtimeRequirements: RUNTIME_REQUIREMENTS };
|
155
157
|
}
|
156
158
|
|
159
|
+
/**
|
160
|
+
* @param {ObjectSerializerContext} context context
|
161
|
+
*/
|
157
162
|
serialize(context) {
|
158
163
|
const { write } = context;
|
159
164
|
write(this.requests);
|
@@ -23,6 +23,8 @@ const RemoteToExternalDependency = require("./RemoteToExternalDependency");
|
|
23
23
|
/** @typedef {import("../RequestShortener")} RequestShortener */
|
24
24
|
/** @typedef {import("../ResolverFactory").ResolverWithOptions} ResolverWithOptions */
|
25
25
|
/** @typedef {import("../WebpackError")} WebpackError */
|
26
|
+
/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
27
|
+
/** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
26
28
|
/** @typedef {import("../util/Hash")} Hash */
|
27
29
|
/** @typedef {import("../util/fs").InputFileSystem} InputFileSystem */
|
28
30
|
|
@@ -149,6 +151,9 @@ class RemoteModule extends Module {
|
|
149
151
|
return { sources, data, runtimeRequirements: RUNTIME_REQUIREMENTS };
|
150
152
|
}
|
151
153
|
|
154
|
+
/**
|
155
|
+
* @param {ObjectSerializerContext} context context
|
156
|
+
*/
|
152
157
|
serialize(context) {
|
153
158
|
const { write } = context;
|
154
159
|
write(this.request);
|
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([
|
@@ -5,10 +5,17 @@
|
|
5
5
|
|
6
6
|
"use strict";
|
7
7
|
|
8
|
-
const { ConcatSource } = require("webpack-sources");
|
8
|
+
const { ConcatSource, PrefixSource } = require("webpack-sources");
|
9
|
+
const CssModule = require("../CssModule");
|
9
10
|
const HotUpdateChunk = require("../HotUpdateChunk");
|
11
|
+
const {
|
12
|
+
CSS_MODULE_TYPE,
|
13
|
+
CSS_MODULE_TYPE_GLOBAL,
|
14
|
+
CSS_MODULE_TYPE_MODULE
|
15
|
+
} = require("../ModuleTypeConstants");
|
10
16
|
const RuntimeGlobals = require("../RuntimeGlobals");
|
11
17
|
const SelfModuleFactory = require("../SelfModuleFactory");
|
18
|
+
const WebpackError = require("../WebpackError");
|
12
19
|
const CssExportDependency = require("../dependencies/CssExportDependency");
|
13
20
|
const CssImportDependency = require("../dependencies/CssImportDependency");
|
14
21
|
const CssLocalIdentifierDependency = require("../dependencies/CssLocalIdentifierDependency");
|
@@ -26,9 +33,14 @@ const CssParser = require("./CssParser");
|
|
26
33
|
|
27
34
|
/** @typedef {import("webpack-sources").Source} Source */
|
28
35
|
/** @typedef {import("../../declarations/WebpackOptions").CssExperimentOptions} CssExperimentOptions */
|
36
|
+
/** @typedef {import("../../declarations/WebpackOptions").Output} OutputOptions */
|
29
37
|
/** @typedef {import("../Chunk")} Chunk */
|
38
|
+
/** @typedef {import("../ChunkGraph")} ChunkGraph */
|
39
|
+
/** @typedef {import("../CodeGenerationResults")} CodeGenerationResults */
|
40
|
+
/** @typedef {import("../Compilation")} Compilation */
|
30
41
|
/** @typedef {import("../Compiler")} Compiler */
|
31
42
|
/** @typedef {import("../Module")} Module */
|
43
|
+
/** @typedef {import("../util/memoize")} Memoize */
|
32
44
|
|
33
45
|
const getCssLoadingRuntimeModule = memoize(() =>
|
34
46
|
require("./CssLoadingRuntimeModule")
|
@@ -59,6 +71,11 @@ const validateParserOptions = createSchemaValidation(
|
|
59
71
|
}
|
60
72
|
);
|
61
73
|
|
74
|
+
/**
|
75
|
+
* @param {string} str string
|
76
|
+
* @param {boolean=} omitOptionalUnderscore if true, optional underscore is not added
|
77
|
+
* @returns {string} escaped string
|
78
|
+
*/
|
62
79
|
const escapeCss = (str, omitOptionalUnderscore) => {
|
63
80
|
const escaped = `${str}`.replace(
|
64
81
|
// cspell:word uffff
|
@@ -125,53 +142,100 @@ class CssModulesPlugin {
|
|
125
142
|
StaticExportsDependency,
|
126
143
|
new StaticExportsDependency.Template()
|
127
144
|
);
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
145
|
+
for (const type of [
|
146
|
+
CSS_MODULE_TYPE,
|
147
|
+
CSS_MODULE_TYPE_GLOBAL,
|
148
|
+
CSS_MODULE_TYPE_MODULE
|
149
|
+
]) {
|
150
|
+
normalModuleFactory.hooks.createParser
|
151
|
+
.for(type)
|
152
|
+
.tap(plugin, parserOptions => {
|
153
|
+
validateParserOptions(parserOptions);
|
154
|
+
|
155
|
+
switch (type) {
|
156
|
+
case CSS_MODULE_TYPE:
|
157
|
+
return new CssParser();
|
158
|
+
case CSS_MODULE_TYPE_GLOBAL:
|
159
|
+
return new CssParser({
|
160
|
+
allowPseudoBlocks: false,
|
161
|
+
allowModeSwitch: false
|
162
|
+
});
|
163
|
+
case CSS_MODULE_TYPE_MODULE:
|
164
|
+
return new CssParser({
|
165
|
+
defaultMode: "local"
|
166
|
+
});
|
167
|
+
}
|
141
168
|
});
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
169
|
+
normalModuleFactory.hooks.createGenerator
|
170
|
+
.for(type)
|
171
|
+
.tap(plugin, generatorOptions => {
|
172
|
+
validateGeneratorOptions(generatorOptions);
|
173
|
+
return this._exportsOnly
|
174
|
+
? new CssExportsGenerator()
|
175
|
+
: new CssGenerator();
|
149
176
|
});
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
177
|
+
normalModuleFactory.hooks.createModuleClass
|
178
|
+
.for(type)
|
179
|
+
.tap(plugin, (createData, resolveData) => {
|
180
|
+
if (resolveData.dependencies.length > 0) {
|
181
|
+
// When CSS is imported from CSS there is only one dependency
|
182
|
+
const dependency = resolveData.dependencies[0];
|
183
|
+
|
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
|
+
}
|
234
|
+
}
|
235
|
+
|
236
|
+
return new CssModule(createData);
|
237
|
+
});
|
238
|
+
}
|
175
239
|
const orderedCssModulesPerChunk = new WeakMap();
|
176
240
|
compilation.hooks.afterCodeGeneration.tap("CssModulesPlugin", () => {
|
177
241
|
const { chunkGraph } = compilation;
|
@@ -210,6 +274,7 @@ class CssModulesPlugin {
|
|
210
274
|
|
211
275
|
if (chunk instanceof HotUpdateChunk) return result;
|
212
276
|
|
277
|
+
/** @type {CssModule[] | undefined} */
|
213
278
|
const modules = orderedCssModulesPerChunk.get(chunk);
|
214
279
|
if (modules !== undefined) {
|
215
280
|
result.push({
|
@@ -266,9 +331,16 @@ class CssModulesPlugin {
|
|
266
331
|
);
|
267
332
|
}
|
268
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
|
+
*/
|
269
340
|
getModulesInOrder(chunk, modules, compilation) {
|
270
341
|
if (!modules) return [];
|
271
342
|
|
343
|
+
/** @type {Module[]} */
|
272
344
|
const modulesList = [...modules];
|
273
345
|
|
274
346
|
// Get ordered list of modules per chunk group
|
@@ -302,6 +374,7 @@ class CssModulesPlugin {
|
|
302
374
|
|
303
375
|
modulesByChunkGroup.sort(compareModuleLists);
|
304
376
|
|
377
|
+
/** @type {Module[]} */
|
305
378
|
const finalModules = [];
|
306
379
|
|
307
380
|
for (;;) {
|
@@ -311,6 +384,7 @@ class CssModulesPlugin {
|
|
311
384
|
// done, everything empty
|
312
385
|
break;
|
313
386
|
}
|
387
|
+
/** @type {Module} */
|
314
388
|
let selectedModule = list[list.length - 1];
|
315
389
|
let hasFailed = undefined;
|
316
390
|
outer: for (;;) {
|
@@ -336,18 +410,17 @@ class CssModulesPlugin {
|
|
336
410
|
if (compilation) {
|
337
411
|
// TODO print better warning
|
338
412
|
compilation.warnings.push(
|
339
|
-
new
|
340
|
-
`chunk ${
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
)} 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(
|
345
418
|
compilation.requestShortener
|
346
419
|
)}`
|
347
420
|
)
|
348
421
|
);
|
349
422
|
}
|
350
|
-
selectedModule = hasFailed;
|
423
|
+
selectedModule = /** @type {Module} */ (hasFailed);
|
351
424
|
}
|
352
425
|
// Insert the selected module into the final modules list
|
353
426
|
finalModules.push(selectedModule);
|
@@ -365,6 +438,12 @@ class CssModulesPlugin {
|
|
365
438
|
return finalModules;
|
366
439
|
}
|
367
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
|
+
*/
|
368
447
|
getOrderedChunkCssModules(chunk, chunkGraph, compilation) {
|
369
448
|
return [
|
370
449
|
...this.getModulesInOrder(
|
@@ -388,6 +467,15 @@ class CssModulesPlugin {
|
|
388
467
|
];
|
389
468
|
}
|
390
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
|
+
*/
|
391
479
|
renderChunk({
|
392
480
|
uniqueName,
|
393
481
|
chunk,
|
@@ -396,21 +484,67 @@ class CssModulesPlugin {
|
|
396
484
|
modules
|
397
485
|
}) {
|
398
486
|
const source = new ConcatSource();
|
487
|
+
/** @type {string[]} */
|
399
488
|
const metaData = [];
|
400
489
|
for (const module of modules) {
|
401
490
|
try {
|
402
491
|
const codeGenResult = codeGenerationResults.get(module, chunk.runtime);
|
403
492
|
|
404
|
-
|
493
|
+
let moduleSource =
|
405
494
|
codeGenResult.sources.get("css") ||
|
406
495
|
codeGenResult.sources.get("css-import");
|
407
|
-
|
408
|
-
|
496
|
+
|
497
|
+
let inheritance = [[module.cssLayer, module.supports, module.media]];
|
498
|
+
|
499
|
+
if (module.inheritance) {
|
500
|
+
inheritance.push(...module.inheritance);
|
501
|
+
}
|
502
|
+
|
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
|
+
}
|
532
|
+
}
|
533
|
+
|
534
|
+
if (moduleSource) {
|
535
|
+
source.add(moduleSource);
|
409
536
|
source.add("\n");
|
410
537
|
}
|
538
|
+
/** @type {Map<string, string> | undefined} */
|
411
539
|
const exports =
|
412
540
|
codeGenResult.data && codeGenResult.data.get("css-exports");
|
413
|
-
|
541
|
+
let moduleId = chunkGraph.getModuleId(module) + "";
|
542
|
+
|
543
|
+
// When `optimization.moduleIds` is `named` the module id is a path, so we need to normalize it between platforms
|
544
|
+
if (typeof moduleId === "string") {
|
545
|
+
moduleId = moduleId.replace(/\\/g, "/");
|
546
|
+
}
|
547
|
+
|
414
548
|
metaData.push(
|
415
549
|
`${
|
416
550
|
exports
|
@@ -441,6 +575,11 @@ class CssModulesPlugin {
|
|
441
575
|
return source;
|
442
576
|
}
|
443
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
|
+
*/
|
444
583
|
static getChunkFilenameTemplate(chunk, outputOptions) {
|
445
584
|
if (chunk.cssFilenameTemplate) {
|
446
585
|
return chunk.cssFilenameTemplate;
|
@@ -451,6 +590,11 @@ class CssModulesPlugin {
|
|
451
590
|
}
|
452
591
|
}
|
453
592
|
|
593
|
+
/**
|
594
|
+
* @param {Chunk} chunk chunk
|
595
|
+
* @param {ChunkGraph} chunkGraph chunk graph
|
596
|
+
* @returns {boolean} true, when the chunk has css
|
597
|
+
*/
|
454
598
|
static chunkHasCss(chunk, chunkGraph) {
|
455
599
|
return (
|
456
600
|
!!chunkGraph.getChunkModulesIterableBySourceType(chunk, "css") ||
|