webpack 5.106.2 → 5.107.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 +2 -2
- package/lib/APIPlugin.js +1 -1
- package/lib/Cache.js +3 -6
- package/lib/CompatibilityPlugin.js +8 -7
- package/lib/Compilation.js +34 -26
- package/lib/Compiler.js +4 -13
- package/lib/ContextModule.js +2 -2
- package/lib/DefinePlugin.js +2 -2
- package/lib/Dependency.js +22 -1
- package/lib/DependencyTemplate.js +2 -1
- package/lib/EnvironmentPlugin.js +1 -1
- package/lib/EvalSourceMapDevToolPlugin.js +8 -9
- package/lib/ExternalModule.js +76 -15
- package/lib/ExternalModuleFactoryPlugin.js +5 -0
- package/lib/FileSystemInfo.js +187 -72
- package/lib/Generator.js +3 -3
- package/lib/HotModuleReplacementPlugin.js +26 -8
- package/lib/IgnorePlugin.js +2 -1
- package/lib/Module.js +19 -18
- package/lib/ModuleFactory.js +1 -1
- package/lib/ModuleSourceTypeConstants.js +31 -1
- package/lib/ModuleTypeConstants.js +12 -3
- package/lib/MultiCompiler.js +2 -2
- package/lib/NodeStuffPlugin.js +1 -1
- package/lib/NormalModule.js +13 -31
- package/lib/NormalModuleFactory.js +10 -2
- package/lib/Parser.js +1 -1
- package/lib/ProgressPlugin.js +129 -56
- package/lib/RuntimeGlobals.js +5 -5
- package/lib/RuntimeModule.js +9 -7
- package/lib/RuntimePlugin.js +11 -0
- package/lib/WarnCaseSensitiveModulesPlugin.js +70 -2
- package/lib/WarnDeprecatedOptionPlugin.js +1 -1
- package/lib/WarnNoModeSetPlugin.js +16 -1
- package/lib/Watching.js +2 -3
- package/lib/WebpackError.js +3 -77
- package/lib/WebpackIsIncludedPlugin.js +1 -1
- package/lib/WebpackOptionsApply.js +13 -1
- package/lib/asset/AssetBytesGenerator.js +6 -2
- package/lib/asset/AssetGenerator.js +22 -8
- package/lib/asset/AssetModulesPlugin.js +3 -1
- package/lib/asset/AssetSourceGenerator.js +6 -2
- package/lib/buildChunkGraph.js +4 -6
- package/lib/cache/PackFileCacheStrategy.js +4 -4
- package/lib/cli.js +3 -1
- package/lib/config/defaults.js +197 -10
- package/lib/config/normalization.js +3 -1
- package/lib/css/CssGenerator.js +320 -105
- package/lib/css/CssInjectStyleRuntimeModule.js +44 -42
- package/lib/css/CssLoadingRuntimeModule.js +22 -4
- package/lib/{CssModule.js → css/CssModule.js} +15 -15
- package/lib/css/CssModulesPlugin.js +166 -86
- package/lib/css/CssParser.js +566 -269
- package/lib/css/walkCssTokens.js +148 -2
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +1 -1
- package/lib/dependencies/CommonJsDependencyHelpers.js +63 -0
- package/lib/dependencies/CommonJsExportRequireDependency.js +54 -10
- package/lib/dependencies/CommonJsExportsParserPlugin.js +1 -1
- package/lib/dependencies/CommonJsFullRequireDependency.js +32 -9
- package/lib/dependencies/CommonJsImportsParserPlugin.js +4 -3
- package/lib/dependencies/CommonJsRequireDependency.js +67 -4
- package/lib/dependencies/ContextDependency.js +1 -1
- package/lib/dependencies/ContextDependencyHelpers.js +1 -1
- package/lib/dependencies/CreateRequireParserPlugin.js +1 -1
- package/lib/dependencies/CriticalDependencyWarning.js +1 -1
- package/lib/dependencies/CssIcssExportDependency.js +332 -67
- package/lib/dependencies/CssIcssImportDependency.js +49 -7
- package/lib/dependencies/CssIcssSymbolDependency.js +11 -3
- package/lib/dependencies/CssImportDependency.js +8 -0
- package/lib/dependencies/CssUrlDependency.js +25 -0
- package/lib/dependencies/HarmonyDetectionParserPlugin.js +1 -1
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +8 -7
- package/lib/dependencies/HarmonyExportExpressionDependency.js +22 -14
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +110 -3
- package/lib/dependencies/HarmonyImportDependency.js +10 -2
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +22 -1
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +1 -1
- package/lib/{HarmonyLinkingError.js → dependencies/HarmonyLinkingError.js} +5 -3
- package/lib/dependencies/HtmlInlineScriptDependency.js +133 -0
- package/lib/dependencies/HtmlInlineStyleDependency.js +101 -0
- package/lib/dependencies/HtmlScriptSrcDependency.js +318 -0
- package/lib/dependencies/HtmlSourceDependency.js +127 -0
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +1 -1
- package/lib/dependencies/ImportParserPlugin.js +2 -2
- package/lib/dependencies/ImportPhase.js +1 -1
- package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +1 -1
- package/lib/{RequireJsStuffPlugin.js → dependencies/RequireJsStuffPlugin.js} +7 -7
- package/lib/dependencies/SystemPlugin.js +1 -1
- package/lib/dependencies/WebAssemblyImportDependency.js +1 -1
- package/lib/dependencies/WorkerPlugin.js +2 -2
- package/lib/{DelegatedModule.js → dll/DelegatedModule.js} +31 -31
- package/lib/{DelegatedModuleFactoryPlugin.js → dll/DelegatedModuleFactoryPlugin.js} +4 -4
- package/lib/{DelegatedPlugin.js → dll/DelegatedPlugin.js} +2 -2
- package/lib/{DllEntryPlugin.js → dll/DllEntryPlugin.js} +4 -4
- package/lib/{DllModule.js → dll/DllModule.js} +24 -24
- package/lib/{DllModuleFactory.js → dll/DllModuleFactory.js} +4 -4
- package/lib/{DllPlugin.js → dll/DllPlugin.js} +6 -5
- package/lib/{DllReferencePlugin.js → dll/DllReferencePlugin.js} +14 -14
- package/lib/{LibManifestPlugin.js → dll/LibManifestPlugin.js} +9 -9
- package/lib/{AsyncDependencyToInitialChunkError.js → errors/AsyncDependencyToInitialChunkError.js} +2 -2
- package/lib/errors/BuildCycleError.js +1 -1
- package/lib/{ChunkRenderError.js → errors/ChunkRenderError.js} +1 -1
- package/lib/{CodeGenerationError.js → errors/CodeGenerationError.js} +1 -1
- package/lib/{CommentCompilationWarning.js → errors/CommentCompilationWarning.js} +3 -3
- package/lib/{ConcurrentCompilationError.js → errors/ConcurrentCompilationError.js} +4 -2
- package/lib/{EnvironmentNotSupportAsyncWarning.js → errors/EnvironmentNotSupportAsyncWarning.js} +4 -4
- package/lib/{HookWebpackError.js → errors/HookWebpackError.js} +5 -5
- package/lib/{IgnoreErrorModuleFactory.js → errors/IgnoreErrorModuleFactory.js} +4 -4
- package/lib/{InvalidDependenciesModuleWarning.js → errors/InvalidDependenciesModuleWarning.js} +3 -3
- package/lib/errors/JSONParseError.js +114 -0
- package/lib/{ModuleBuildError.js → errors/ModuleBuildError.js} +5 -5
- package/lib/{ModuleDependencyError.js → errors/ModuleDependencyError.js} +2 -2
- package/lib/{ModuleDependencyWarning.js → errors/ModuleDependencyWarning.js} +4 -4
- package/lib/{ModuleError.js → errors/ModuleError.js} +5 -5
- package/lib/{ModuleHashingError.js → errors/ModuleHashingError.js} +1 -1
- package/lib/{ModuleNotFoundError.js → errors/ModuleNotFoundError.js} +2 -2
- package/lib/{ModuleParseError.js → errors/ModuleParseError.js} +8 -6
- package/lib/{ModuleRestoreError.js → errors/ModuleRestoreError.js} +1 -1
- package/lib/{ModuleStoreError.js → errors/ModuleStoreError.js} +1 -1
- package/lib/{ModuleWarning.js → errors/ModuleWarning.js} +5 -5
- package/lib/{NodeStuffInWebError.js → errors/NodeStuffInWebError.js} +4 -4
- package/lib/errors/NonErrorEmittedError.js +28 -0
- package/lib/{UnhandledSchemeError.js → errors/UnhandledSchemeError.js} +2 -2
- package/lib/{UnsupportedFeatureWarning.js → errors/UnsupportedFeatureWarning.js} +3 -3
- package/lib/errors/WebpackError.js +84 -0
- package/lib/html/HtmlGenerator.js +379 -0
- package/lib/html/HtmlModulesPlugin.js +433 -0
- package/lib/html/HtmlParser.js +1489 -0
- package/lib/html/walkHtmlTokens.js +2733 -0
- package/lib/ids/IdHelpers.js +2 -1
- package/lib/index.js +34 -15
- package/lib/javascript/JavascriptModulesPlugin.js +89 -8
- package/lib/javascript/JavascriptParser.js +197 -16
- package/lib/javascript/JavascriptParserHelpers.js +1 -1
- package/lib/json/JsonParser.js +7 -16
- package/lib/library/AbstractLibraryPlugin.js +1 -1
- package/lib/library/EnableLibraryPlugin.js +1 -1
- package/lib/{FalseIIFEUmdWarning.js → library/FalseIIFEUmdWarning.js} +1 -1
- package/lib/library/ModuleLibraryPlugin.js +74 -0
- package/lib/node/NodeEnvironmentPlugin.js +4 -2
- package/lib/node/nodeConsole.js +113 -64
- package/lib/optimize/ConcatenatedModule.js +51 -6
- package/lib/optimize/InnerGraph.js +1 -1
- package/lib/optimize/InnerGraphPlugin.js +11 -1
- package/lib/optimize/MinMaxSizeWarning.js +4 -4
- package/lib/optimize/ModuleConcatenationPlugin.js +15 -7
- package/lib/optimize/RealContentHashPlugin.js +89 -26
- package/lib/optimize/SideEffectsFlagPlugin.js +111 -3
- package/lib/optimize/SplitChunksPlugin.js +1 -1
- package/lib/performance/AssetsOverSizeLimitWarning.js +2 -2
- package/lib/performance/EntrypointsOverSizeLimitWarning.js +2 -2
- package/lib/performance/NoAsyncChunksWarning.js +5 -3
- package/lib/performance/SizeLimitsPlugin.js +1 -1
- package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +4 -1
- package/lib/rules/UseEffectRulePlugin.js +4 -3
- package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +119 -13
- package/lib/runtime/SetAnonymousDefaultNameRuntimeModule.js +35 -0
- package/lib/schemes/DataUriPlugin.js +13 -1
- package/lib/schemes/VirtualUrlPlugin.js +1 -1
- package/lib/serialization/SerializerMiddleware.js +2 -2
- package/lib/sharing/ConsumeSharedPlugin.js +2 -2
- package/lib/sharing/ConsumeSharedRuntimeModule.js +8 -4
- package/lib/sharing/ProvideSharedModule.js +1 -1
- package/lib/sharing/ProvideSharedPlugin.js +1 -1
- package/lib/sharing/resolveMatchedConfigs.js +1 -1
- package/lib/stats/DefaultStatsFactoryPlugin.js +2 -2
- package/lib/stats/DefaultStatsPresetPlugin.js +1 -1
- package/lib/stats/DefaultStatsPrinterPlugin.js +1 -1
- package/lib/stats/StatsFactory.js +1 -1
- package/lib/typescript/TypeScriptPlugin.js +210 -0
- package/lib/url/URLParserPlugin.js +2 -2
- package/lib/util/AsyncQueue.js +2 -2
- package/lib/util/Hash.js +2 -2
- package/lib/util/LocConverter.js +53 -0
- package/lib/util/SortableSet.js +1 -1
- package/lib/util/cleverMerge.js +2 -2
- package/lib/util/comparators.js +3 -3
- package/lib/util/concatenate.js +3 -3
- package/lib/util/conventions.js +42 -1
- package/lib/util/createMappings.js +118 -0
- package/lib/{formatLocation.js → util/formatLocation.js} +2 -2
- package/lib/{SizeFormatHelpers.js → util/formatSize.js} +3 -1
- package/lib/util/fs.js +8 -8
- package/lib/util/hash/md4.js +1 -1
- package/lib/util/hash/xxhash64.js +1 -1
- package/lib/util/identifier.js +48 -0
- package/lib/util/internalSerializables.js +35 -19
- package/lib/util/magicComment.js +10 -7
- package/lib/util/parseJson.js +2 -73
- package/lib/util/source.js +21 -0
- package/lib/util/topologicalSort.js +69 -0
- package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +2 -2
- package/lib/wasm-async/AsyncWebAssemblyParser.js +1 -1
- package/lib/wasm-sync/UnsupportedWebAssemblyFeatureError.js +5 -3
- package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +1 -1
- package/lib/wasm-sync/WebAssemblyInInitialChunkError.js +5 -3
- package/lib/webpack.js +3 -1
- package/package.json +22 -20
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +118 -3
- package/schemas/plugins/{DllPlugin.check.d.ts → HtmlGeneratorOptions.check.d.ts} +1 -1
- package/schemas/plugins/HtmlGeneratorOptions.check.js +6 -0
- package/schemas/plugins/HtmlGeneratorOptions.json +3 -0
- package/schemas/plugins/ProgressPlugin.check.js +1 -1
- package/schemas/plugins/ProgressPlugin.json +22 -0
- package/schemas/plugins/{DllReferencePlugin.check.d.ts → css/CssAutoOrModuleParserOptions.check.d.ts} +1 -1
- package/schemas/plugins/css/CssAutoOrModuleParserOptions.check.js +6 -0
- package/schemas/plugins/css/CssAutoOrModuleParserOptions.json +3 -0
- package/schemas/plugins/dll/DllPlugin.check.d.ts +7 -0
- package/schemas/plugins/dll/DllReferencePlugin.check.d.ts +7 -0
- package/types.d.ts +810 -101
- package/lib/CaseSensitiveModulesWarning.js +0 -80
- package/lib/GraphHelpers.js +0 -49
- package/lib/NoModeWarning.js +0 -23
- package/lib/css/CssMergeStyleSheetsRuntimeModule.js +0 -57
- /package/lib/{AbstractMethodError.js → errors/AbstractMethodError.js} +0 -0
- /package/schemas/plugins/{DllPlugin.check.js → dll/DllPlugin.check.js} +0 -0
- /package/schemas/plugins/{DllPlugin.json → dll/DllPlugin.json} +0 -0
- /package/schemas/plugins/{DllReferencePlugin.check.js → dll/DllReferencePlugin.check.js} +0 -0
- /package/schemas/plugins/{DllReferencePlugin.json → dll/DllReferencePlugin.json} +0 -0
package/lib/css/CssGenerator.js
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
|
|
8
8
|
const {
|
|
9
9
|
ConcatSource,
|
|
10
|
+
OriginalSource,
|
|
10
11
|
RawSource,
|
|
11
12
|
ReplaceSource,
|
|
12
13
|
SourceMapSource
|
|
@@ -15,8 +16,11 @@ const { UsageState } = require("../ExportsInfo");
|
|
|
15
16
|
const Generator = require("../Generator");
|
|
16
17
|
const InitFragment = require("../InitFragment");
|
|
17
18
|
const {
|
|
19
|
+
CSS_TEXT_TYPE,
|
|
20
|
+
CSS_TEXT_TYPES,
|
|
18
21
|
CSS_TYPE,
|
|
19
22
|
CSS_TYPES,
|
|
23
|
+
JAVASCRIPT_AND_CSS_TEXT_TYPES,
|
|
20
24
|
JAVASCRIPT_AND_CSS_TYPES,
|
|
21
25
|
JAVASCRIPT_TYPE,
|
|
22
26
|
JAVASCRIPT_TYPES
|
|
@@ -26,6 +30,7 @@ const Template = require("../Template");
|
|
|
26
30
|
const CssImportDependency = require("../dependencies/CssImportDependency");
|
|
27
31
|
const HarmonyImportSideEffectDependency = require("../dependencies/HarmonyImportSideEffectDependency");
|
|
28
32
|
|
|
33
|
+
const { encodeMappings } = require("../util/createMappings");
|
|
29
34
|
const memoize = require("../util/memoize");
|
|
30
35
|
|
|
31
36
|
/** @typedef {import("webpack-sources").Source} Source */
|
|
@@ -46,14 +51,74 @@ const memoize = require("../util/memoize");
|
|
|
46
51
|
/** @typedef {import("../NormalModule")} NormalModule */
|
|
47
52
|
/** @typedef {import("../util/Hash")} Hash */
|
|
48
53
|
/** @typedef {import("./CssModulesPlugin").ModuleFactoryCacheEntry} ModuleFactoryCacheEntry */
|
|
49
|
-
/** @typedef {import("
|
|
54
|
+
/** @typedef {import("./CssModule")} CssModule */
|
|
50
55
|
/** @typedef {import("../Compilation")} Compilation */
|
|
51
56
|
/** @typedef {import("../Module").RuntimeRequirements} RuntimeRequirements */
|
|
52
57
|
/** @typedef {import("../../declarations/WebpackOptions").CssParserExportType} CssParserExportType */
|
|
53
58
|
|
|
59
|
+
/** @typedef {{ line: number, column: number }} SourcePosition */
|
|
60
|
+
/** @typedef {Map<string, SourcePosition>} ExportLocsMap */
|
|
61
|
+
|
|
54
62
|
const getPropertyName = memoize(() => require("../util/property"));
|
|
55
63
|
const getCssModulesPlugin = memoize(() => require("./CssModulesPlugin"));
|
|
56
64
|
|
|
65
|
+
/** @typedef {import("webpack-sources").RawSourceMap} RawSourceMap */
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Build a v3 source map that maps each line in `generatedJs` containing a
|
|
69
|
+
* known CSS-class export entry back to the corresponding selector position
|
|
70
|
+
* in the original CSS. Lines without an associated export are left
|
|
71
|
+
* unmapped — devtools simply shows them as part of the bundled JS.
|
|
72
|
+
* @param {string} generatedJs the generated JS string
|
|
73
|
+
* @param {ExportLocsMap} exportLocs map of export names to CSS source location
|
|
74
|
+
* @param {string} cssContent original CSS source content
|
|
75
|
+
* @param {string} sourceName source identifier to use in the map
|
|
76
|
+
* @returns {RawSourceMap} a v3 RawSourceMap
|
|
77
|
+
*/
|
|
78
|
+
const buildExportsSourceMap = (
|
|
79
|
+
generatedJs,
|
|
80
|
+
exportLocs,
|
|
81
|
+
cssContent,
|
|
82
|
+
sourceName
|
|
83
|
+
) => {
|
|
84
|
+
const lines = generatedJs.split("\n");
|
|
85
|
+
|
|
86
|
+
const lineByExport = new Map();
|
|
87
|
+
for (const [exportName] of exportLocs) {
|
|
88
|
+
const needle = `${JSON.stringify(exportName)}:`;
|
|
89
|
+
for (let i = 0; i < lines.length; i++) {
|
|
90
|
+
if (lines[i].includes(needle)) {
|
|
91
|
+
lineByExport.set(exportName, i);
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** @type {(import("../util/createMappings").LineMappings)[]} */
|
|
98
|
+
const perLine = lines.map(() => null);
|
|
99
|
+
for (const [exportName, genLine] of lineByExport) {
|
|
100
|
+
const pos = /** @type {SourcePosition} */ (exportLocs.get(exportName));
|
|
101
|
+
// Source-map V3 uses 0-based lines and 0-based columns. webpack's
|
|
102
|
+
// dependency `loc` uses 1-based lines and 0-based columns, so subtract
|
|
103
|
+
// one from the line.
|
|
104
|
+
perLine[genLine] = {
|
|
105
|
+
generatedColumn: 0,
|
|
106
|
+
sourceIndex: 0,
|
|
107
|
+
originalLine: pos.line - 1,
|
|
108
|
+
originalColumn: pos.column
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return {
|
|
113
|
+
version: 3,
|
|
114
|
+
file: "",
|
|
115
|
+
sources: [sourceName],
|
|
116
|
+
sourcesContent: [cssContent],
|
|
117
|
+
names: [],
|
|
118
|
+
mappings: encodeMappings(perLine)
|
|
119
|
+
};
|
|
120
|
+
};
|
|
121
|
+
|
|
57
122
|
class CssGenerator extends Generator {
|
|
58
123
|
/**
|
|
59
124
|
* Creates an instance of CssGenerator.
|
|
@@ -85,47 +150,134 @@ class CssGenerator extends Generator {
|
|
|
85
150
|
}
|
|
86
151
|
|
|
87
152
|
/**
|
|
88
|
-
*
|
|
153
|
+
* Returns the `@charset` that will appear at the start of this module's
|
|
154
|
+
* default export, walking through text imports when the module has no
|
|
155
|
+
* local `@charset` of its own.
|
|
156
|
+
* @param {NormalModule} module the module
|
|
157
|
+
* @param {ModuleGraph} moduleGraph module graph
|
|
158
|
+
* @param {WeakSet<NormalModule>=} visited cycle guard
|
|
159
|
+
* @returns {string | undefined} the effective charset
|
|
160
|
+
*/
|
|
161
|
+
_getEffectiveCharset(module, moduleGraph, visited = new WeakSet()) {
|
|
162
|
+
if (!module || visited.has(module)) return undefined;
|
|
163
|
+
const exportType = /** @type {CssModule} */ (module).exportType;
|
|
164
|
+
if (exportType !== "text" && exportType !== "css-style-sheet") {
|
|
165
|
+
return undefined;
|
|
166
|
+
}
|
|
167
|
+
visited.add(module);
|
|
168
|
+
const own =
|
|
169
|
+
module.buildInfo && /** @type {BuildInfo} */ (module.buildInfo).charset;
|
|
170
|
+
if (own !== undefined) return own;
|
|
171
|
+
if (exportType !== "text") return undefined;
|
|
172
|
+
for (const dep of module.dependencies) {
|
|
173
|
+
if (dep instanceof CssImportDependency) {
|
|
174
|
+
const depModule = /** @type {NormalModule} */ (
|
|
175
|
+
moduleGraph.getModule(dep)
|
|
176
|
+
);
|
|
177
|
+
const inherited = this._getEffectiveCharset(
|
|
178
|
+
depModule,
|
|
179
|
+
moduleGraph,
|
|
180
|
+
visited
|
|
181
|
+
);
|
|
182
|
+
if (inherited !== undefined) return inherited;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
return undefined;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Generate JavaScript expressions that evaluate each `@import`'d module
|
|
190
|
+
* for side effects. Only used by `style` exportType, where each imported
|
|
191
|
+
* style module injects its own `<style>` element independently — no
|
|
192
|
+
* content merging happens at the parent. `text` and `css-style-sheet`
|
|
193
|
+
* instead inline their imports at build time via
|
|
194
|
+
* {@link CssGenerator#_generateMergedContentSource}.
|
|
89
195
|
* @param {NormalModule} module the module to generate CSS text for
|
|
90
196
|
* @param {GenerateContext} generateContext the generate context
|
|
91
|
-
* @
|
|
92
|
-
* @returns {{ expr: string, type: CssParserExportType }[]} JavaScript code that concatenates all imported CSS
|
|
197
|
+
* @returns {string[]} JS expressions, one per `@import` dependency
|
|
93
198
|
*/
|
|
94
|
-
|
|
95
|
-
const moduleGraph = generateContext
|
|
96
|
-
/** @type {{ expr: string, type: CssParserExportType }[]} */
|
|
199
|
+
_generateImportSideEffects(module, generateContext) {
|
|
200
|
+
const { moduleGraph, concatenationScope } = generateContext;
|
|
97
201
|
const parts = [];
|
|
98
202
|
|
|
99
|
-
// Iterate through module.dependencies to maintain source order
|
|
100
203
|
for (const dep of module.dependencies) {
|
|
101
|
-
if (dep instanceof CssImportDependency)
|
|
102
|
-
|
|
103
|
-
|
|
204
|
+
if (!(dep instanceof CssImportDependency)) continue;
|
|
205
|
+
const depModule = /** @type {CssModule} */ (moduleGraph.getModule(dep));
|
|
206
|
+
// Concat-scoped deps are inlined into the same module; their side
|
|
207
|
+
// effect (own `<style>` injection) is emitted at the dep's own
|
|
208
|
+
// site, so no explicit reference is needed here.
|
|
209
|
+
if (concatenationScope && concatenationScope.isModuleInScope(depModule)) {
|
|
210
|
+
continue;
|
|
211
|
+
}
|
|
212
|
+
parts.push(
|
|
213
|
+
generateContext.runtimeTemplate.moduleExports({
|
|
104
214
|
module: depModule,
|
|
105
215
|
chunkGraph: generateContext.chunkGraph,
|
|
106
216
|
request: depModule.userRequest,
|
|
107
217
|
weak: false,
|
|
108
218
|
runtimeRequirements: generateContext.runtimeRequirements
|
|
109
|
-
})
|
|
219
|
+
})
|
|
220
|
+
);
|
|
221
|
+
}
|
|
110
222
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
223
|
+
return parts;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* Build a single CSS `Source` that contains, in source order, the rendered
|
|
228
|
+
* CSS text of every transitively `@import`'d module followed by the
|
|
229
|
+
* current module's own CSS text. Imports are inlined at build time so
|
|
230
|
+
* the resulting `Source` carries a single, accurate source map covering
|
|
231
|
+
* every contributing file — no runtime merge helper required.
|
|
232
|
+
*
|
|
233
|
+
* Only `text` / `css-style-sheet` imports contribute CSS text; `link` and
|
|
234
|
+
* `style` imports are emitted separately (own `.css` file or own
|
|
235
|
+
* `<style>` injection) and are skipped here.
|
|
236
|
+
*
|
|
237
|
+
* `ancestors` tracks the path from the top-level caller down to the
|
|
238
|
+
* current module — not every module ever visited. A module reappearing
|
|
239
|
+
* along a sibling branch (a "diamond import" like two different files
|
|
240
|
+
* each `@import`'ing the same shared module) must be inlined every time,
|
|
241
|
+
* matching the prior runtime behavior where each `default` getter was
|
|
242
|
+
* invoked at every import site.
|
|
243
|
+
* @param {NormalModule} module the module to render
|
|
244
|
+
* @param {GenerateContext} generateContext the generate context
|
|
245
|
+
* @param {Set<NormalModule>} ancestors modules on the current path
|
|
246
|
+
* @returns {Source | null} merged CSS source, or null when the module has no content
|
|
247
|
+
*/
|
|
248
|
+
_generateMergedContentSource(module, generateContext, ancestors) {
|
|
249
|
+
if (ancestors.has(module)) return null;
|
|
250
|
+
ancestors.add(module);
|
|
251
|
+
try {
|
|
252
|
+
const { moduleGraph } = generateContext;
|
|
253
|
+
/** @type {Source[]} */
|
|
254
|
+
const parts = [];
|
|
255
|
+
|
|
256
|
+
for (const dep of module.dependencies) {
|
|
257
|
+
if (!(dep instanceof CssImportDependency)) continue;
|
|
258
|
+
const depModule = /** @type {CssModule} */ (moduleGraph.getModule(dep));
|
|
259
|
+
if (!depModule) continue;
|
|
260
|
+
const depExportType = depModule.exportType;
|
|
261
|
+
if (depExportType !== "text" && depExportType !== "css-style-sheet") {
|
|
262
|
+
continue;
|
|
124
263
|
}
|
|
264
|
+
const depMerged = this._generateMergedContentSource(
|
|
265
|
+
depModule,
|
|
266
|
+
generateContext,
|
|
267
|
+
ancestors
|
|
268
|
+
);
|
|
269
|
+
if (depMerged) parts.push(depMerged);
|
|
125
270
|
}
|
|
126
|
-
}
|
|
127
271
|
|
|
128
|
-
|
|
272
|
+
const own = this._generateContentSource(module, generateContext);
|
|
273
|
+
if (own) parts.push(own);
|
|
274
|
+
|
|
275
|
+
if (parts.length === 0) return null;
|
|
276
|
+
if (parts.length === 1) return parts[0];
|
|
277
|
+
return new ConcatSource(...parts);
|
|
278
|
+
} finally {
|
|
279
|
+
ancestors.delete(module);
|
|
280
|
+
}
|
|
129
281
|
}
|
|
130
282
|
|
|
131
283
|
/**
|
|
@@ -168,20 +320,28 @@ class CssGenerator extends Generator {
|
|
|
168
320
|
}
|
|
169
321
|
|
|
170
322
|
/**
|
|
171
|
-
*
|
|
172
|
-
*
|
|
323
|
+
* Serialize a CSS Source into a JS string literal with an optional
|
|
324
|
+
* inline `sourceMappingURL` data URI so DevTools can resolve the
|
|
325
|
+
* original sources at runtime.
|
|
173
326
|
* @param {Source} cssSource the CSS source
|
|
174
|
-
* @param {
|
|
327
|
+
* @param {import("../../declarations/WebpackOptions").DevTool | undefined} devtool the devtool option
|
|
175
328
|
* @returns {Source} a Source representing a JS string literal
|
|
176
329
|
*/
|
|
177
|
-
|
|
330
|
+
_cssToJsLiteral(cssSource, devtool) {
|
|
178
331
|
const { source, map } = cssSource.sourceAndMap();
|
|
179
|
-
|
|
180
|
-
const escaped = JSON.stringify(content);
|
|
332
|
+
let content = /** @type {string} */ (source);
|
|
181
333
|
if (map) {
|
|
182
|
-
|
|
334
|
+
const inlineMap =
|
|
335
|
+
typeof devtool === "string" && devtool.includes("nosources")
|
|
336
|
+
? { ...map, sourcesContent: undefined }
|
|
337
|
+
: map;
|
|
338
|
+
const base64Map = Buffer.from(JSON.stringify(inlineMap), "utf8").toString(
|
|
339
|
+
"base64"
|
|
340
|
+
);
|
|
341
|
+
const trailingNewline = content.endsWith("\n") ? "" : "\n";
|
|
342
|
+
content += `${trailingNewline}/*# sourceMappingURL=data:application/json;charset=utf-8;base64,${base64Map}*/`;
|
|
183
343
|
}
|
|
184
|
-
return new RawSource(
|
|
344
|
+
return new RawSource(JSON.stringify(content));
|
|
185
345
|
}
|
|
186
346
|
|
|
187
347
|
/**
|
|
@@ -291,7 +451,8 @@ class CssGenerator extends Generator {
|
|
|
291
451
|
/** @type {CssData} */
|
|
292
452
|
const cssData = {
|
|
293
453
|
esModule: /** @type {boolean} */ (this._esModule),
|
|
294
|
-
exports: new Map()
|
|
454
|
+
exports: new Map(),
|
|
455
|
+
exportLocs: new Map()
|
|
295
456
|
};
|
|
296
457
|
|
|
297
458
|
this.sourceModule(module, initFragments, source, {
|
|
@@ -301,6 +462,11 @@ class CssGenerator extends Generator {
|
|
|
301
462
|
|
|
302
463
|
switch (generateContext.type) {
|
|
303
464
|
case JAVASCRIPT_TYPE: {
|
|
465
|
+
const compilation = generateContext.runtimeTemplate.compilation;
|
|
466
|
+
const devtool = compilation.options.devtool;
|
|
467
|
+
const isCssModule = /** @type {BuildMeta} */ (module.buildMeta)
|
|
468
|
+
.isCssModule;
|
|
469
|
+
|
|
304
470
|
const generateContentCode = () => {
|
|
305
471
|
switch (exportType) {
|
|
306
472
|
case "style": {
|
|
@@ -309,15 +475,24 @@ class CssGenerator extends Generator {
|
|
|
309
475
|
generateContext
|
|
310
476
|
);
|
|
311
477
|
if (!cssSource) return "";
|
|
312
|
-
const moduleId = generateContext.chunkGraph.getModuleId(module);
|
|
313
478
|
|
|
314
479
|
generateContext.runtimeRequirements.add(
|
|
315
480
|
RuntimeGlobals.cssInjectStyle
|
|
316
481
|
);
|
|
317
482
|
|
|
483
|
+
const moduleId = generateContext.chunkGraph.getModuleId(module);
|
|
484
|
+
|
|
485
|
+
if (generateContext.concatenationScope) {
|
|
486
|
+
return new ConcatSource(
|
|
487
|
+
`__webpack_css_styles__.push([${JSON.stringify(moduleId)}, `,
|
|
488
|
+
this._cssToJsLiteral(cssSource, devtool),
|
|
489
|
+
"]);"
|
|
490
|
+
);
|
|
491
|
+
}
|
|
492
|
+
|
|
318
493
|
return new ConcatSource(
|
|
319
|
-
`${RuntimeGlobals.cssInjectStyle}(${JSON.stringify(moduleId
|
|
320
|
-
this.
|
|
494
|
+
`${RuntimeGlobals.cssInjectStyle}(${JSON.stringify(moduleId)}, `,
|
|
495
|
+
this._cssToJsLiteral(cssSource, devtool),
|
|
321
496
|
");"
|
|
322
497
|
);
|
|
323
498
|
}
|
|
@@ -329,8 +504,8 @@ class CssGenerator extends Generator {
|
|
|
329
504
|
const generateImportCode = () => {
|
|
330
505
|
switch (exportType) {
|
|
331
506
|
case "style": {
|
|
332
|
-
return this.
|
|
333
|
-
.map((
|
|
507
|
+
return this._generateImportSideEffects(module, generateContext)
|
|
508
|
+
.map((expr) => `${expr};`)
|
|
334
509
|
.join("\n");
|
|
335
510
|
}
|
|
336
511
|
default:
|
|
@@ -340,52 +515,23 @@ class CssGenerator extends Generator {
|
|
|
340
515
|
const generateExportCode = () => {
|
|
341
516
|
/** @returns {Source} generated CSS text as JS expression */
|
|
342
517
|
const generateCssText = () => {
|
|
343
|
-
const
|
|
344
|
-
module,
|
|
345
|
-
generateContext
|
|
346
|
-
);
|
|
347
|
-
const cssSource = this._generateContentSource(
|
|
518
|
+
const cssSource = this._generateMergedContentSource(
|
|
348
519
|
module,
|
|
349
|
-
generateContext
|
|
520
|
+
generateContext,
|
|
521
|
+
new Set()
|
|
350
522
|
);
|
|
351
523
|
|
|
352
524
|
let jsLiteral = cssSource
|
|
353
|
-
? this.
|
|
525
|
+
? this._cssToJsLiteral(cssSource, devtool)
|
|
354
526
|
: new RawSource('""');
|
|
355
527
|
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
generateContext.runtimeRequirements.add(
|
|
362
|
-
RuntimeGlobals.cssMergeStyleSheets
|
|
363
|
-
);
|
|
364
|
-
|
|
365
|
-
const args = importCode.map((part) => part.expr);
|
|
366
|
-
|
|
367
|
-
jsLiteral = new ConcatSource(
|
|
368
|
-
`${RuntimeGlobals.cssMergeStyleSheets}([${args.join(", ")}, `,
|
|
369
|
-
jsLiteral,
|
|
370
|
-
"])"
|
|
371
|
-
);
|
|
372
|
-
} else {
|
|
373
|
-
jsLiteral = new ConcatSource(
|
|
374
|
-
`${generateContext.runtimeTemplate.concatenation(
|
|
375
|
-
...importCode
|
|
376
|
-
)} + `,
|
|
377
|
-
jsLiteral
|
|
378
|
-
);
|
|
379
|
-
}
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
if (
|
|
383
|
-
exportType === "css-style-sheet" &&
|
|
384
|
-
typeof (/** @type {BuildInfo} */ (module.buildInfo).charset) !==
|
|
385
|
-
"undefined"
|
|
386
|
-
) {
|
|
528
|
+
const effectiveCharset =
|
|
529
|
+
exportType === "css-style-sheet" || exportType === "text"
|
|
530
|
+
? this._getEffectiveCharset(module, generateContext.moduleGraph)
|
|
531
|
+
: undefined;
|
|
532
|
+
if (effectiveCharset !== undefined) {
|
|
387
533
|
jsLiteral = new ConcatSource(
|
|
388
|
-
`'@charset "${
|
|
534
|
+
`'@charset "${effectiveCharset}";\\n' + `,
|
|
389
535
|
jsLiteral
|
|
390
536
|
);
|
|
391
537
|
}
|
|
@@ -402,21 +548,19 @@ class CssGenerator extends Generator {
|
|
|
402
548
|
return generateCssText();
|
|
403
549
|
}
|
|
404
550
|
case "css-style-sheet": {
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
551
|
+
// Build a constructable stylesheet from the statically
|
|
552
|
+
// merged CSS text. The merged literal carries a single
|
|
553
|
+
// inline source map covering every contributing module.
|
|
408
554
|
const fnPrefix =
|
|
409
555
|
generateContext.runtimeTemplate.supportsArrowFunction()
|
|
410
556
|
? "() => {\n"
|
|
411
557
|
: "function() {\n";
|
|
412
|
-
const
|
|
413
|
-
|
|
414
|
-
"sheet.replaceSync(cssText);\n" +
|
|
415
|
-
"return sheet;\n";
|
|
558
|
+
const constOrVar =
|
|
559
|
+
generateContext.runtimeTemplate.renderConst();
|
|
416
560
|
return new ConcatSource(
|
|
417
|
-
`(${fnPrefix}${constOrVar}
|
|
418
|
-
|
|
419
|
-
|
|
561
|
+
`(${fnPrefix}${constOrVar} sheet = new CSSStyleSheet();\nsheet.replaceSync(`,
|
|
562
|
+
generateCssText(),
|
|
563
|
+
");\nreturn sheet;\n})()"
|
|
420
564
|
);
|
|
421
565
|
}
|
|
422
566
|
default:
|
|
@@ -424,8 +568,6 @@ class CssGenerator extends Generator {
|
|
|
424
568
|
}
|
|
425
569
|
};
|
|
426
570
|
|
|
427
|
-
const isCSSModule = /** @type {BuildMeta} */ (module.buildMeta)
|
|
428
|
-
.isCSSModule;
|
|
429
571
|
/** @type {Source | null} */
|
|
430
572
|
const defaultExport = generateJSDefaultExport();
|
|
431
573
|
|
|
@@ -437,7 +579,7 @@ class CssGenerator extends Generator {
|
|
|
437
579
|
generateContext.runtimeRequirements.add(RuntimeGlobals.module);
|
|
438
580
|
}
|
|
439
581
|
|
|
440
|
-
if (!defaultExport && cssData.exports.size === 0 && !
|
|
582
|
+
if (!defaultExport && cssData.exports.size === 0 && !isCssModule) {
|
|
441
583
|
return new RawSource("");
|
|
442
584
|
}
|
|
443
585
|
|
|
@@ -514,7 +656,7 @@ class CssGenerator extends Generator {
|
|
|
514
656
|
// Should be after `concatenationScope` to allow module inlining
|
|
515
657
|
generateContext.runtimeRequirements.add(RuntimeGlobals.module);
|
|
516
658
|
|
|
517
|
-
if (!
|
|
659
|
+
if (!isCssModule && !needNsObj) {
|
|
518
660
|
return new ConcatSource(
|
|
519
661
|
`${module.moduleArgument}.exports = `,
|
|
520
662
|
/** @type {Source} */ (defaultExport)
|
|
@@ -562,20 +704,78 @@ class CssGenerator extends Generator {
|
|
|
562
704
|
source.add("\n");
|
|
563
705
|
}
|
|
564
706
|
}
|
|
565
|
-
|
|
566
|
-
}
|
|
567
|
-
case CSS_TYPE: {
|
|
707
|
+
// For link-type modules without any JS emit, skip source wrapping
|
|
568
708
|
if (
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
709
|
+
exportType === "link" &&
|
|
710
|
+
!isCssModule &&
|
|
711
|
+
cssData.exports.size === 0
|
|
712
|
+
) {
|
|
713
|
+
return source;
|
|
714
|
+
}
|
|
715
|
+
|
|
716
|
+
const generatedJs = /** @type {string} */ (source.source());
|
|
717
|
+
const sourceName = module.readableIdentifier(
|
|
718
|
+
compilation.requestShortener
|
|
719
|
+
);
|
|
720
|
+
|
|
721
|
+
// When per-export source positions are available, emit a
|
|
722
|
+
// SourceMapSource mapping each export line back to its CSS
|
|
723
|
+
// selector; otherwise fall back to OriginalSource.
|
|
724
|
+
if (
|
|
725
|
+
/** @type {ExportLocsMap} */
|
|
726
|
+
(cssData.exportLocs).size > 0
|
|
573
727
|
) {
|
|
728
|
+
const cssOriginal = module.originalSource();
|
|
729
|
+
if (cssOriginal) {
|
|
730
|
+
const sourceMap = buildExportsSourceMap(
|
|
731
|
+
generatedJs,
|
|
732
|
+
/** @type {ExportLocsMap} */
|
|
733
|
+
(cssData.exportLocs),
|
|
734
|
+
/** @type {string} */ (cssOriginal.source()),
|
|
735
|
+
sourceName
|
|
736
|
+
);
|
|
737
|
+
return new SourceMapSource(generatedJs, sourceName, sourceMap);
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
return new OriginalSource(generatedJs, sourceName);
|
|
741
|
+
}
|
|
742
|
+
case CSS_TYPE: {
|
|
743
|
+
if (!(this._exportsOnly || (exportType && exportType !== "link"))) {
|
|
574
744
|
generateContext.runtimeRequirements.add(RuntimeGlobals.hasCssModules);
|
|
575
745
|
}
|
|
576
746
|
|
|
577
747
|
return InitFragment.addToSource(source, initFragments, generateContext);
|
|
578
748
|
}
|
|
749
|
+
case CSS_TEXT_TYPE: {
|
|
750
|
+
// The merged CSS text — what consumers like
|
|
751
|
+
// `HtmlInlineStyleDependency.Template` need when they want to
|
|
752
|
+
// drop the processed CSS straight into an inline `<style>`
|
|
753
|
+
// tag. Mirrors the JS-side `generateCssText()` (charset
|
|
754
|
+
// prefix included), without the JS string-literal wrapper.
|
|
755
|
+
const cssSource = this._generateMergedContentSource(
|
|
756
|
+
module,
|
|
757
|
+
generateContext,
|
|
758
|
+
new Set()
|
|
759
|
+
);
|
|
760
|
+
|
|
761
|
+
const effectiveCharset = this._getEffectiveCharset(
|
|
762
|
+
module,
|
|
763
|
+
generateContext.moduleGraph
|
|
764
|
+
);
|
|
765
|
+
const charsetPrefix =
|
|
766
|
+
effectiveCharset !== undefined
|
|
767
|
+
? `@charset "${effectiveCharset}";\n`
|
|
768
|
+
: "";
|
|
769
|
+
|
|
770
|
+
if (!cssSource) {
|
|
771
|
+
return charsetPrefix
|
|
772
|
+
? new RawSource(charsetPrefix)
|
|
773
|
+
: new RawSource("");
|
|
774
|
+
}
|
|
775
|
+
return charsetPrefix
|
|
776
|
+
? new ConcatSource(charsetPrefix, cssSource)
|
|
777
|
+
: cssSource;
|
|
778
|
+
}
|
|
579
779
|
default:
|
|
580
780
|
return null;
|
|
581
781
|
}
|
|
@@ -631,6 +831,19 @@ class CssGenerator extends Generator {
|
|
|
631
831
|
continue;
|
|
632
832
|
}
|
|
633
833
|
|
|
834
|
+
// Inline `<style>` blocks in HTML modules read the merged CSS
|
|
835
|
+
// text directly via the `css-text` source type — they don't go
|
|
836
|
+
// through the JS-string wrapper that other consumers use.
|
|
837
|
+
// Matched by dependency category so the CSS package doesn't
|
|
838
|
+
// have to import HtmlInlineStyleDependency.
|
|
839
|
+
if (
|
|
840
|
+
connection.dependency &&
|
|
841
|
+
connection.dependency.category === "html-style"
|
|
842
|
+
) {
|
|
843
|
+
sourceTypes.add(CSS_TEXT_TYPE);
|
|
844
|
+
continue;
|
|
845
|
+
}
|
|
846
|
+
|
|
634
847
|
if (!connection.originModule) {
|
|
635
848
|
continue;
|
|
636
849
|
}
|
|
@@ -654,9 +867,11 @@ class CssGenerator extends Generator {
|
|
|
654
867
|
this._exportsOnly ||
|
|
655
868
|
/** @type {boolean} */ (exportType && exportType !== "link")
|
|
656
869
|
) {
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
870
|
+
const hasJs = sourceTypes.has(JAVASCRIPT_TYPE);
|
|
871
|
+
const hasCssText = sourceTypes.has(CSS_TEXT_TYPE);
|
|
872
|
+
if (hasJs && hasCssText) return JAVASCRIPT_AND_CSS_TEXT_TYPES;
|
|
873
|
+
if (hasJs) return JAVASCRIPT_TYPES;
|
|
874
|
+
if (hasCssText) return CSS_TEXT_TYPES;
|
|
660
875
|
return new Set();
|
|
661
876
|
}
|
|
662
877
|
if (sourceTypes.has(JAVASCRIPT_TYPE)) {
|
|
@@ -679,7 +894,7 @@ class CssGenerator extends Generator {
|
|
|
679
894
|
return 42;
|
|
680
895
|
}
|
|
681
896
|
if (cssData.exports.size === 0) {
|
|
682
|
-
if (/** @type {BuildMeta} */ (module.buildMeta).
|
|
897
|
+
if (/** @type {BuildMeta} */ (module.buildMeta).isCssModule) {
|
|
683
898
|
return 42;
|
|
684
899
|
}
|
|
685
900
|
return 0;
|