webpack 5.90.3 → 5.92.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/README.md +5 -5
- package/bin/webpack.js +6 -3
- package/lib/APIPlugin.js +14 -6
- package/lib/AutomaticPrefetchPlugin.js +1 -1
- package/lib/BannerPlugin.js +3 -1
- package/lib/Cache.js +8 -2
- package/lib/CacheFacade.js +3 -3
- package/lib/Chunk.js +7 -4
- package/lib/ChunkGraph.js +52 -25
- package/lib/ChunkGroup.js +23 -17
- package/lib/CleanPlugin.js +8 -6
- package/lib/Compilation.js +295 -120
- package/lib/Compiler.js +223 -87
- package/lib/ConcatenationScope.js +3 -3
- package/lib/ConditionalInitFragment.js +4 -5
- package/lib/ContextModule.js +95 -41
- package/lib/ContextModuleFactory.js +4 -2
- package/lib/ContextReplacementPlugin.js +3 -2
- package/lib/DefinePlugin.js +18 -6
- package/lib/Dependency.js +12 -10
- package/lib/DependencyTemplate.js +17 -7
- package/lib/DllModule.js +1 -0
- package/lib/DllReferencePlugin.js +7 -3
- package/lib/EntryOptionPlugin.js +4 -1
- package/lib/EntryPlugin.js +6 -1
- package/lib/Entrypoint.js +1 -1
- package/lib/EvalDevToolModulePlugin.js +11 -0
- package/lib/ExportsInfo.js +23 -8
- package/lib/ExternalModule.js +160 -35
- package/lib/ExternalModuleFactoryPlugin.js +37 -2
- package/lib/FileSystemInfo.js +69 -42
- package/lib/FlagDependencyExportsPlugin.js +21 -7
- package/lib/Generator.js +4 -4
- package/lib/HookWebpackError.js +2 -2
- package/lib/HotModuleReplacementPlugin.js +108 -45
- package/lib/IgnorePlugin.js +4 -1
- package/lib/InitFragment.js +5 -3
- package/lib/LibManifestPlugin.js +17 -9
- package/lib/Module.js +41 -14
- package/lib/ModuleFactory.js +3 -3
- package/lib/ModuleFilenameHelpers.js +30 -17
- package/lib/ModuleGraph.js +60 -31
- package/lib/ModuleGraphConnection.js +2 -1
- package/lib/MultiCompiler.js +62 -9
- package/lib/NodeStuffPlugin.js +14 -3
- package/lib/NormalModule.js +13 -13
- package/lib/NormalModuleFactory.js +18 -9
- package/lib/NormalModuleReplacementPlugin.js +5 -1
- package/lib/Parser.js +1 -1
- package/lib/PlatformPlugin.js +39 -0
- package/lib/ProgressPlugin.js +1 -1
- package/lib/ProvidePlugin.js +3 -1
- package/lib/RawModule.js +2 -1
- package/lib/RecordIdsPlugin.js +4 -4
- package/lib/ResolverFactory.js +6 -4
- package/lib/RuntimeModule.js +4 -4
- package/lib/RuntimePlugin.js +1 -0
- package/lib/RuntimeTemplate.js +124 -52
- package/lib/SourceMapDevToolPlugin.js +4 -1
- package/lib/Stats.js +11 -4
- package/lib/Template.js +5 -5
- package/lib/TemplatedPathPlugin.js +48 -7
- package/lib/Watching.js +67 -60
- package/lib/WebpackError.js +6 -6
- package/lib/WebpackOptionsApply.js +18 -5
- package/lib/asset/AssetGenerator.js +15 -0
- package/lib/asset/RawDataUrlModule.js +3 -1
- package/lib/async-modules/AwaitDependenciesInitFragment.js +2 -2
- package/lib/buildChunkGraph.js +120 -67
- package/lib/cache/IdleFileCachePlugin.js +8 -3
- package/lib/cache/MemoryCachePlugin.js +1 -1
- package/lib/cache/MemoryWithGcCachePlugin.js +6 -2
- package/lib/cache/PackFileCacheStrategy.js +51 -18
- package/lib/cache/ResolverCachePlugin.js +22 -14
- package/lib/cache/getLazyHashedEtag.js +2 -2
- package/lib/cli.js +5 -5
- package/lib/config/browserslistTargetHandler.js +7 -1
- package/lib/config/defaults.js +108 -34
- package/lib/config/normalization.js +3 -1
- package/lib/config/target.js +18 -11
- package/lib/container/ContainerEntryDependency.js +2 -1
- package/lib/container/ContainerEntryModule.js +4 -2
- package/lib/container/ContainerPlugin.js +14 -10
- package/lib/container/FallbackModule.js +1 -1
- package/lib/container/RemoteRuntimeModule.js +12 -3
- package/lib/css/CssExportsGenerator.js +68 -25
- package/lib/css/CssGenerator.js +34 -6
- package/lib/css/CssLoadingRuntimeModule.js +217 -98
- package/lib/css/CssModulesPlugin.js +238 -107
- package/lib/css/CssParser.js +24 -15
- package/lib/css/walkCssTokens.js +1 -1
- package/lib/debug/ProfilingPlugin.js +28 -3
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +9 -5
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +4 -1
- package/lib/dependencies/CommonJsDependencyHelpers.js +2 -1
- package/lib/dependencies/CommonJsExportRequireDependency.js +33 -18
- package/lib/dependencies/CommonJsExportsDependency.js +13 -5
- package/lib/dependencies/CommonJsExportsParserPlugin.js +20 -15
- package/lib/dependencies/CommonJsImportsParserPlugin.js +1 -2
- package/lib/dependencies/ContextDependencyHelpers.js +49 -29
- package/lib/dependencies/ContextElementDependency.js +8 -1
- package/lib/dependencies/CssExportDependency.js +2 -2
- package/lib/dependencies/CssLocalIdentifierDependency.js +71 -9
- package/lib/dependencies/CssUrlDependency.js +10 -7
- package/lib/dependencies/ExportsInfoDependency.js +5 -4
- package/lib/dependencies/ExternalModuleDependency.js +4 -2
- package/lib/dependencies/ExternalModuleInitFragment.js +5 -3
- package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +4 -4
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +43 -23
- package/lib/dependencies/HarmonyExportHeaderDependency.js +1 -1
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +73 -32
- package/lib/dependencies/HarmonyExportInitFragment.js +10 -2
- package/lib/dependencies/HarmonyImportDependency.js +28 -12
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +70 -19
- package/lib/dependencies/HarmonyImportSideEffectDependency.js +7 -6
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +47 -35
- package/lib/dependencies/ImportDependency.js +9 -2
- package/lib/dependencies/ImportEagerDependency.js +4 -2
- package/lib/dependencies/ImportMetaContextDependency.js +7 -0
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +25 -14
- package/lib/dependencies/ImportMetaPlugin.js +1 -1
- package/lib/dependencies/ImportParserPlugin.js +15 -5
- package/lib/dependencies/ImportWeakDependency.js +4 -2
- package/lib/dependencies/LoaderDependency.js +2 -1
- package/lib/dependencies/LoaderImportDependency.js +2 -1
- package/lib/dependencies/LoaderPlugin.js +2 -2
- package/lib/dependencies/ModuleDependency.js +4 -5
- package/lib/dependencies/PureExpressionDependency.js +64 -47
- package/lib/dependencies/RequireContextPlugin.js +1 -1
- package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +26 -14
- package/lib/dependencies/RequireEnsureDependency.js +1 -1
- package/lib/dependencies/URLDependency.js +7 -4
- package/lib/dependencies/WorkerDependency.js +1 -1
- package/lib/dependencies/WorkerPlugin.js +2 -1
- package/lib/dependencies/getFunctionExpression.js +3 -1
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +92 -3
- package/lib/hmr/LazyCompilationPlugin.js +2 -2
- package/lib/ids/ChunkModuleIdRangePlugin.js +1 -1
- package/lib/ids/DeterministicChunkIdsPlugin.js +1 -1
- package/lib/ids/DeterministicModuleIdsPlugin.js +1 -1
- package/lib/ids/IdHelpers.js +6 -6
- package/lib/ids/NamedChunkIdsPlugin.js +1 -1
- package/lib/ids/NamedModuleIdsPlugin.js +1 -1
- package/lib/ids/SyncModuleIdsPlugin.js +2 -2
- package/lib/index.js +11 -0
- package/lib/javascript/BasicEvaluatedExpression.js +2 -2
- package/lib/javascript/ChunkHelpers.js +2 -2
- package/lib/javascript/CommonJsChunkFormatPlugin.js +1 -1
- package/lib/javascript/JavascriptGenerator.js +0 -1
- package/lib/javascript/JavascriptModulesPlugin.js +174 -17
- package/lib/javascript/JavascriptParser.js +204 -71
- package/lib/javascript/JavascriptParserHelpers.js +1 -1
- package/lib/javascript/StartupHelpers.js +22 -5
- package/lib/library/AbstractLibraryPlugin.js +2 -2
- package/lib/library/AmdLibraryPlugin.js +2 -2
- package/lib/library/AssignLibraryPlugin.js +3 -3
- package/lib/library/ExportPropertyLibraryPlugin.js +2 -2
- package/lib/library/JsonpLibraryPlugin.js +2 -2
- package/lib/library/ModuleLibraryPlugin.js +2 -2
- package/lib/library/SystemLibraryPlugin.js +2 -2
- package/lib/library/UmdLibraryPlugin.js +33 -12
- package/lib/logging/Logger.js +27 -2
- package/lib/logging/createConsoleLogger.js +13 -9
- package/lib/node/CommonJsChunkLoadingPlugin.js +2 -1
- package/lib/node/NodeEnvironmentPlugin.js +14 -8
- package/lib/node/NodeTemplatePlugin.js +1 -1
- package/lib/node/NodeWatchFileSystem.js +37 -26
- package/lib/node/ReadFileChunkLoadingRuntimeModule.js +2 -1
- package/lib/node/ReadFileCompileWasmPlugin.js +1 -1
- package/lib/node/RequireChunkLoadingRuntimeModule.js +2 -1
- package/lib/node/nodeConsole.js +24 -1
- package/lib/optimize/AggressiveMergingPlugin.js +1 -1
- package/lib/optimize/AggressiveSplittingPlugin.js +1 -0
- package/lib/optimize/ConcatenatedModule.js +140 -121
- package/lib/optimize/EnsureChunkConditionsPlugin.js +1 -1
- package/lib/optimize/InnerGraph.js +8 -3
- package/lib/optimize/InnerGraphPlugin.js +36 -13
- package/lib/optimize/LimitChunkCountPlugin.js +1 -2
- package/lib/optimize/ModuleConcatenationPlugin.js +13 -3
- package/lib/optimize/RealContentHashPlugin.js +3 -3
- package/lib/optimize/RemoveParentModulesPlugin.js +1 -0
- package/lib/optimize/RuntimeChunkPlugin.js +6 -1
- package/lib/optimize/SideEffectsFlagPlugin.js +48 -17
- package/lib/optimize/SplitChunksPlugin.js +10 -10
- package/lib/performance/SizeLimitsPlugin.js +13 -2
- package/lib/rules/ObjectMatcherRulePlugin.js +15 -1
- package/lib/rules/RuleSetCompiler.js +9 -7
- package/lib/runtime/EnsureChunkRuntimeModule.js +2 -1
- package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +2 -1
- package/lib/runtime/LoadScriptRuntimeModule.js +1 -1
- package/lib/runtime/StartupChunkDependenciesPlugin.js +1 -1
- package/lib/schemes/HttpUriPlugin.js +1 -1
- package/lib/serialization/BinaryMiddleware.js +4 -4
- package/lib/serialization/FileMiddleware.js +4 -3
- package/lib/serialization/NullPrototypeObjectSerializer.js +2 -2
- package/lib/serialization/ObjectMiddleware.js +8 -5
- package/lib/serialization/PlainObjectSerializer.js +2 -2
- package/lib/serialization/Serializer.js +19 -0
- package/lib/serialization/SerializerMiddleware.js +2 -2
- package/lib/serialization/SingleItemMiddleware.js +2 -2
- package/lib/serialization/types.js +1 -1
- package/lib/sharing/ConsumeSharedModule.js +2 -2
- package/lib/sharing/ConsumeSharedPlugin.js +17 -3
- package/lib/sharing/ConsumeSharedRuntimeModule.js +9 -2
- package/lib/sharing/ProvideSharedPlugin.js +13 -6
- package/lib/sharing/resolveMatchedConfigs.js +3 -3
- package/lib/sharing/utils.js +13 -6
- package/lib/stats/DefaultStatsFactoryPlugin.js +20 -20
- package/lib/stats/DefaultStatsPrinterPlugin.js +1 -1
- package/lib/stats/StatsFactory.js +2 -2
- package/lib/stats/StatsPrinter.js +6 -6
- package/lib/util/ArrayQueue.js +14 -21
- package/lib/util/AsyncQueue.js +1 -1
- package/lib/util/Queue.js +8 -2
- package/lib/util/SortableSet.js +16 -4
- package/lib/util/StackedCacheMap.js +26 -0
- package/lib/util/TupleQueue.js +8 -2
- package/lib/util/WeakTupleMap.js +57 -13
- package/lib/util/binarySearchBounds.js +1 -1
- package/lib/util/cleverMerge.js +26 -13
- package/lib/util/comparators.js +37 -15
- package/lib/util/conventions.js +129 -0
- package/lib/util/createHash.js +3 -5
- package/lib/util/deprecation.js +3 -3
- package/lib/util/deterministicGrouping.js +2 -2
- package/lib/util/findGraphRoots.js +1 -1
- package/lib/util/fs.js +383 -69
- package/lib/util/hash/BatchedHash.js +3 -0
- package/lib/util/hash/xxhash64.js +2 -2
- package/lib/util/identifier.js +5 -5
- package/lib/util/mergeScope.js +79 -0
- package/lib/util/runtime.js +2 -17
- package/lib/util/semver.js +3 -0
- package/lib/util/smartGrouping.js +3 -3
- package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +4 -2
- package/lib/wasm-async/AsyncWebAssemblyGenerator.js +1 -1
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +4 -2
- package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +3 -3
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +16 -7
- package/lib/wasm-sync/WebAssemblyGenerator.js +40 -19
- package/lib/wasm-sync/WebAssemblyModulesPlugin.js +1 -1
- package/lib/wasm-sync/WebAssemblyParser.js +7 -4
- package/lib/wasm-sync/WebAssemblyUtils.js +2 -1
- package/lib/web/FetchCompileWasmPlugin.js +1 -1
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +3 -2
- package/lib/webpack.js +19 -6
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +2 -1
- package/package.json +40 -39
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +97 -8
- package/schemas/plugins/BannerPlugin.check.js +1 -1
- package/schemas/plugins/BannerPlugin.json +5 -1
- package/schemas/plugins/css/CssAutoGeneratorOptions.check.js +1 -1
- package/schemas/plugins/css/CssGeneratorOptions.check.js +1 -1
- package/schemas/plugins/css/CssGlobalGeneratorOptions.check.js +1 -1
- package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +1 -1
- package/types.d.ts +1826 -639
@@ -10,9 +10,14 @@ const { UsageState } = require("../ExportsInfo");
|
|
10
10
|
const Generator = require("../Generator");
|
11
11
|
const RuntimeGlobals = require("../RuntimeGlobals");
|
12
12
|
const Template = require("../Template");
|
13
|
+
const { cssExportConvention } = require("../util/conventions");
|
13
14
|
|
14
15
|
/** @typedef {import("webpack-sources").Source} Source */
|
16
|
+
/** @typedef {import("../../declarations/WebpackOptions").CssGeneratorExportsConvention} CssGeneratorExportsConvention */
|
17
|
+
/** @typedef {import("../../declarations/WebpackOptions").CssGeneratorLocalIdentName} CssGeneratorLocalIdentName */
|
15
18
|
/** @typedef {import("../Dependency")} Dependency */
|
19
|
+
/** @typedef {import("../DependencyTemplate").CssDependencyTemplateContext} DependencyTemplateContext */
|
20
|
+
/** @typedef {import("../DependencyTemplate").CssExportsData} CssExportsData */
|
16
21
|
/** @typedef {import("../Generator").GenerateContext} GenerateContext */
|
17
22
|
/** @typedef {import("../Generator").UpdateHashContext} UpdateHashContext */
|
18
23
|
/** @typedef {import("../Module").ConcatenationBailoutReasonContext} ConcatenationBailoutReasonContext */
|
@@ -27,12 +32,39 @@ const Template = require("../Template");
|
|
27
32
|
const TYPES = new Set(["javascript"]);
|
28
33
|
|
29
34
|
class CssExportsGenerator extends Generator {
|
30
|
-
|
35
|
+
/**
|
36
|
+
* @param {CssGeneratorExportsConvention | undefined} convention the convention of the exports name
|
37
|
+
* @param {CssGeneratorLocalIdentName | undefined} localIdentName css export local ident name
|
38
|
+
* @param {boolean} esModule whether to use ES modules syntax
|
39
|
+
*/
|
40
|
+
constructor(convention, localIdentName, esModule) {
|
31
41
|
super();
|
42
|
+
/** @type {CssGeneratorExportsConvention | undefined} */
|
43
|
+
this.convention = convention;
|
44
|
+
/** @type {CssGeneratorLocalIdentName | undefined} */
|
45
|
+
this.localIdentName = localIdentName;
|
46
|
+
/** @type {boolean} */
|
47
|
+
this.esModule = esModule;
|
32
48
|
}
|
33
49
|
|
34
|
-
|
35
|
-
|
50
|
+
/**
|
51
|
+
* @param {NormalModule} module module for which the bailout reason should be determined
|
52
|
+
* @param {ConcatenationBailoutReasonContext} context context
|
53
|
+
* @returns {string | undefined} reason why this module can't be concatenated, undefined when it can be concatenated
|
54
|
+
*/
|
55
|
+
getConcatenationBailoutReason(module, context) {
|
56
|
+
if (!this.esModule) {
|
57
|
+
return "Module is not an ECMAScript module";
|
58
|
+
}
|
59
|
+
// TODO webpack 6: remove /\[moduleid\]/.test
|
60
|
+
if (
|
61
|
+
/\[id\]/.test(this.localIdentName) ||
|
62
|
+
/\[moduleid\]/.test(this.localIdentName)
|
63
|
+
) {
|
64
|
+
return "The localIdentName includes moduleId ([id] or [moduleid])";
|
65
|
+
}
|
66
|
+
return undefined;
|
67
|
+
}
|
36
68
|
|
37
69
|
/**
|
38
70
|
* @param {NormalModule} module module for which the code should be generated
|
@@ -43,13 +75,18 @@ class CssExportsGenerator extends Generator {
|
|
43
75
|
const source = new ReplaceSource(new RawSource(""));
|
44
76
|
/** @type {InitFragment<TODO>[]} */
|
45
77
|
const initFragments = [];
|
46
|
-
|
78
|
+
/** @type {CssExportsData} */
|
79
|
+
const cssExportsData = {
|
80
|
+
esModule: this.esModule,
|
81
|
+
exports: new Map()
|
82
|
+
};
|
47
83
|
|
48
84
|
generateContext.runtimeRequirements.add(RuntimeGlobals.module);
|
49
85
|
|
50
86
|
let chunkInitFragments;
|
51
87
|
const runtimeRequirements = new Set();
|
52
88
|
|
89
|
+
/** @type {DependencyTemplateContext} */
|
53
90
|
const templateContext = {
|
54
91
|
runtimeTemplate: generateContext.runtimeTemplate,
|
55
92
|
dependencyTemplates: generateContext.dependencyTemplates,
|
@@ -61,7 +98,7 @@ class CssExportsGenerator extends Generator {
|
|
61
98
|
concatenationScope: generateContext.concatenationScope,
|
62
99
|
codeGenerationResults: generateContext.codeGenerationResults,
|
63
100
|
initFragments,
|
64
|
-
|
101
|
+
cssExportsData,
|
65
102
|
get chunkInitFragments() {
|
66
103
|
if (!chunkInitFragments) {
|
67
104
|
const data = generateContext.getData();
|
@@ -97,39 +134,45 @@ class CssExportsGenerator extends Generator {
|
|
97
134
|
if (generateContext.concatenationScope) {
|
98
135
|
const source = new ConcatSource();
|
99
136
|
const usedIdentifiers = new Set();
|
100
|
-
for (const [
|
101
|
-
let
|
102
|
-
|
103
|
-
|
104
|
-
|
137
|
+
for (const [name, v] of cssExportsData.exports) {
|
138
|
+
for (let k of cssExportConvention(name, this.convention)) {
|
139
|
+
let identifier = Template.toIdentifier(k);
|
140
|
+
let i = 0;
|
141
|
+
while (usedIdentifiers.has(identifier)) {
|
142
|
+
identifier = Template.toIdentifier(k + i);
|
143
|
+
}
|
144
|
+
usedIdentifiers.add(identifier);
|
145
|
+
generateContext.concatenationScope.registerExport(k, identifier);
|
146
|
+
source.add(
|
147
|
+
`${
|
148
|
+
generateContext.runtimeTemplate.supportsConst() ? "const" : "var"
|
149
|
+
} ${identifier} = ${JSON.stringify(v)};\n`
|
150
|
+
);
|
105
151
|
}
|
106
|
-
usedIdentifiers.add(identifier);
|
107
|
-
generateContext.concatenationScope.registerExport(k, identifier);
|
108
|
-
source.add(
|
109
|
-
`${
|
110
|
-
generateContext.runtimeTemplate.supportsConst ? "const" : "var"
|
111
|
-
} ${identifier} = ${JSON.stringify(v)};\n`
|
112
|
-
);
|
113
152
|
}
|
114
153
|
return source;
|
115
154
|
} else {
|
116
|
-
const
|
155
|
+
const needNsObj =
|
156
|
+
this.esModule &&
|
117
157
|
generateContext.moduleGraph
|
118
158
|
.getExportsInfo(module)
|
119
159
|
.otherExportsInfo.getUsed(generateContext.runtime) !==
|
120
|
-
|
121
|
-
if (
|
160
|
+
UsageState.Unused;
|
161
|
+
if (needNsObj) {
|
122
162
|
generateContext.runtimeRequirements.add(
|
123
163
|
RuntimeGlobals.makeNamespaceObject
|
124
164
|
);
|
125
165
|
}
|
166
|
+
const newExports = [];
|
167
|
+
for (let [k, v] of cssExportsData.exports) {
|
168
|
+
for (let name of cssExportConvention(k, this.convention)) {
|
169
|
+
newExports.push(`\t${JSON.stringify(name)}: ${JSON.stringify(v)}`);
|
170
|
+
}
|
171
|
+
}
|
126
172
|
return new RawSource(
|
127
|
-
`${
|
173
|
+
`${needNsObj ? `${RuntimeGlobals.makeNamespaceObject}(` : ""}${
|
128
174
|
module.moduleArgument
|
129
|
-
}.exports = {\n${
|
130
|
-
cssExports,
|
131
|
-
([k, v]) => `\t${JSON.stringify(k)}: ${JSON.stringify(v)}`
|
132
|
-
).join(",\n")}\n}${otherUsed ? ")" : ""};`
|
175
|
+
}.exports = {\n${newExports.join(",\n")}\n}${needNsObj ? ")" : ""};`
|
133
176
|
);
|
134
177
|
}
|
135
178
|
}
|
package/lib/css/CssGenerator.js
CHANGED
@@ -9,9 +9,14 @@ const { ReplaceSource } = require("webpack-sources");
|
|
9
9
|
const Generator = require("../Generator");
|
10
10
|
const InitFragment = require("../InitFragment");
|
11
11
|
const RuntimeGlobals = require("../RuntimeGlobals");
|
12
|
+
const { cssExportConvention } = require("../util/conventions");
|
12
13
|
|
13
14
|
/** @typedef {import("webpack-sources").Source} Source */
|
15
|
+
/** @typedef {import("../../declarations/WebpackOptions").CssGeneratorExportsConvention} CssGeneratorExportsConvention */
|
16
|
+
/** @typedef {import("../../declarations/WebpackOptions").CssGeneratorLocalIdentName} CssGeneratorLocalIdentName */
|
14
17
|
/** @typedef {import("../Dependency")} Dependency */
|
18
|
+
/** @typedef {import("../DependencyTemplate").CssDependencyTemplateContext} DependencyTemplateContext */
|
19
|
+
/** @typedef {import("../DependencyTemplate").CssExportsData} CssExportsData */
|
15
20
|
/** @typedef {import("../Generator").GenerateContext} GenerateContext */
|
16
21
|
/** @typedef {import("../Generator").UpdateHashContext} UpdateHashContext */
|
17
22
|
/** @typedef {import("../NormalModule")} NormalModule */
|
@@ -20,8 +25,19 @@ const RuntimeGlobals = require("../RuntimeGlobals");
|
|
20
25
|
const TYPES = new Set(["css"]);
|
21
26
|
|
22
27
|
class CssGenerator extends Generator {
|
23
|
-
|
28
|
+
/**
|
29
|
+
* @param {CssGeneratorExportsConvention | undefined} convention the convention of the exports name
|
30
|
+
* @param {CssGeneratorLocalIdentName | undefined} localIdentName css export local ident name
|
31
|
+
* @param {boolean} esModule whether to use ES modules syntax
|
32
|
+
*/
|
33
|
+
constructor(convention, localIdentName, esModule) {
|
24
34
|
super();
|
35
|
+
/** @type {CssGeneratorExportsConvention | undefined} */
|
36
|
+
this.convention = convention;
|
37
|
+
/** @type {CssGeneratorLocalIdentName | undefined} */
|
38
|
+
this.localIdentName = localIdentName;
|
39
|
+
/** @type {boolean} */
|
40
|
+
this.esModule = esModule;
|
25
41
|
}
|
26
42
|
|
27
43
|
/**
|
@@ -34,11 +50,16 @@ class CssGenerator extends Generator {
|
|
34
50
|
const source = new ReplaceSource(originalSource);
|
35
51
|
/** @type {InitFragment[]} */
|
36
52
|
const initFragments = [];
|
37
|
-
|
53
|
+
/** @type {CssExportsData} */
|
54
|
+
const cssExportsData = {
|
55
|
+
esModule: this.esModule,
|
56
|
+
exports: new Map()
|
57
|
+
};
|
38
58
|
|
39
59
|
generateContext.runtimeRequirements.add(RuntimeGlobals.hasCssModules);
|
40
60
|
|
41
61
|
let chunkInitFragments;
|
62
|
+
/** @type {DependencyTemplateContext} */
|
42
63
|
const templateContext = {
|
43
64
|
runtimeTemplate: generateContext.runtimeTemplate,
|
44
65
|
dependencyTemplates: generateContext.dependencyTemplates,
|
@@ -50,7 +71,7 @@ class CssGenerator extends Generator {
|
|
50
71
|
concatenationScope: generateContext.concatenationScope,
|
51
72
|
codeGenerationResults: generateContext.codeGenerationResults,
|
52
73
|
initFragments,
|
53
|
-
|
74
|
+
cssExportsData,
|
54
75
|
get chunkInitFragments() {
|
55
76
|
if (!chunkInitFragments) {
|
56
77
|
const data = generateContext.getData();
|
@@ -85,10 +106,17 @@ class CssGenerator extends Generator {
|
|
85
106
|
if (module.presentationalDependencies !== undefined)
|
86
107
|
module.presentationalDependencies.forEach(handleDependency);
|
87
108
|
|
88
|
-
if (
|
89
|
-
const
|
90
|
-
|
109
|
+
if (cssExportsData.exports.size > 0) {
|
110
|
+
const newExports = new Map();
|
111
|
+
for (let [name, v] of cssExportsData.exports) {
|
112
|
+
for (let newName of cssExportConvention(name, this.convention)) {
|
113
|
+
newExports.set(newName, v);
|
114
|
+
}
|
115
|
+
}
|
116
|
+
cssExportsData.exports = newExports;
|
91
117
|
}
|
118
|
+
const data = generateContext.getData();
|
119
|
+
data.set("css-exports", cssExportsData);
|
92
120
|
|
93
121
|
return InitFragment.addToSource(source, initFragments, generateContext);
|
94
122
|
}
|
@@ -16,19 +16,22 @@ const { chunkHasCss } = require("./CssModulesPlugin");
|
|
16
16
|
/** @typedef {import("../Chunk")} Chunk */
|
17
17
|
/** @typedef {import("../ChunkGraph")} ChunkGraph */
|
18
18
|
/** @typedef {import("../Compilation").RuntimeRequirementsContext} RuntimeRequirementsContext */
|
19
|
+
/** @typedef {import("../Module").ReadOnlyRuntimeRequirements} ReadOnlyRuntimeRequirements */
|
19
20
|
|
20
21
|
/**
|
21
|
-
* @typedef {
|
22
|
+
* @typedef {object} CssLoadingRuntimeModulePluginHooks
|
22
23
|
* @property {SyncWaterfallHook<[string, Chunk]>} createStylesheet
|
24
|
+
* @property {SyncWaterfallHook<[string, Chunk]>} linkPreload
|
25
|
+
* @property {SyncWaterfallHook<[string, Chunk]>} linkPrefetch
|
23
26
|
*/
|
24
27
|
|
25
|
-
/** @type {WeakMap<Compilation,
|
28
|
+
/** @type {WeakMap<Compilation, CssLoadingRuntimeModulePluginHooks>} */
|
26
29
|
const compilationHooksMap = new WeakMap();
|
27
30
|
|
28
31
|
class CssLoadingRuntimeModule extends RuntimeModule {
|
29
32
|
/**
|
30
33
|
* @param {Compilation} compilation the compilation
|
31
|
-
* @returns {
|
34
|
+
* @returns {CssLoadingRuntimeModulePluginHooks} hooks
|
32
35
|
*/
|
33
36
|
static getCompilationHooks(compilation) {
|
34
37
|
if (!(compilation instanceof Compilation)) {
|
@@ -39,7 +42,9 @@ class CssLoadingRuntimeModule extends RuntimeModule {
|
|
39
42
|
let hooks = compilationHooksMap.get(compilation);
|
40
43
|
if (hooks === undefined) {
|
41
44
|
hooks = {
|
42
|
-
createStylesheet: new SyncWaterfallHook(["source", "chunk"])
|
45
|
+
createStylesheet: new SyncWaterfallHook(["source", "chunk"]),
|
46
|
+
linkPreload: new SyncWaterfallHook(["source", "chunk"]),
|
47
|
+
linkPrefetch: new SyncWaterfallHook(["source", "chunk"])
|
43
48
|
};
|
44
49
|
compilationHooksMap.set(compilation, hooks);
|
45
50
|
}
|
@@ -47,7 +52,7 @@ class CssLoadingRuntimeModule extends RuntimeModule {
|
|
47
52
|
}
|
48
53
|
|
49
54
|
/**
|
50
|
-
* @param {
|
55
|
+
* @param {ReadOnlyRuntimeRequirements} runtimeRequirements runtime requirements
|
51
56
|
*/
|
52
57
|
constructor(runtimeRequirements) {
|
53
58
|
super("css loading", 10);
|
@@ -59,16 +64,19 @@ class CssLoadingRuntimeModule extends RuntimeModule {
|
|
59
64
|
* @returns {string | null} runtime code
|
60
65
|
*/
|
61
66
|
generate() {
|
62
|
-
const {
|
67
|
+
const { _runtimeRequirements } = this;
|
68
|
+
const compilation = /** @type {Compilation} */ (this.compilation);
|
69
|
+
const chunk = /** @type {Chunk} */ (this.chunk);
|
63
70
|
const {
|
64
71
|
chunkGraph,
|
65
72
|
runtimeTemplate,
|
66
73
|
outputOptions: {
|
67
74
|
crossOriginLoading,
|
68
75
|
uniqueName,
|
69
|
-
chunkLoadTimeout: loadTimeout
|
76
|
+
chunkLoadTimeout: loadTimeout,
|
77
|
+
cssHeadDataCompression: withCompression
|
70
78
|
}
|
71
|
-
} =
|
79
|
+
} = compilation;
|
72
80
|
const fn = RuntimeGlobals.ensureChunkHandlers;
|
73
81
|
const conditionMap = chunkGraph.getChunkConditionMap(
|
74
82
|
/** @type {Chunk} */ (chunk),
|
@@ -85,6 +93,12 @@ class CssLoadingRuntimeModule extends RuntimeModule {
|
|
85
93
|
const withLoading =
|
86
94
|
_runtimeRequirements.has(RuntimeGlobals.ensureChunkHandlers) &&
|
87
95
|
hasCssMatcher !== false;
|
96
|
+
const withPrefetch = this._runtimeRequirements.has(
|
97
|
+
RuntimeGlobals.prefetchChunkHandlers
|
98
|
+
);
|
99
|
+
const withPreload = this._runtimeRequirements.has(
|
100
|
+
RuntimeGlobals.preloadChunkHandlers
|
101
|
+
);
|
88
102
|
/** @type {boolean} */
|
89
103
|
const withHmr = _runtimeRequirements.has(
|
90
104
|
RuntimeGlobals.hmrDownloadUpdateHandlers
|
@@ -104,19 +118,39 @@ class CssLoadingRuntimeModule extends RuntimeModule {
|
|
104
118
|
return null;
|
105
119
|
}
|
106
120
|
|
107
|
-
const {
|
108
|
-
|
121
|
+
const { linkPreload, linkPrefetch } =
|
122
|
+
CssLoadingRuntimeModule.getCompilationHooks(compilation);
|
123
|
+
|
124
|
+
const withFetchPriority = _runtimeRequirements.has(
|
125
|
+
RuntimeGlobals.hasFetchPriority
|
109
126
|
);
|
110
127
|
|
128
|
+
const { createStylesheet } =
|
129
|
+
CssLoadingRuntimeModule.getCompilationHooks(compilation);
|
130
|
+
|
111
131
|
const stateExpression = withHmr
|
112
132
|
? `${RuntimeGlobals.hmrRuntimeStatePrefix}_css`
|
113
133
|
: undefined;
|
114
134
|
|
115
135
|
const code = Template.asString([
|
116
136
|
"link = document.createElement('link');",
|
137
|
+
`if (${RuntimeGlobals.scriptNonce}) {`,
|
138
|
+
Template.indent(
|
139
|
+
`link.setAttribute("nonce", ${RuntimeGlobals.scriptNonce});`
|
140
|
+
),
|
141
|
+
"}",
|
117
142
|
uniqueName
|
118
143
|
? 'link.setAttribute("data-webpack", uniqueName + ":" + key);'
|
119
144
|
: "",
|
145
|
+
withFetchPriority
|
146
|
+
? Template.asString([
|
147
|
+
"if(fetchPriority) {",
|
148
|
+
Template.indent(
|
149
|
+
'link.setAttribute("fetchpriority", fetchPriority);'
|
150
|
+
),
|
151
|
+
"}"
|
152
|
+
])
|
153
|
+
: "",
|
120
154
|
"link.setAttribute(loadingAttribute, 1);",
|
121
155
|
'link.rel = "stylesheet";',
|
122
156
|
"link.href = url;",
|
@@ -163,9 +197,9 @@ class CssLoadingRuntimeModule extends RuntimeModule {
|
|
163
197
|
`var loadCssChunkData = ${runtimeTemplate.basicFunction(
|
164
198
|
"target, link, chunkId",
|
165
199
|
[
|
166
|
-
`var data, token = "", token2, exports = {},
|
200
|
+
`var data, token = "", token2 = "", exports = {}, ${
|
167
201
|
withHmr ? "moduleIds = [], " : ""
|
168
|
-
}name = ${name}, i
|
202
|
+
}name = ${name}, i, cc = 1;`,
|
169
203
|
"try {",
|
170
204
|
Template.indent([
|
171
205
|
"if(!link) link = loadStylesheet(chunkId);",
|
@@ -187,46 +221,44 @@ class CssLoadingRuntimeModule extends RuntimeModule {
|
|
187
221
|
]),
|
188
222
|
"}",
|
189
223
|
"if(!data) return [];",
|
190
|
-
|
224
|
+
withCompression
|
225
|
+
? Template.asString([
|
226
|
+
// LZW decode
|
227
|
+
`var map = {}, char = data[0], oldPhrase = char, decoded = char, code = 256, maxCode = ${"\uffff".charCodeAt(
|
228
|
+
0
|
229
|
+
)}, phrase;`,
|
230
|
+
"for (i = 1; i < data.length; i++) {",
|
231
|
+
Template.indent([
|
232
|
+
"cc = data[i].charCodeAt(0);",
|
233
|
+
"if (cc < 256) phrase = data[i]; else phrase = map[cc] ? map[cc] : (oldPhrase + char);",
|
234
|
+
"decoded += phrase;",
|
235
|
+
"char = phrase.charAt(0);",
|
236
|
+
"map[code] = oldPhrase + char;",
|
237
|
+
"if (++code > maxCode) { code = 256; map = {}; }",
|
238
|
+
"oldPhrase = phrase;"
|
239
|
+
]),
|
240
|
+
"}",
|
241
|
+
"data = decoded;"
|
242
|
+
])
|
243
|
+
: "// css head data compression is disabled",
|
244
|
+
"for(i = 0; cc; i++) {",
|
191
245
|
Template.indent([
|
192
246
|
"cc = data.charCodeAt(i);",
|
193
|
-
`if(cc == ${cc("
|
247
|
+
`if(cc == ${cc(":")}) { token2 = token; token = ""; }`,
|
194
248
|
`else if(cc == ${cc(
|
195
|
-
"
|
196
|
-
)}) {
|
197
|
-
`else if(cc == ${cc("
|
198
|
-
|
199
|
-
|
200
|
-
"%"
|
201
|
-
)}) exportsWithDashes.push(token); token = ""; }`,
|
249
|
+
"/"
|
250
|
+
)}) { token = token.replace(/^_/, ""); token2 = token2.replace(/^_/, ""); exports[token2] = token; token = ""; token2 = ""; }`,
|
251
|
+
`else if(cc == ${cc("&")}) { ${
|
252
|
+
RuntimeGlobals.makeNamespaceObject
|
253
|
+
}(exports); }`,
|
202
254
|
`else if(!cc || cc == ${cc(
|
203
255
|
","
|
204
|
-
)}) { token = token.replace(/^_/, "");
|
205
|
-
`exports[x] = ${
|
206
|
-
uniqueName
|
207
|
-
? runtimeTemplate.concatenation(
|
208
|
-
{ expr: "uniqueName" },
|
209
|
-
"-",
|
210
|
-
{ expr: "token" },
|
211
|
-
"-",
|
212
|
-
{ expr: "exports[x]" }
|
213
|
-
)
|
214
|
-
: runtimeTemplate.concatenation({ expr: "token" }, "-", {
|
215
|
-
expr: "exports[x]"
|
216
|
-
})
|
217
|
-
}`,
|
218
|
-
"x"
|
219
|
-
)}); exportsWithDashes.forEach(${runtimeTemplate.expressionFunction(
|
220
|
-
`exports[x] = "--" + exports[x]`,
|
221
|
-
"x"
|
222
|
-
)}); ${
|
223
|
-
RuntimeGlobals.makeNamespaceObject
|
224
|
-
}(exports); target[token] = (${runtimeTemplate.basicFunction(
|
256
|
+
)}) { token = token.replace(/^_/, ""); target[token] = (${runtimeTemplate.basicFunction(
|
225
257
|
"exports, module",
|
226
258
|
`module.exports = exports;`
|
227
259
|
)}).bind(null, exports); ${
|
228
260
|
withHmr ? "moduleIds.push(token); " : ""
|
229
|
-
}token = "";
|
261
|
+
}token = ""; token2 = ""; exports = {}; }`,
|
230
262
|
`else if(cc == ${cc("\\")}) { token += data[++i] }`,
|
231
263
|
`else { token += data[i]; }`
|
232
264
|
]),
|
@@ -239,7 +271,9 @@ class CssLoadingRuntimeModule extends RuntimeModule {
|
|
239
271
|
)}`,
|
240
272
|
'var loadingAttribute = "data-webpack-loading";',
|
241
273
|
`var loadStylesheet = ${runtimeTemplate.basicFunction(
|
242
|
-
"chunkId, url, done" +
|
274
|
+
"chunkId, url, done" +
|
275
|
+
(withHmr ? ", hmr" : "") +
|
276
|
+
(withFetchPriority ? ", fetchPriority" : ""),
|
243
277
|
[
|
244
278
|
'var link, needAttach, key = "chunk-" + chunkId;',
|
245
279
|
withHmr ? "if(!hmr) {" : "",
|
@@ -307,74 +341,159 @@ class CssLoadingRuntimeModule extends RuntimeModule {
|
|
307
341
|
"",
|
308
342
|
withLoading
|
309
343
|
? Template.asString([
|
310
|
-
`${fn}.css = ${runtimeTemplate.basicFunction(
|
311
|
-
"
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
"",
|
316
|
-
'// a Promise means "currently loading".',
|
317
|
-
"if(installedChunkData) {",
|
318
|
-
Template.indent(["promises.push(installedChunkData[2]);"]),
|
319
|
-
"} else {",
|
344
|
+
`${fn}.css = ${runtimeTemplate.basicFunction(
|
345
|
+
`chunkId, promises${withFetchPriority ? " , fetchPriority" : ""}`,
|
346
|
+
[
|
347
|
+
"// css chunk loading",
|
348
|
+
`var installedChunkData = ${RuntimeGlobals.hasOwnProperty}(installedChunks, chunkId) ? installedChunks[chunkId] : undefined;`,
|
349
|
+
'if(installedChunkData !== 0) { // 0 means "already installed".',
|
320
350
|
Template.indent([
|
321
|
-
|
322
|
-
|
323
|
-
|
351
|
+
"",
|
352
|
+
'// a Promise means "currently loading".',
|
353
|
+
"if(installedChunkData) {",
|
354
|
+
Template.indent(["promises.push(installedChunkData[2]);"]),
|
355
|
+
"} else {",
|
324
356
|
Template.indent([
|
325
|
-
|
326
|
-
|
327
|
-
`
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
357
|
+
hasCssMatcher === true
|
358
|
+
? "if(true) { // all chunks have CSS"
|
359
|
+
: `if(${hasCssMatcher("chunkId")}) {`,
|
360
|
+
Template.indent([
|
361
|
+
"// setup Promise in chunk cache",
|
362
|
+
`var promise = new Promise(${runtimeTemplate.expressionFunction(
|
363
|
+
`installedChunkData = installedChunks[chunkId] = [resolve, reject]`,
|
364
|
+
"resolve, reject"
|
365
|
+
)});`,
|
366
|
+
"promises.push(installedChunkData[2] = promise);",
|
367
|
+
"",
|
368
|
+
"// start chunk loading",
|
369
|
+
`var url = ${RuntimeGlobals.publicPath} + ${RuntimeGlobals.getChunkCssFilename}(chunkId);`,
|
370
|
+
"// create error before stack unwound to get useful stacktrace later",
|
371
|
+
"var error = new Error();",
|
372
|
+
`var loadingEnded = ${runtimeTemplate.basicFunction(
|
373
|
+
"event",
|
374
|
+
[
|
375
|
+
`if(${RuntimeGlobals.hasOwnProperty}(installedChunks, chunkId)) {`,
|
344
376
|
Template.indent([
|
345
|
-
|
377
|
+
"installedChunkData = installedChunks[chunkId];",
|
378
|
+
"if(installedChunkData !== 0) installedChunks[chunkId] = undefined;",
|
379
|
+
"if(installedChunkData) {",
|
346
380
|
Template.indent([
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
381
|
+
'if(event.type !== "load") {',
|
382
|
+
Template.indent([
|
383
|
+
"var errorType = event && event.type;",
|
384
|
+
"var realHref = event && event.target && event.target.href;",
|
385
|
+
"error.message = 'Loading css chunk ' + chunkId + ' failed.\\n(' + errorType + ': ' + realHref + ')';",
|
386
|
+
"error.name = 'ChunkLoadError';",
|
387
|
+
"error.type = errorType;",
|
388
|
+
"error.request = realHref;",
|
389
|
+
"installedChunkData[1](error);"
|
390
|
+
]),
|
391
|
+
"} else {",
|
392
|
+
Template.indent([
|
393
|
+
`loadCssChunkData(${RuntimeGlobals.moduleFactories}, link, chunkId);`,
|
394
|
+
"installedChunkData[0]();"
|
395
|
+
]),
|
396
|
+
"}"
|
359
397
|
]),
|
360
398
|
"}"
|
361
399
|
]),
|
362
400
|
"}"
|
363
|
-
]
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
401
|
+
]
|
402
|
+
)};`,
|
403
|
+
`var link = loadStylesheet(chunkId, url, loadingEnded${
|
404
|
+
withFetchPriority ? ", fetchPriority" : ""
|
405
|
+
});`
|
406
|
+
]),
|
407
|
+
"} else installedChunks[chunkId] = 0;"
|
368
408
|
]),
|
369
|
-
"}
|
409
|
+
"}"
|
370
410
|
]),
|
371
411
|
"}"
|
372
|
-
]
|
373
|
-
|
374
|
-
])};`
|
412
|
+
]
|
413
|
+
)};`
|
375
414
|
])
|
376
415
|
: "// no chunk loading",
|
377
416
|
"",
|
417
|
+
withPrefetch && hasCssMatcher !== false
|
418
|
+
? `${
|
419
|
+
RuntimeGlobals.prefetchChunkHandlers
|
420
|
+
}.s = ${runtimeTemplate.basicFunction("chunkId", [
|
421
|
+
`if((!${
|
422
|
+
RuntimeGlobals.hasOwnProperty
|
423
|
+
}(installedChunks, chunkId) || installedChunks[chunkId] === undefined) && ${
|
424
|
+
hasCssMatcher === true ? "true" : hasCssMatcher("chunkId")
|
425
|
+
}) {`,
|
426
|
+
Template.indent([
|
427
|
+
"installedChunks[chunkId] = null;",
|
428
|
+
linkPrefetch.call(
|
429
|
+
Template.asString([
|
430
|
+
"var link = document.createElement('link');",
|
431
|
+
crossOriginLoading
|
432
|
+
? `link.crossOrigin = ${JSON.stringify(
|
433
|
+
crossOriginLoading
|
434
|
+
)};`
|
435
|
+
: "",
|
436
|
+
`if (${RuntimeGlobals.scriptNonce}) {`,
|
437
|
+
Template.indent(
|
438
|
+
`link.setAttribute("nonce", ${RuntimeGlobals.scriptNonce});`
|
439
|
+
),
|
440
|
+
"}",
|
441
|
+
'link.rel = "prefetch";',
|
442
|
+
'link.as = "style";',
|
443
|
+
`link.href = ${RuntimeGlobals.publicPath} + ${RuntimeGlobals.getChunkCssFilename}(chunkId);`
|
444
|
+
]),
|
445
|
+
chunk
|
446
|
+
),
|
447
|
+
"document.head.appendChild(link);"
|
448
|
+
]),
|
449
|
+
"}"
|
450
|
+
])};`
|
451
|
+
: "// no prefetching",
|
452
|
+
"",
|
453
|
+
withPreload && hasCssMatcher !== false
|
454
|
+
? `${
|
455
|
+
RuntimeGlobals.preloadChunkHandlers
|
456
|
+
}.s = ${runtimeTemplate.basicFunction("chunkId", [
|
457
|
+
`if((!${
|
458
|
+
RuntimeGlobals.hasOwnProperty
|
459
|
+
}(installedChunks, chunkId) || installedChunks[chunkId] === undefined) && ${
|
460
|
+
hasCssMatcher === true ? "true" : hasCssMatcher("chunkId")
|
461
|
+
}) {`,
|
462
|
+
Template.indent([
|
463
|
+
"installedChunks[chunkId] = null;",
|
464
|
+
linkPreload.call(
|
465
|
+
Template.asString([
|
466
|
+
"var link = document.createElement('link');",
|
467
|
+
"link.charset = 'utf-8';",
|
468
|
+
`if (${RuntimeGlobals.scriptNonce}) {`,
|
469
|
+
Template.indent(
|
470
|
+
`link.setAttribute("nonce", ${RuntimeGlobals.scriptNonce});`
|
471
|
+
),
|
472
|
+
"}",
|
473
|
+
'link.rel = "preload";',
|
474
|
+
'link.as = "style";',
|
475
|
+
`link.href = ${RuntimeGlobals.publicPath} + ${RuntimeGlobals.getChunkCssFilename}(chunkId);`,
|
476
|
+
crossOriginLoading
|
477
|
+
? crossOriginLoading === "use-credentials"
|
478
|
+
? 'link.crossOrigin = "use-credentials";'
|
479
|
+
: Template.asString([
|
480
|
+
"if (link.href.indexOf(window.location.origin + '/') !== 0) {",
|
481
|
+
Template.indent(
|
482
|
+
`link.crossOrigin = ${JSON.stringify(
|
483
|
+
crossOriginLoading
|
484
|
+
)};`
|
485
|
+
),
|
486
|
+
"}"
|
487
|
+
])
|
488
|
+
: ""
|
489
|
+
]),
|
490
|
+
chunk
|
491
|
+
),
|
492
|
+
"document.head.appendChild(link);"
|
493
|
+
]),
|
494
|
+
"}"
|
495
|
+
])};`
|
496
|
+
: "// no preloaded",
|
378
497
|
withHmr
|
379
498
|
? Template.asString([
|
380
499
|
"var oldTags = [];",
|