webpack 5.106.2 → 5.107.1
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/BannerPlugin.js +3 -4
- package/lib/Cache.js +3 -6
- package/lib/Chunk.js +21 -25
- package/lib/ChunkGroup.js +57 -15
- package/lib/CompatibilityPlugin.js +8 -7
- package/lib/Compilation.js +67 -37
- 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 -10
- package/lib/ExportsInfo.js +30 -34
- package/lib/ExternalModule.js +91 -26
- package/lib/ExternalModuleFactoryPlugin.js +7 -1
- 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 +20 -19
- package/lib/ModuleFactory.js +1 -1
- package/lib/ModuleNotFoundError.js +3 -84
- package/lib/ModuleSourceTypeConstants.js +51 -19
- package/lib/ModuleTypeConstants.js +12 -3
- package/lib/MultiCompiler.js +2 -2
- package/lib/NodeStuffPlugin.js +1 -1
- package/lib/NormalModule.js +119 -77
- package/lib/NormalModuleFactory.js +47 -27
- 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 +12 -1
- package/lib/SourceMapDevToolPlugin.js +250 -49
- package/lib/Template.js +1 -1
- package/lib/TemplatedPathPlugin.js +22 -4
- 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 +12 -8
- package/lib/asset/AssetGenerator.js +36 -22
- package/lib/asset/AssetModulesPlugin.js +6 -8
- package/lib/asset/AssetSourceGenerator.js +12 -8
- 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 +168 -88
- 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 +112 -4
- 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 +28 -2
- package/lib/dependencies/HarmonyDetectionParserPlugin.js +22 -2
- 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 +557 -0
- package/lib/dependencies/HtmlSourceDependency.js +128 -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/errors/ModuleNotFoundError.js +91 -0
- 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 +429 -0
- package/lib/html/HtmlParser.js +1489 -0
- package/lib/html/walkHtmlTokens.js +3249 -0
- package/lib/ids/IdHelpers.js +2 -1
- package/lib/index.js +36 -15
- package/lib/javascript/JavascriptModulesPlugin.js +91 -10
- 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 +112 -5
- package/lib/optimize/SplitChunksPlugin.js +5 -5
- 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/AutoPublicPathRuntimeModule.js +3 -3
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +5 -5
- 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 +4 -10
- package/lib/sharing/ConsumeSharedRuntimeModule.js +8 -4
- package/lib/sharing/ProvideSharedModule.js +1 -1
- package/lib/sharing/ProvideSharedPlugin.js +5 -5
- 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 +3 -4
- 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 +24 -22
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +129 -12
- 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/container/ContainerReferencePlugin.check.js +1 -1
- package/schemas/plugins/container/ContainerReferencePlugin.json +1 -0
- package/schemas/plugins/container/ExternalsType.check.js +1 -1
- package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
- package/schemas/plugins/container/ModuleFederationPlugin.json +1 -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 +1153 -233
- 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
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/*
|
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
"use strict";
|
|
6
|
+
|
|
7
|
+
const makeSerializable = require("../util/makeSerializable");
|
|
8
|
+
const CssUrlDependency = require("./CssUrlDependency");
|
|
9
|
+
const ModuleDependency = require("./ModuleDependency");
|
|
10
|
+
|
|
11
|
+
/** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
|
|
12
|
+
/** @typedef {import("../Chunk")} Chunk */
|
|
13
|
+
/** @typedef {import("../Dependency")} Dependency */
|
|
14
|
+
/** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
|
|
15
|
+
/** @typedef {import("../Entrypoint")} Entrypoint */
|
|
16
|
+
/** @typedef {import("../javascript/JavascriptParser").Range} Range */
|
|
17
|
+
/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
|
18
|
+
/** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Represents an inline `<script>...</script>` block in an HTML module. The
|
|
22
|
+
* tag's body is bundled as its own entry chunk — the same pipeline that
|
|
23
|
+
* processes `<script src>` — and the inline body is replaced with a
|
|
24
|
+
* `src` attribute pointing at the emitted chunk URL.
|
|
25
|
+
*/
|
|
26
|
+
class HtmlInlineScriptDependency extends ModuleDependency {
|
|
27
|
+
/**
|
|
28
|
+
* Creates an instance of HtmlInlineScriptDependency.
|
|
29
|
+
* @param {string} request virtual request resolving to the inline JS (data URI)
|
|
30
|
+
* @param {number} insertPos position right after `<script` where ` src="…"` is inserted
|
|
31
|
+
* @param {Range} contentRange range of the inline JS body (between `<script>` and `</script>`)
|
|
32
|
+
* @param {string} entryName name of the entry the inline JS is bundled into
|
|
33
|
+
* @param {string=} category dependency category used for resolving and grouping
|
|
34
|
+
*/
|
|
35
|
+
constructor(request, insertPos, contentRange, entryName, category) {
|
|
36
|
+
super(request);
|
|
37
|
+
this.insertPos = insertPos;
|
|
38
|
+
this.contentRange = contentRange;
|
|
39
|
+
this.range = contentRange;
|
|
40
|
+
this.entryName = entryName;
|
|
41
|
+
/** @type {string} */
|
|
42
|
+
this._category = category || "commonjs";
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
get type() {
|
|
46
|
+
return "html inline script";
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
get category() {
|
|
50
|
+
return this._category;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Serializes this instance into the provided serializer context.
|
|
55
|
+
* @param {ObjectSerializerContext} context context
|
|
56
|
+
*/
|
|
57
|
+
serialize(context) {
|
|
58
|
+
const { write } = context;
|
|
59
|
+
write(this.insertPos);
|
|
60
|
+
write(this.contentRange);
|
|
61
|
+
write(this.entryName);
|
|
62
|
+
write(this._category);
|
|
63
|
+
super.serialize(context);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Restores this instance from the provided deserializer context.
|
|
68
|
+
* @param {ObjectDeserializerContext} context context
|
|
69
|
+
*/
|
|
70
|
+
deserialize(context) {
|
|
71
|
+
const { read } = context;
|
|
72
|
+
this.insertPos = read();
|
|
73
|
+
this.contentRange = read();
|
|
74
|
+
this.range = this.contentRange;
|
|
75
|
+
this.entryName = read();
|
|
76
|
+
this._category = read();
|
|
77
|
+
super.deserialize(context);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
HtmlInlineScriptDependency.Template = class HtmlInlineScriptDependencyTemplate extends (
|
|
82
|
+
ModuleDependency.Template
|
|
83
|
+
) {
|
|
84
|
+
/**
|
|
85
|
+
* Applies the plugin by registering its hooks on the compiler.
|
|
86
|
+
* @param {Dependency} dependency the dependency for which the template should be applied
|
|
87
|
+
* @param {ReplaceSource} source the current replace source which can be modified
|
|
88
|
+
* @param {DependencyTemplateContext} templateContext the context object
|
|
89
|
+
* @returns {void}
|
|
90
|
+
*/
|
|
91
|
+
apply(dependency, source, templateContext) {
|
|
92
|
+
const { runtimeTemplate } = templateContext;
|
|
93
|
+
const dep = /** @type {HtmlInlineScriptDependency} */ (dependency);
|
|
94
|
+
const compilation = runtimeTemplate.compilation;
|
|
95
|
+
const entrypoint = /** @type {Entrypoint | undefined} */ (
|
|
96
|
+
compilation.entrypoints.get(dep.entryName)
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
/** @type {string} */
|
|
100
|
+
let url = "data:,";
|
|
101
|
+
|
|
102
|
+
if (entrypoint) {
|
|
103
|
+
const chunk = /** @type {Chunk} */ (entrypoint.getEntrypointChunk());
|
|
104
|
+
const outputOptions = runtimeTemplate.outputOptions;
|
|
105
|
+
const filenameTemplate =
|
|
106
|
+
chunk.filenameTemplate ||
|
|
107
|
+
(chunk.canBeInitial()
|
|
108
|
+
? outputOptions.filename
|
|
109
|
+
: outputOptions.chunkFilename);
|
|
110
|
+
|
|
111
|
+
const filename = compilation.getPath(filenameTemplate, {
|
|
112
|
+
chunk,
|
|
113
|
+
contentHashType: "javascript"
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
url = `${CssUrlDependency.PUBLIC_PATH_AUTO}${filename}`;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// Insert ` src="…"` right after `<script` so the inline body is
|
|
120
|
+
// served from the emitted chunk instead. The browser ignores the
|
|
121
|
+
// remaining inline body once `src` is present, but we still clear
|
|
122
|
+
// it below so the unprocessed JS doesn't ride along.
|
|
123
|
+
source.insert(dep.insertPos, ` src="${url}"`);
|
|
124
|
+
source.replace(dep.contentRange[0], dep.contentRange[1] - 1, "");
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
makeSerializable(
|
|
129
|
+
HtmlInlineScriptDependency,
|
|
130
|
+
"webpack/lib/dependencies/HtmlInlineScriptDependency"
|
|
131
|
+
);
|
|
132
|
+
|
|
133
|
+
module.exports = HtmlInlineScriptDependency;
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/*
|
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
"use strict";
|
|
6
|
+
|
|
7
|
+
const { CSS_TEXT_TYPE } = require("../ModuleSourceTypeConstants");
|
|
8
|
+
const makeSerializable = require("../util/makeSerializable");
|
|
9
|
+
const ModuleDependency = require("./ModuleDependency");
|
|
10
|
+
|
|
11
|
+
/** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
|
|
12
|
+
/** @typedef {import("../CodeGenerationResults")} CodeGenerationResults */
|
|
13
|
+
/** @typedef {import("../Dependency")} Dependency */
|
|
14
|
+
/** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
|
|
15
|
+
/** @typedef {import("../Module")} Module */
|
|
16
|
+
/** @typedef {import("../javascript/JavascriptParser").Range} Range */
|
|
17
|
+
/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
|
18
|
+
/** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
|
19
|
+
/** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Represents an inline `<style>...</style>` block in an HTML module. The
|
|
23
|
+
* tag's content is fed into webpack's CSS pipeline as a virtual CSS module
|
|
24
|
+
* with `exportType: "text"` so `url()` and `\@import` references are
|
|
25
|
+
* resolved relative to the HTML file. At render time the original content
|
|
26
|
+
* range is replaced with the processed CSS text read from the CSS module's
|
|
27
|
+
* code generation data.
|
|
28
|
+
*/
|
|
29
|
+
class HtmlInlineStyleDependency extends ModuleDependency {
|
|
30
|
+
/**
|
|
31
|
+
* Creates an instance of HtmlInlineStyleDependency.
|
|
32
|
+
* @param {string} request virtual request resolving to the inline CSS (data URI)
|
|
33
|
+
* @param {Range} range range of the inline CSS content (between `<style>` and `</style>`)
|
|
34
|
+
*/
|
|
35
|
+
constructor(request, range) {
|
|
36
|
+
super(request);
|
|
37
|
+
this.range = range;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
get type() {
|
|
41
|
+
return "html inline style";
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
get category() {
|
|
45
|
+
return "html-style";
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Serializes this instance into the provided serializer context.
|
|
50
|
+
* @param {ObjectSerializerContext} context context
|
|
51
|
+
*/
|
|
52
|
+
serialize(context) {
|
|
53
|
+
super.serialize(context);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Restores this instance from the provided deserializer context.
|
|
58
|
+
* @param {ObjectDeserializerContext} context context
|
|
59
|
+
*/
|
|
60
|
+
deserialize(context) {
|
|
61
|
+
super.deserialize(context);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
HtmlInlineStyleDependency.Template = class HtmlInlineStyleDependencyTemplate extends (
|
|
66
|
+
ModuleDependency.Template
|
|
67
|
+
) {
|
|
68
|
+
/**
|
|
69
|
+
* Applies the plugin by registering its hooks on the compiler.
|
|
70
|
+
* @param {Dependency} dependency the dependency for which the template should be applied
|
|
71
|
+
* @param {ReplaceSource} source the current replace source which can be modified
|
|
72
|
+
* @param {DependencyTemplateContext} templateContext the context object
|
|
73
|
+
* @returns {void}
|
|
74
|
+
*/
|
|
75
|
+
apply(dependency, source, { moduleGraph, runtime, codeGenerationResults }) {
|
|
76
|
+
const dep = /** @type {HtmlInlineStyleDependency} */ (dependency);
|
|
77
|
+
const module = /** @type {Module} */ (moduleGraph.getModule(dep));
|
|
78
|
+
|
|
79
|
+
/** @type {string} */
|
|
80
|
+
let cssText = "";
|
|
81
|
+
|
|
82
|
+
if (module) {
|
|
83
|
+
const codeGen =
|
|
84
|
+
/** @type {CodeGenerationResults} */
|
|
85
|
+
(codeGenerationResults).get(module, runtime);
|
|
86
|
+
const cssTextSource = codeGen.sources.get(CSS_TEXT_TYPE);
|
|
87
|
+
if (cssTextSource) {
|
|
88
|
+
cssText = /** @type {string} */ (cssTextSource.source());
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
source.replace(dep.range[0], dep.range[1] - 1, cssText);
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
makeSerializable(
|
|
97
|
+
HtmlInlineStyleDependency,
|
|
98
|
+
"webpack/lib/dependencies/HtmlInlineStyleDependency"
|
|
99
|
+
);
|
|
100
|
+
|
|
101
|
+
module.exports = HtmlInlineStyleDependency;
|