webpack 5.105.3 → 5.106.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.
- package/README.md +3 -6
- package/lib/BannerPlugin.js +13 -13
- package/lib/Chunk.js +25 -0
- package/lib/ChunkGraph.js +8 -4
- package/lib/CleanPlugin.js +23 -20
- package/lib/CompatibilityPlugin.js +1 -1
- package/lib/Compilation.js +36 -13
- package/lib/Compiler.js +59 -1
- package/lib/CssModule.js +17 -2
- package/lib/Dependency.js +1 -1
- package/lib/DllPlugin.js +17 -17
- package/lib/DllReferencePlugin.js +20 -18
- package/lib/DotenvPlugin.js +29 -27
- package/lib/ExternalModule.js +39 -6
- package/lib/FileSystemInfo.js +3 -1
- package/lib/IgnorePlugin.js +12 -11
- package/lib/LoaderOptionsPlugin.js +17 -15
- package/lib/ManifestPlugin.js +27 -25
- package/lib/Module.js +84 -4
- package/lib/ModuleGraph.js +3 -0
- package/lib/ModuleParseError.js +1 -1
- package/lib/ModuleTypeConstants.js +1 -1
- package/lib/MultiStats.js +5 -5
- package/lib/NormalModule.js +7 -3
- package/lib/NormalModuleFactory.js +20 -1
- package/lib/ProgressPlugin.js +39 -29
- package/lib/RuntimeGlobals.js +6 -0
- package/lib/RuntimeModule.js +18 -1
- package/lib/RuntimeTemplate.js +1 -1
- package/lib/SourceMapDevToolPlugin.js +13 -11
- package/lib/Stats.js +3 -2
- package/lib/TemplatedPathPlugin.js +4 -3
- package/lib/WatchIgnorePlugin.js +15 -13
- package/lib/WebpackOptionsApply.js +4 -4
- package/lib/asset/AssetModulesPlugin.js +50 -29
- package/lib/cli.js +3 -1
- package/lib/config/defaults.js +27 -13
- package/lib/config/normalization.js +3 -2
- package/lib/container/ContainerPlugin.js +46 -42
- package/lib/container/ContainerReferencePlugin.js +42 -26
- package/lib/container/FallbackModule.js +1 -1
- package/lib/container/ModuleFederationPlugin.js +17 -13
- package/lib/container/RemoteModule.js +18 -1
- package/lib/css/CssGenerator.js +315 -191
- package/lib/css/CssInjectStyleRuntimeModule.js +179 -0
- package/lib/css/CssLoadingRuntimeModule.js +1 -4
- package/lib/css/CssModulesPlugin.js +197 -98
- package/lib/css/CssParser.js +231 -134
- package/lib/css/walkCssTokens.js +115 -12
- package/lib/debug/ProfilingPlugin.js +16 -13
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +20 -15
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +4 -3
- package/lib/dependencies/CommonJsExportRequireDependency.js +4 -2
- package/lib/dependencies/CommonJsExportsDependency.js +1 -1
- package/lib/dependencies/CommonJsExportsParserPlugin.js +1 -1
- package/lib/dependencies/CommonJsFullRequireDependency.js +1 -1
- package/lib/dependencies/CommonJsImportsParserPlugin.js +63 -2
- package/lib/dependencies/CommonJsRequireContextDependency.js +21 -0
- package/lib/dependencies/CommonJsRequireDependency.js +42 -1
- package/lib/dependencies/CommonJsSelfReferenceDependency.js +1 -1
- package/lib/dependencies/ContextElementDependency.js +1 -1
- package/lib/dependencies/CreateRequireParserPlugin.js +11 -0
- package/lib/dependencies/CssIcssExportDependency.js +210 -87
- package/lib/dependencies/CssIcssImportDependency.js +13 -70
- package/lib/dependencies/CssIcssSymbolDependency.js +19 -30
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +13 -2
- package/lib/dependencies/HarmonyExportExpressionDependency.js +28 -2
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +13 -3
- package/lib/dependencies/HarmonyExportInitFragment.js +1 -1
- package/lib/dependencies/HarmonyImportDependency.js +21 -8
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +124 -205
- package/lib/dependencies/HarmonyImportSideEffectDependency.js +12 -6
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +13 -2
- package/lib/dependencies/ImportContextDependency.js +1 -1
- package/lib/dependencies/ImportDependency.js +16 -2
- package/lib/dependencies/ImportMetaPlugin.js +39 -29
- package/lib/dependencies/ImportParserPlugin.js +4 -5
- package/lib/dependencies/ImportPhase.js +65 -22
- package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +1 -1
- package/lib/esm/ModuleChunkFormatPlugin.js +1 -4
- package/lib/ids/HashedModuleIdsPlugin.js +21 -23
- package/lib/ids/OccurrenceChunkIdsPlugin.js +15 -11
- package/lib/ids/OccurrenceModuleIdsPlugin.js +15 -11
- package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +1 -4
- package/lib/javascript/CommonJsChunkFormatPlugin.js +1 -4
- package/lib/javascript/EnableChunkLoadingPlugin.js +1 -2
- package/lib/javascript/JavascriptModulesPlugin.js +38 -12
- package/lib/javascript/JavascriptParser.js +5 -3
- package/lib/json/JsonModulesPlugin.js +28 -21
- package/lib/library/AssignLibraryPlugin.js +1 -1
- package/lib/library/ExportPropertyLibraryPlugin.js +1 -1
- package/lib/library/ModuleLibraryPlugin.js +35 -13
- package/lib/library/SystemLibraryPlugin.js +1 -1
- package/lib/node/ReadFileCompileAsyncWasmPlugin.js +22 -0
- package/lib/optimize/AggressiveSplittingPlugin.js +18 -31
- package/lib/optimize/ConcatenatedModule.js +6 -2
- package/lib/optimize/InnerGraphPlugin.js +11 -5
- package/lib/optimize/LimitChunkCountPlugin.js +22 -18
- package/lib/optimize/MergeDuplicateChunksPlugin.js +15 -12
- package/lib/optimize/MinChunkSizePlugin.js +20 -16
- package/lib/optimize/ModuleConcatenationPlugin.js +4 -1
- package/lib/optimize/RemoveEmptyChunksPlugin.js +0 -1
- package/lib/rules/RuleSetCompiler.js +1 -0
- package/lib/schemes/HttpUriPlugin.js +20 -11
- package/lib/schemes/VirtualUrlPlugin.js +77 -30
- package/lib/serialization/FileMiddleware.js +7 -7
- package/lib/sharing/ConsumeSharedModule.js +18 -1
- package/lib/sharing/ConsumeSharedPlugin.js +32 -25
- package/lib/sharing/ProvideSharedPlugin.js +29 -25
- package/lib/util/AppendOnlyStackedSet.js +22 -1
- package/lib/util/{propertyName.js → property.js} +26 -1
- package/lib/wasm-async/AsyncWasmCompileRuntimeModule.js +148 -0
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +54 -0
- package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +105 -0
- package/lib/wasm-async/AsyncWebAssemblyParser.js +30 -6
- package/lib/wasm-async/UniversalCompileAsyncWasmPlugin.js +26 -2
- package/lib/web/FetchCompileAsyncWasmPlugin.js +23 -0
- package/lib/web/JsonpTemplatePlugin.js +1 -0
- package/lib/webpack.js +34 -4
- package/package.json +20 -18
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +82 -22
- package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +1 -1
- package/schemas/plugins/css/CssModuleParserOptions.check.js +1 -1
- package/schemas/plugins/css/CssParserOptions.check.js +1 -1
- package/schemas/plugins/optimize/LimitChunkCountPlugin.json +1 -1
- package/schemas/plugins/schemes/VirtualUrlPlugin.check.js +1 -1
- package/schemas/plugins/schemes/VirtualUrlPlugin.json +8 -0
- package/types.d.ts +606 -150
- package/lib/util/create-schema-validation.js +0 -41
- package/lib/util/propertyAccess.js +0 -30
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
/*
|
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
3
|
+
Author Natsu @xiaoxiaojx
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
"use strict";
|
|
7
|
+
|
|
8
|
+
const { SyncWaterfallHook } = require("tapable");
|
|
9
|
+
const Compilation = require("../Compilation");
|
|
10
|
+
const RuntimeGlobals = require("../RuntimeGlobals");
|
|
11
|
+
const RuntimeModule = require("../RuntimeModule");
|
|
12
|
+
const Template = require("../Template");
|
|
13
|
+
|
|
14
|
+
/** @typedef {import("../Chunk")} Chunk */
|
|
15
|
+
/** @typedef {import("../Module").ReadOnlyRuntimeRequirements} ReadOnlyRuntimeRequirements */
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @typedef {object} CssInjectCompilationHooks
|
|
19
|
+
* @property {SyncWaterfallHook<[string, Chunk]>} createStyle
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
/** @type {WeakMap<Compilation, CssInjectCompilationHooks>} */
|
|
23
|
+
const compilationHooksMap = new WeakMap();
|
|
24
|
+
|
|
25
|
+
class CssInjectStyleRuntimeModule extends RuntimeModule {
|
|
26
|
+
/**
|
|
27
|
+
* @param {Compilation} compilation the compilation
|
|
28
|
+
* @returns {CssInjectCompilationHooks} hooks
|
|
29
|
+
*/
|
|
30
|
+
static getCompilationHooks(compilation) {
|
|
31
|
+
if (!(compilation instanceof Compilation)) {
|
|
32
|
+
throw new TypeError(
|
|
33
|
+
"The 'compilation' argument must be an instance of Compilation"
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
let hooks = compilationHooksMap.get(compilation);
|
|
37
|
+
if (hooks === undefined) {
|
|
38
|
+
hooks = {
|
|
39
|
+
createStyle: new SyncWaterfallHook(["source", "chunk"])
|
|
40
|
+
};
|
|
41
|
+
compilationHooksMap.set(compilation, hooks);
|
|
42
|
+
}
|
|
43
|
+
return hooks;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* @param {ReadOnlyRuntimeRequirements} runtimeRequirements runtime requirements
|
|
48
|
+
*/
|
|
49
|
+
constructor(runtimeRequirements) {
|
|
50
|
+
super("css inject style", RuntimeModule.STAGE_ATTACH);
|
|
51
|
+
/** @type {ReadOnlyRuntimeRequirements} */
|
|
52
|
+
this._runtimeRequirements = runtimeRequirements;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* @returns {string | null} runtime code
|
|
57
|
+
*/
|
|
58
|
+
generate() {
|
|
59
|
+
const compilation = /** @type {Compilation} */ (this.compilation);
|
|
60
|
+
const { runtimeTemplate, outputOptions } = compilation;
|
|
61
|
+
const { uniqueName } = outputOptions;
|
|
62
|
+
const { _runtimeRequirements } = this;
|
|
63
|
+
|
|
64
|
+
/** @type {boolean} */
|
|
65
|
+
const withHmr =
|
|
66
|
+
_runtimeRequirements &&
|
|
67
|
+
_runtimeRequirements.has(RuntimeGlobals.hmrDownloadUpdateHandlers);
|
|
68
|
+
|
|
69
|
+
const { createStyle } =
|
|
70
|
+
CssInjectStyleRuntimeModule.getCompilationHooks(compilation);
|
|
71
|
+
|
|
72
|
+
const createStyleElementCode = Template.asString([
|
|
73
|
+
"var style = document.createElement('style');",
|
|
74
|
+
"",
|
|
75
|
+
`if (${RuntimeGlobals.scriptNonce}) {`,
|
|
76
|
+
Template.indent(
|
|
77
|
+
`style.setAttribute("nonce", ${RuntimeGlobals.scriptNonce});`
|
|
78
|
+
),
|
|
79
|
+
"}",
|
|
80
|
+
'style.setAttribute("data-webpack", getDataWebpackId(key));'
|
|
81
|
+
]);
|
|
82
|
+
|
|
83
|
+
return Template.asString([
|
|
84
|
+
`var dataWebpackPrefix = ${uniqueName ? JSON.stringify(`${uniqueName}:`) : '"webpack:"'};`,
|
|
85
|
+
"",
|
|
86
|
+
"function getDataWebpackId(identifier) {",
|
|
87
|
+
Template.indent("return dataWebpackPrefix + identifier;"),
|
|
88
|
+
"}",
|
|
89
|
+
"",
|
|
90
|
+
"function applyStyle(styleElement, css) {",
|
|
91
|
+
Template.indent("styleElement.textContent = css;"),
|
|
92
|
+
"}",
|
|
93
|
+
"",
|
|
94
|
+
"function removeStyleElement(styleElement) {",
|
|
95
|
+
Template.indent([
|
|
96
|
+
"if (styleElement.parentNode) {",
|
|
97
|
+
Template.indent("styleElement.parentNode.removeChild(styleElement);"),
|
|
98
|
+
"}"
|
|
99
|
+
]),
|
|
100
|
+
"}",
|
|
101
|
+
"",
|
|
102
|
+
"function findStyleElement(identifier) {",
|
|
103
|
+
Template.indent([
|
|
104
|
+
"var elements = document.getElementsByTagName('style');",
|
|
105
|
+
"for (var i = 0; i < elements.length; i++) {",
|
|
106
|
+
Template.indent([
|
|
107
|
+
"var el = elements[i];",
|
|
108
|
+
"if (el.getAttribute('data-webpack') === getDataWebpackId(identifier)) {",
|
|
109
|
+
Template.indent("return el;"),
|
|
110
|
+
"}"
|
|
111
|
+
]),
|
|
112
|
+
"}",
|
|
113
|
+
"return null;"
|
|
114
|
+
]),
|
|
115
|
+
"}",
|
|
116
|
+
"",
|
|
117
|
+
"function insertStyleElement(key) {",
|
|
118
|
+
Template.indent([
|
|
119
|
+
createStyle.call(
|
|
120
|
+
createStyleElementCode,
|
|
121
|
+
/** @type {Chunk} */ (this.chunk)
|
|
122
|
+
),
|
|
123
|
+
"",
|
|
124
|
+
"document.head.appendChild(style);",
|
|
125
|
+
"",
|
|
126
|
+
"return style;"
|
|
127
|
+
]),
|
|
128
|
+
"}",
|
|
129
|
+
"",
|
|
130
|
+
`${RuntimeGlobals.cssInjectStyle} = ${runtimeTemplate.basicFunction(
|
|
131
|
+
"identifier, css",
|
|
132
|
+
[
|
|
133
|
+
"var element = findStyleElement(identifier);",
|
|
134
|
+
"if (element) {",
|
|
135
|
+
Template.indent("applyStyle(element, css);"),
|
|
136
|
+
"} else {",
|
|
137
|
+
Template.indent([
|
|
138
|
+
"var element = insertStyleElement(identifier);",
|
|
139
|
+
"applyStyle(element, css);"
|
|
140
|
+
]),
|
|
141
|
+
"}"
|
|
142
|
+
]
|
|
143
|
+
)};`,
|
|
144
|
+
"",
|
|
145
|
+
`${RuntimeGlobals.cssInjectStyle}.removeModules = ${runtimeTemplate.basicFunction(
|
|
146
|
+
"removedModules",
|
|
147
|
+
[
|
|
148
|
+
"if (!removedModules) return;",
|
|
149
|
+
"var identifiers = Array.isArray(removedModules) ? removedModules : [removedModules];",
|
|
150
|
+
"for (var i = 0; i < identifiers.length; i++) {",
|
|
151
|
+
Template.indent([
|
|
152
|
+
"var identifier = identifiers[i];",
|
|
153
|
+
"var element = findStyleElement(identifier);",
|
|
154
|
+
"if (element) {",
|
|
155
|
+
Template.indent("removeStyleElement(element);"),
|
|
156
|
+
"}"
|
|
157
|
+
]),
|
|
158
|
+
"}"
|
|
159
|
+
]
|
|
160
|
+
)};`,
|
|
161
|
+
withHmr
|
|
162
|
+
? Template.asString([
|
|
163
|
+
`${RuntimeGlobals.hmrDownloadUpdateHandlers}.cssInjectStyle = ${runtimeTemplate.basicFunction(
|
|
164
|
+
"chunkIds, removedChunks, removedModules, promises, applyHandlers, updatedModulesList, css",
|
|
165
|
+
[
|
|
166
|
+
"if (removedModules) {",
|
|
167
|
+
Template.indent(
|
|
168
|
+
`${RuntimeGlobals.cssInjectStyle}.removeModules(removedModules);`
|
|
169
|
+
),
|
|
170
|
+
"}"
|
|
171
|
+
]
|
|
172
|
+
)};`
|
|
173
|
+
])
|
|
174
|
+
: "// no css inject style HMR download handler"
|
|
175
|
+
]);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
module.exports = CssInjectStyleRuntimeModule;
|
|
@@ -121,16 +121,13 @@ class CssLoadingRuntimeModule extends RuntimeModule {
|
|
|
121
121
|
(environment.document || isNeutralPlatform) &&
|
|
122
122
|
chunk.hasChildByOrder(chunkGraph, "preload", true, chunkHasCss);
|
|
123
123
|
|
|
124
|
-
const { linkPreload, linkPrefetch } =
|
|
124
|
+
const { linkPreload, linkPrefetch, createStylesheet } =
|
|
125
125
|
CssLoadingRuntimeModule.getCompilationHooks(compilation);
|
|
126
126
|
|
|
127
127
|
const withFetchPriority = _runtimeRequirements.has(
|
|
128
128
|
RuntimeGlobals.hasFetchPriority
|
|
129
129
|
);
|
|
130
130
|
|
|
131
|
-
const { createStylesheet } =
|
|
132
|
-
CssLoadingRuntimeModule.getCompilationHooks(compilation);
|
|
133
|
-
|
|
134
131
|
const stateExpression = withHmr
|
|
135
132
|
? `${RuntimeGlobals.hmrRuntimeStatePrefix}_css`
|
|
136
133
|
: undefined;
|
|
@@ -36,16 +36,16 @@ const CssUrlDependency = require("../dependencies/CssUrlDependency");
|
|
|
36
36
|
const StaticExportsDependency = require("../dependencies/StaticExportsDependency");
|
|
37
37
|
const JavascriptModulesPlugin = require("../javascript/JavascriptModulesPlugin");
|
|
38
38
|
const { compareModulesByFullName } = require("../util/comparators");
|
|
39
|
-
const createSchemaValidation = require("../util/create-schema-validation");
|
|
40
39
|
const createHash = require("../util/createHash");
|
|
41
40
|
const { getUndoPath } = require("../util/identifier");
|
|
42
41
|
const memoize = require("../util/memoize");
|
|
43
42
|
const nonNumericOnlyHash = require("../util/nonNumericOnlyHash");
|
|
44
43
|
const removeBOM = require("../util/removeBOM");
|
|
45
44
|
const CssGenerator = require("./CssGenerator");
|
|
46
|
-
const CssMergeStyleSheetsRuntimeModule = require("./CssMergeStyleSheetsRuntimeModule");
|
|
47
45
|
const CssParser = require("./CssParser");
|
|
48
46
|
|
|
47
|
+
const publicPathAutoRegex = new RegExp(CssUrlDependency.PUBLIC_PATH_AUTO, "g");
|
|
48
|
+
|
|
49
49
|
/** @typedef {import("webpack-sources").Source} Source */
|
|
50
50
|
/** @typedef {import("../config/defaults").OutputNormalizedWithDefaults} OutputOptions */
|
|
51
51
|
/** @typedef {import("../Chunk")} Chunk */
|
|
@@ -101,6 +101,12 @@ const CssParser = require("./CssParser");
|
|
|
101
101
|
const getCssLoadingRuntimeModule = memoize(() =>
|
|
102
102
|
require("./CssLoadingRuntimeModule")
|
|
103
103
|
);
|
|
104
|
+
const getCssMergeStyleSheetsRuntimeModule = memoize(() =>
|
|
105
|
+
require("./CssMergeStyleSheetsRuntimeModule")
|
|
106
|
+
);
|
|
107
|
+
const getCssInjectStyleRuntimeModule = memoize(() =>
|
|
108
|
+
require("./CssInjectStyleRuntimeModule")
|
|
109
|
+
);
|
|
104
110
|
|
|
105
111
|
/**
|
|
106
112
|
* @param {string} name name
|
|
@@ -115,58 +121,14 @@ const getSchema = (name) => {
|
|
|
115
121
|
};
|
|
116
122
|
};
|
|
117
123
|
|
|
118
|
-
const generatorValidationOptions = {
|
|
119
|
-
name: "Css Modules Plugin",
|
|
120
|
-
baseDataPath: "generator"
|
|
121
|
-
};
|
|
122
|
-
const validateGeneratorOptions = {
|
|
123
|
-
css: createSchemaValidation(
|
|
124
|
-
require("../../schemas/plugins/css/CssGeneratorOptions.check"),
|
|
125
|
-
() => getSchema("CssGeneratorOptions"),
|
|
126
|
-
generatorValidationOptions
|
|
127
|
-
),
|
|
128
|
-
"css/auto": createSchemaValidation(
|
|
129
|
-
require("../../schemas/plugins/css/CssModuleGeneratorOptions.check"),
|
|
130
|
-
() => getSchema("CssModuleGeneratorOptions"),
|
|
131
|
-
generatorValidationOptions
|
|
132
|
-
),
|
|
133
|
-
"css/module": createSchemaValidation(
|
|
134
|
-
require("../../schemas/plugins/css/CssModuleGeneratorOptions.check"),
|
|
135
|
-
() => getSchema("CssModuleGeneratorOptions"),
|
|
136
|
-
generatorValidationOptions
|
|
137
|
-
),
|
|
138
|
-
"css/global": createSchemaValidation(
|
|
139
|
-
require("../../schemas/plugins/css/CssModuleGeneratorOptions.check"),
|
|
140
|
-
() => getSchema("CssModuleGeneratorOptions"),
|
|
141
|
-
generatorValidationOptions
|
|
142
|
-
)
|
|
143
|
-
};
|
|
144
|
-
|
|
145
124
|
const parserValidationOptions = {
|
|
146
125
|
name: "Css Modules Plugin",
|
|
147
126
|
baseDataPath: "parser"
|
|
148
127
|
};
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
parserValidationOptions
|
|
154
|
-
),
|
|
155
|
-
"css/auto": createSchemaValidation(
|
|
156
|
-
require("../../schemas/plugins/css/CssModuleParserOptions.check"),
|
|
157
|
-
() => getSchema("CssModuleParserOptions"),
|
|
158
|
-
parserValidationOptions
|
|
159
|
-
),
|
|
160
|
-
"css/module": createSchemaValidation(
|
|
161
|
-
require("../../schemas/plugins/css/CssModuleParserOptions.check"),
|
|
162
|
-
() => getSchema("CssModuleParserOptions"),
|
|
163
|
-
parserValidationOptions
|
|
164
|
-
),
|
|
165
|
-
"css/global": createSchemaValidation(
|
|
166
|
-
require("../../schemas/plugins/css/CssModuleParserOptions.check"),
|
|
167
|
-
() => getSchema("CssModuleParserOptions"),
|
|
168
|
-
parserValidationOptions
|
|
169
|
-
)
|
|
128
|
+
|
|
129
|
+
const generatorValidationOptions = {
|
|
130
|
+
name: "Css Modules Plugin",
|
|
131
|
+
baseDataPath: "generator"
|
|
170
132
|
};
|
|
171
133
|
|
|
172
134
|
/** @type {WeakMap<Compilation, CompilationHooks>} */
|
|
@@ -260,38 +222,126 @@ class CssModulesPlugin {
|
|
|
260
222
|
normalModuleFactory.hooks.createParser
|
|
261
223
|
.for(type)
|
|
262
224
|
.tap(PLUGIN_NAME, (parserOptions) => {
|
|
225
|
+
/** @type {undefined | "global" | "local" | "auto"} */
|
|
226
|
+
let defaultMode;
|
|
227
|
+
|
|
263
228
|
switch (type) {
|
|
264
|
-
case CSS_MODULE_TYPE:
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
229
|
+
case CSS_MODULE_TYPE: {
|
|
230
|
+
compiler.validate(
|
|
231
|
+
() => getSchema("CssParserOptions"),
|
|
232
|
+
parserOptions,
|
|
233
|
+
parserValidationOptions,
|
|
234
|
+
(options) =>
|
|
235
|
+
require("../../schemas/plugins/css/CssParserOptions.check")(
|
|
236
|
+
options
|
|
237
|
+
)
|
|
238
|
+
);
|
|
239
|
+
|
|
240
|
+
break;
|
|
241
|
+
}
|
|
242
|
+
case CSS_MODULE_TYPE_GLOBAL: {
|
|
243
|
+
defaultMode = "global";
|
|
244
|
+
compiler.validate(
|
|
245
|
+
() => getSchema("CssModuleParserOptions"),
|
|
246
|
+
parserOptions,
|
|
247
|
+
parserValidationOptions,
|
|
248
|
+
(options) =>
|
|
249
|
+
require("../../schemas/plugins/css/CssModuleParserOptions.check")(
|
|
250
|
+
options
|
|
251
|
+
)
|
|
252
|
+
);
|
|
253
|
+
break;
|
|
254
|
+
}
|
|
255
|
+
case CSS_MODULE_TYPE_MODULE: {
|
|
256
|
+
defaultMode = "local";
|
|
257
|
+
compiler.validate(
|
|
258
|
+
() => getSchema("CssModuleParserOptions"),
|
|
259
|
+
parserOptions,
|
|
260
|
+
parserValidationOptions,
|
|
261
|
+
(options) =>
|
|
262
|
+
require("../../schemas/plugins/css/CssModuleParserOptions.check")(
|
|
263
|
+
options
|
|
264
|
+
)
|
|
265
|
+
);
|
|
266
|
+
break;
|
|
267
|
+
}
|
|
268
|
+
case CSS_MODULE_TYPE_AUTO: {
|
|
269
|
+
defaultMode = "auto";
|
|
270
|
+
compiler.validate(
|
|
271
|
+
() => getSchema("CssModuleParserOptions"),
|
|
272
|
+
parserOptions,
|
|
273
|
+
parserValidationOptions,
|
|
274
|
+
(options) =>
|
|
275
|
+
require("../../schemas/plugins/css/CssModuleParserOptions.check")(
|
|
276
|
+
options
|
|
277
|
+
)
|
|
278
|
+
);
|
|
279
|
+
break;
|
|
280
|
+
}
|
|
289
281
|
}
|
|
282
|
+
|
|
283
|
+
return new CssParser({
|
|
284
|
+
defaultMode,
|
|
285
|
+
...parserOptions
|
|
286
|
+
});
|
|
290
287
|
});
|
|
291
288
|
normalModuleFactory.hooks.createGenerator
|
|
292
289
|
.for(type)
|
|
293
290
|
.tap(PLUGIN_NAME, (generatorOptions) => {
|
|
294
|
-
|
|
291
|
+
switch (type) {
|
|
292
|
+
case CSS_MODULE_TYPE: {
|
|
293
|
+
compiler.validate(
|
|
294
|
+
() => getSchema("CssGeneratorOptions"),
|
|
295
|
+
generatorOptions,
|
|
296
|
+
generatorValidationOptions,
|
|
297
|
+
(options) =>
|
|
298
|
+
require("../../schemas/plugins/css/CssGeneratorOptions.check")(
|
|
299
|
+
options
|
|
300
|
+
)
|
|
301
|
+
);
|
|
302
|
+
|
|
303
|
+
break;
|
|
304
|
+
}
|
|
305
|
+
case CSS_MODULE_TYPE_GLOBAL: {
|
|
306
|
+
compiler.validate(
|
|
307
|
+
() => getSchema("CssModuleGeneratorOptions"),
|
|
308
|
+
generatorOptions,
|
|
309
|
+
generatorValidationOptions,
|
|
310
|
+
(options) =>
|
|
311
|
+
require("../../schemas/plugins/css/CssModuleGeneratorOptions.check")(
|
|
312
|
+
options
|
|
313
|
+
)
|
|
314
|
+
);
|
|
315
|
+
|
|
316
|
+
break;
|
|
317
|
+
}
|
|
318
|
+
case CSS_MODULE_TYPE_MODULE: {
|
|
319
|
+
compiler.validate(
|
|
320
|
+
() => getSchema("CssModuleGeneratorOptions"),
|
|
321
|
+
generatorOptions,
|
|
322
|
+
generatorValidationOptions,
|
|
323
|
+
(options) =>
|
|
324
|
+
require("../../schemas/plugins/css/CssModuleGeneratorOptions.check")(
|
|
325
|
+
options
|
|
326
|
+
)
|
|
327
|
+
);
|
|
328
|
+
|
|
329
|
+
break;
|
|
330
|
+
}
|
|
331
|
+
case CSS_MODULE_TYPE_AUTO: {
|
|
332
|
+
compiler.validate(
|
|
333
|
+
() => getSchema("CssModuleGeneratorOptions"),
|
|
334
|
+
generatorOptions,
|
|
335
|
+
generatorValidationOptions,
|
|
336
|
+
(options) =>
|
|
337
|
+
require("../../schemas/plugins/css/CssModuleGeneratorOptions.check")(
|
|
338
|
+
options
|
|
339
|
+
)
|
|
340
|
+
);
|
|
341
|
+
|
|
342
|
+
break;
|
|
343
|
+
}
|
|
344
|
+
}
|
|
295
345
|
|
|
296
346
|
return new CssGenerator(
|
|
297
347
|
generatorOptions,
|
|
@@ -301,6 +351,9 @@ class CssModulesPlugin {
|
|
|
301
351
|
normalModuleFactory.hooks.createModuleClass
|
|
302
352
|
.for(type)
|
|
303
353
|
.tap(PLUGIN_NAME, (createData, resolveData) => {
|
|
354
|
+
const exportType =
|
|
355
|
+
/** @type {CssParser} */
|
|
356
|
+
(createData.parser).options.exportType;
|
|
304
357
|
if (resolveData.dependencies.length > 0) {
|
|
305
358
|
// When CSS is imported from CSS there is only one dependency
|
|
306
359
|
const dependency = resolveData.dependencies[0];
|
|
@@ -345,7 +398,8 @@ class CssModulesPlugin {
|
|
|
345
398
|
cssLayer: dependency.layer,
|
|
346
399
|
supports: dependency.supports,
|
|
347
400
|
media: dependency.media,
|
|
348
|
-
inheritance
|
|
401
|
+
inheritance,
|
|
402
|
+
exportType: exportType || parent.exportType
|
|
349
403
|
})
|
|
350
404
|
);
|
|
351
405
|
}
|
|
@@ -356,7 +410,8 @@ class CssModulesPlugin {
|
|
|
356
410
|
...createData,
|
|
357
411
|
cssLayer: dependency.layer,
|
|
358
412
|
supports: dependency.supports,
|
|
359
|
-
media: dependency.media
|
|
413
|
+
media: dependency.media,
|
|
414
|
+
exportType
|
|
360
415
|
})
|
|
361
416
|
);
|
|
362
417
|
}
|
|
@@ -364,7 +419,12 @@ class CssModulesPlugin {
|
|
|
364
419
|
|
|
365
420
|
return new CssModule(
|
|
366
421
|
/** @type {CSSModuleCreateData} */
|
|
367
|
-
(
|
|
422
|
+
(
|
|
423
|
+
/** @type {unknown} */ ({
|
|
424
|
+
...createData,
|
|
425
|
+
exportType
|
|
426
|
+
})
|
|
427
|
+
)
|
|
368
428
|
);
|
|
369
429
|
});
|
|
370
430
|
|
|
@@ -386,10 +446,9 @@ class CssModulesPlugin {
|
|
|
386
446
|
compilation
|
|
387
447
|
).renderModuleContent.tap(PLUGIN_NAME, (source, module) => {
|
|
388
448
|
if (module instanceof CssModule && module.hot) {
|
|
389
|
-
const exportType =
|
|
390
|
-
.exportType;
|
|
449
|
+
const exportType = module.exportType;
|
|
391
450
|
// When exportType !== "link", modules behave like JavaScript modules
|
|
392
|
-
if (exportType &&
|
|
451
|
+
if (exportType && !["link", "style"].includes(exportType)) {
|
|
393
452
|
return source;
|
|
394
453
|
}
|
|
395
454
|
// For exportType === "link", we can optimize with self-acceptance
|
|
@@ -398,13 +457,13 @@ class CssModulesPlugin {
|
|
|
398
457
|
return source;
|
|
399
458
|
}
|
|
400
459
|
const exports = cssData.exports;
|
|
460
|
+
/** @type {Record<string, string>} */
|
|
461
|
+
const exportsObj = {};
|
|
462
|
+
for (const [key, value] of exports) {
|
|
463
|
+
exportsObj[key] = value;
|
|
464
|
+
}
|
|
401
465
|
const stringifiedExports = JSON.stringify(
|
|
402
|
-
JSON.stringify(
|
|
403
|
-
[...exports].reduce((obj, [key, value]) => {
|
|
404
|
-
obj[key] = value;
|
|
405
|
-
return obj;
|
|
406
|
-
}, /** @type {Record<string, string>} */ ({}))
|
|
407
|
-
)
|
|
466
|
+
JSON.stringify(exportsObj)
|
|
408
467
|
);
|
|
409
468
|
|
|
410
469
|
const hmrCode = Template.asString([
|
|
@@ -416,7 +475,11 @@ class CssModulesPlugin {
|
|
|
416
475
|
"} else {",
|
|
417
476
|
Template.indent("module.hot.accept();"),
|
|
418
477
|
"}",
|
|
419
|
-
"module.hot.dispose(function(data) {
|
|
478
|
+
"module.hot.dispose(function(data) {",
|
|
479
|
+
Template.indent([
|
|
480
|
+
"data.__webpack_css_exports__ = __webpack_css_exports__;"
|
|
481
|
+
]),
|
|
482
|
+
"});"
|
|
420
483
|
]);
|
|
421
484
|
|
|
422
485
|
return new ConcatSource(source, "\n", new RawSource(hmrCode));
|
|
@@ -595,11 +658,24 @@ class CssModulesPlugin {
|
|
|
595
658
|
compilation.hooks.runtimeRequirementInTree
|
|
596
659
|
.for(RuntimeGlobals.cssMergeStyleSheets)
|
|
597
660
|
.tap(PLUGIN_NAME, (chunk) => {
|
|
661
|
+
const CssMergeStyleSheetsRuntimeModule =
|
|
662
|
+
getCssMergeStyleSheetsRuntimeModule();
|
|
598
663
|
compilation.addRuntimeModule(
|
|
599
664
|
chunk,
|
|
600
665
|
new CssMergeStyleSheetsRuntimeModule()
|
|
601
666
|
);
|
|
602
667
|
});
|
|
668
|
+
|
|
669
|
+
compilation.hooks.runtimeRequirementInTree
|
|
670
|
+
.for(RuntimeGlobals.cssInjectStyle)
|
|
671
|
+
.tap(PLUGIN_NAME, (chunk, set) => {
|
|
672
|
+
const CssInjectStyleRuntimeModule =
|
|
673
|
+
getCssInjectStyleRuntimeModule();
|
|
674
|
+
compilation.addRuntimeModule(
|
|
675
|
+
chunk,
|
|
676
|
+
new CssInjectStyleRuntimeModule(set)
|
|
677
|
+
);
|
|
678
|
+
});
|
|
603
679
|
}
|
|
604
680
|
);
|
|
605
681
|
}
|
|
@@ -694,18 +770,43 @@ class CssModulesPlugin {
|
|
|
694
770
|
break;
|
|
695
771
|
}
|
|
696
772
|
if (hasFailed) {
|
|
773
|
+
const fallbackModule = /** @type {Module} */ (hasFailed);
|
|
774
|
+
|
|
775
|
+
const fallbackIssuers = [
|
|
776
|
+
...compilation.moduleGraph
|
|
777
|
+
.getIncomingConnectionsByOriginModule(fallbackModule)
|
|
778
|
+
.keys()
|
|
779
|
+
].filter(Boolean);
|
|
780
|
+
|
|
781
|
+
const selectedIssuers = [
|
|
782
|
+
...compilation.moduleGraph
|
|
783
|
+
.getIncomingConnectionsByOriginModule(selectedModule)
|
|
784
|
+
.keys()
|
|
785
|
+
].filter(Boolean);
|
|
786
|
+
|
|
787
|
+
const allIssuers = [
|
|
788
|
+
...new Set([...fallbackIssuers, ...selectedIssuers])
|
|
789
|
+
]
|
|
790
|
+
.map((m) =>
|
|
791
|
+
/** @type {Module} */ (m).readableIdentifier(
|
|
792
|
+
compilation.requestShortener
|
|
793
|
+
)
|
|
794
|
+
)
|
|
795
|
+
.sort();
|
|
796
|
+
|
|
697
797
|
// There is a not resolve-able conflict with the selectedModule
|
|
698
|
-
// TODO print better warning
|
|
699
798
|
compilation.warnings.push(
|
|
700
799
|
new WebpackError(
|
|
701
|
-
`chunk ${
|
|
800
|
+
`chunk ${
|
|
801
|
+
chunk.name || chunk.id
|
|
802
|
+
}\nConflicting order between ${fallbackModule.readableIdentifier(
|
|
702
803
|
compilation.requestShortener
|
|
703
804
|
)} and ${selectedModule.readableIdentifier(
|
|
704
805
|
compilation.requestShortener
|
|
705
|
-
)}`
|
|
806
|
+
)}\nCSS modules are imported in:\n - ${allIssuers.join("\n - ")}`
|
|
706
807
|
)
|
|
707
808
|
);
|
|
708
|
-
selectedModule =
|
|
809
|
+
selectedModule = fallbackModule;
|
|
709
810
|
}
|
|
710
811
|
// Insert the selected module into the final modules list
|
|
711
812
|
finalModules.push(selectedModule);
|
|
@@ -774,6 +875,7 @@ class CssModulesPlugin {
|
|
|
774
875
|
if (
|
|
775
876
|
cacheEntry &&
|
|
776
877
|
cacheEntry.undoPath === undoPath &&
|
|
878
|
+
cacheEntry.inheritance.length === inheritance.length &&
|
|
777
879
|
cacheEntry.inheritance.every(([layer, supports, media], i) => {
|
|
778
880
|
const item = inheritance[i];
|
|
779
881
|
if (Array.isArray(item)) {
|
|
@@ -788,10 +890,7 @@ class CssModulesPlugin {
|
|
|
788
890
|
const moduleSourceCode =
|
|
789
891
|
/** @type {string} */
|
|
790
892
|
(moduleSourceContent.source());
|
|
791
|
-
|
|
792
|
-
CssUrlDependency.PUBLIC_PATH_AUTO,
|
|
793
|
-
"g"
|
|
794
|
-
);
|
|
893
|
+
publicPathAutoRegex.lastIndex = 0;
|
|
795
894
|
/** @type {Source} */
|
|
796
895
|
let moduleSource = new ReplaceSource(moduleSourceContent);
|
|
797
896
|
/** @type {null | RegExpExecArray} */
|
|
@@ -799,7 +898,7 @@ class CssModulesPlugin {
|
|
|
799
898
|
while ((match = publicPathAutoRegex.exec(moduleSourceCode))) {
|
|
800
899
|
/** @type {ReplaceSource} */ (moduleSource).replace(
|
|
801
900
|
match.index,
|
|
802
|
-
|
|
901
|
+
match.index + match[0].length - 1,
|
|
803
902
|
undoPath
|
|
804
903
|
);
|
|
805
904
|
}
|