webpack 5.96.0 → 5.97.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/lib/CssModule.js +5 -0
- package/lib/DependencyTemplate.js +2 -2
- package/lib/EvalSourceMapDevToolPlugin.js +5 -0
- package/lib/FalseIIFEUmdWarning.js +19 -0
- package/lib/HotModuleReplacementPlugin.js +4 -0
- package/lib/Module.js +6 -0
- package/lib/ModuleSourceTypesConstants.js +12 -0
- package/lib/NormalModule.js +1 -0
- package/lib/RuntimeTemplate.js +7 -0
- package/lib/SourceMapDevToolPlugin.js +8 -0
- package/lib/WebpackOptionsApply.js +3 -1
- package/lib/asset/AssetModulesPlugin.js +7 -2
- package/lib/config/defaults.js +52 -36
- package/lib/config/normalization.js +0 -1
- package/lib/config/target.js +8 -8
- package/lib/css/CssGenerator.js +139 -35
- package/lib/css/CssLoadingRuntimeModule.js +108 -198
- package/lib/css/CssModulesPlugin.js +78 -124
- package/lib/css/CssParser.js +545 -121
- package/lib/css/walkCssTokens.js +41 -19
- package/lib/dependencies/CachedConstDependency.js +2 -1
- package/lib/dependencies/ContextDependencyTemplateAsId.js +3 -2
- package/lib/dependencies/{CssExportDependency.js → CssIcssExportDependency.js} +35 -35
- package/lib/dependencies/CssIcssImportDependency.js +118 -0
- package/lib/dependencies/CssIcssSymbolDependency.js +132 -0
- package/lib/dependencies/CssImportDependency.js +0 -8
- package/lib/dependencies/CssLocalIdentifierDependency.js +69 -73
- package/lib/dependencies/CssUrlDependency.js +1 -0
- package/lib/esm/ModuleChunkFormatPlugin.js +8 -4
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +17 -10
- package/lib/index.js +13 -6
- package/lib/javascript/EnableChunkLoadingPlugin.js +2 -4
- package/lib/library/AssignLibraryPlugin.js +1 -1
- package/lib/library/EnableLibraryPlugin.js +17 -0
- package/lib/node/ReadFileCompileAsyncWasmPlugin.js +81 -78
- package/lib/node/ReadFileCompileWasmPlugin.js +76 -57
- package/lib/optimize/MergeDuplicateChunksPlugin.js +22 -2
- package/lib/sharing/ConsumeSharedPlugin.js +35 -12
- package/lib/sharing/utils.js +35 -4
- package/lib/stats/DefaultStatsFactoryPlugin.js +0 -5
- package/lib/util/Queue.js +52 -24
- package/lib/util/generateDebugId.js +33 -0
- package/lib/util/internalSerializables.js +6 -2
- package/lib/wasm/EnableWasmLoadingPlugin.js +36 -25
- package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +26 -2
- package/lib/wasm-async/UniversalCompileAsyncWasmPlugin.js +103 -0
- package/lib/wasm-sync/WebAssemblyParser.js +1 -1
- package/lib/web/FetchCompileAsyncWasmPlugin.js +43 -44
- package/lib/web/FetchCompileWasmPlugin.js +4 -4
- package/package.json +5 -5
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +34 -12
- package/schemas/plugins/BannerPlugin.json +1 -1
- package/schemas/plugins/SourceMapDevToolPlugin.check.js +1 -1
- package/schemas/plugins/SourceMapDevToolPlugin.json +4 -0
- package/schemas/plugins/css/CssAutoParserOptions.check.js +1 -1
- package/schemas/plugins/css/CssGlobalParserOptions.check.js +1 -1
- package/schemas/plugins/css/CssModuleParserOptions.check.js +1 -1
- package/schemas/plugins/css/CssParserOptions.check.js +1 -1
- package/schemas/plugins/optimize/MergeDuplicateChunksPlugin.check.d.ts +7 -0
- package/schemas/plugins/optimize/MergeDuplicateChunksPlugin.check.js +6 -0
- package/schemas/plugins/optimize/MergeDuplicateChunksPlugin.json +11 -0
- package/types.d.ts +85 -24
- package/lib/css/CssExportsGenerator.js +0 -207
package/lib/css/CssGenerator.js
CHANGED
@@ -5,37 +5,55 @@
|
|
5
5
|
|
6
6
|
"use strict";
|
7
7
|
|
8
|
-
const { ReplaceSource } = require("webpack-sources");
|
8
|
+
const { ReplaceSource, RawSource, ConcatSource } = require("webpack-sources");
|
9
|
+
const { UsageState } = require("../ExportsInfo");
|
9
10
|
const Generator = require("../Generator");
|
10
11
|
const InitFragment = require("../InitFragment");
|
11
|
-
const {
|
12
|
+
const {
|
13
|
+
JS_AND_CSS_EXPORT_TYPES,
|
14
|
+
JS_AND_CSS_TYPES
|
15
|
+
} = require("../ModuleSourceTypesConstants");
|
12
16
|
const RuntimeGlobals = require("../RuntimeGlobals");
|
17
|
+
const Template = require("../Template");
|
13
18
|
|
14
19
|
/** @typedef {import("webpack-sources").Source} Source */
|
15
|
-
/** @typedef {import("../../declarations/WebpackOptions").
|
16
|
-
/** @typedef {import("../../declarations/WebpackOptions").
|
20
|
+
/** @typedef {import("../../declarations/WebpackOptions").CssAutoGeneratorOptions} CssAutoGeneratorOptions */
|
21
|
+
/** @typedef {import("../../declarations/WebpackOptions").CssGlobalGeneratorOptions} CssGlobalGeneratorOptions */
|
22
|
+
/** @typedef {import("../../declarations/WebpackOptions").CssModuleGeneratorOptions} CssModuleGeneratorOptions */
|
17
23
|
/** @typedef {import("../CodeGenerationResults")} CodeGenerationResults */
|
18
24
|
/** @typedef {import("../Dependency")} Dependency */
|
25
|
+
/** @typedef {import("../DependencyTemplate").CssData} CssData */
|
19
26
|
/** @typedef {import("../DependencyTemplate").CssDependencyTemplateContext} DependencyTemplateContext */
|
20
|
-
/** @typedef {import("../DependencyTemplate").CssExportsData} CssExportsData */
|
21
27
|
/** @typedef {import("../Generator").GenerateContext} GenerateContext */
|
22
28
|
/** @typedef {import("../Generator").UpdateHashContext} UpdateHashContext */
|
29
|
+
/** @typedef {import("../Module").ConcatenationBailoutReasonContext} ConcatenationBailoutReasonContext */
|
23
30
|
/** @typedef {import("../Module").SourceTypes} SourceTypes */
|
24
31
|
/** @typedef {import("../NormalModule")} NormalModule */
|
25
32
|
/** @typedef {import("../util/Hash")} Hash */
|
26
33
|
|
27
34
|
class CssGenerator extends Generator {
|
28
35
|
/**
|
29
|
-
* @param {
|
30
|
-
* @param {CssGeneratorLocalIdentName} localIdentName css export local ident name
|
31
|
-
* @param {boolean} esModule whether to use ES modules syntax
|
36
|
+
* @param {CssAutoGeneratorOptions | CssGlobalGeneratorOptions | CssModuleGeneratorOptions} options options
|
32
37
|
*/
|
33
|
-
constructor(
|
38
|
+
constructor(options) {
|
34
39
|
super();
|
35
|
-
this.convention =
|
36
|
-
this.localIdentName = localIdentName;
|
37
|
-
|
38
|
-
this.esModule = esModule;
|
40
|
+
this.convention = options.exportsConvention;
|
41
|
+
this.localIdentName = options.localIdentName;
|
42
|
+
this.exportsOnly = options.exportsOnly;
|
43
|
+
this.esModule = options.esModule;
|
44
|
+
}
|
45
|
+
|
46
|
+
/**
|
47
|
+
* @param {NormalModule} module module for which the bailout reason should be determined
|
48
|
+
* @param {ConcatenationBailoutReasonContext} context context
|
49
|
+
* @returns {string | undefined} reason why this module can't be concatenated, undefined when it can be concatenated
|
50
|
+
*/
|
51
|
+
getConcatenationBailoutReason(module, context) {
|
52
|
+
if (!this.esModule) {
|
53
|
+
return "Module is not an ECMAScript module";
|
54
|
+
}
|
55
|
+
|
56
|
+
return undefined;
|
39
57
|
}
|
40
58
|
|
41
59
|
/**
|
@@ -44,18 +62,19 @@ class CssGenerator extends Generator {
|
|
44
62
|
* @returns {Source | null} generated code
|
45
63
|
*/
|
46
64
|
generate(module, generateContext) {
|
47
|
-
const
|
48
|
-
|
65
|
+
const source =
|
66
|
+
generateContext.type === "javascript"
|
67
|
+
? new ReplaceSource(new RawSource(""))
|
68
|
+
: new ReplaceSource(/** @type {Source} */ (module.originalSource()));
|
69
|
+
|
49
70
|
/** @type {InitFragment<GenerateContext>[]} */
|
50
71
|
const initFragments = [];
|
51
|
-
/** @type {
|
52
|
-
const
|
72
|
+
/** @type {CssData} */
|
73
|
+
const cssData = {
|
53
74
|
esModule: this.esModule,
|
54
75
|
exports: new Map()
|
55
76
|
};
|
56
77
|
|
57
|
-
generateContext.runtimeRequirements.add(RuntimeGlobals.hasCssModules);
|
58
|
-
|
59
78
|
/** @type {InitFragment<GenerateContext>[] | undefined} */
|
60
79
|
let chunkInitFragments;
|
61
80
|
/** @type {DependencyTemplateContext} */
|
@@ -72,7 +91,7 @@ class CssGenerator extends Generator {
|
|
72
91
|
/** @type {CodeGenerationResults} */
|
73
92
|
(generateContext.codeGenerationResults),
|
74
93
|
initFragments,
|
75
|
-
|
94
|
+
cssData,
|
76
95
|
get chunkInitFragments() {
|
77
96
|
if (!chunkInitFragments) {
|
78
97
|
const data =
|
@@ -105,21 +124,86 @@ class CssGenerator extends Generator {
|
|
105
124
|
|
106
125
|
template.apply(dependency, source, templateContext);
|
107
126
|
};
|
127
|
+
|
108
128
|
for (const dependency of module.dependencies) {
|
109
129
|
handleDependency(dependency);
|
110
130
|
}
|
111
|
-
|
112
|
-
|
113
|
-
|
131
|
+
|
132
|
+
switch (generateContext.type) {
|
133
|
+
case "javascript": {
|
134
|
+
module.buildInfo.cssData = cssData;
|
135
|
+
|
136
|
+
generateContext.runtimeRequirements.add(RuntimeGlobals.module);
|
137
|
+
|
138
|
+
if (generateContext.concatenationScope) {
|
139
|
+
const source = new ConcatSource();
|
140
|
+
const usedIdentifiers = new Set();
|
141
|
+
for (const [name, v] of cssData.exports) {
|
142
|
+
const usedName = generateContext.moduleGraph
|
143
|
+
.getExportInfo(module, name)
|
144
|
+
.getUsedName(name, generateContext.runtime);
|
145
|
+
if (!usedName) {
|
146
|
+
continue;
|
147
|
+
}
|
148
|
+
let identifier = Template.toIdentifier(usedName);
|
149
|
+
const { RESERVED_IDENTIFIER } = require("../util/propertyName");
|
150
|
+
if (RESERVED_IDENTIFIER.has(identifier)) {
|
151
|
+
identifier = `_${identifier}`;
|
152
|
+
}
|
153
|
+
const i = 0;
|
154
|
+
while (usedIdentifiers.has(identifier)) {
|
155
|
+
identifier = Template.toIdentifier(name + i);
|
156
|
+
}
|
157
|
+
usedIdentifiers.add(identifier);
|
158
|
+
generateContext.concatenationScope.registerExport(name, identifier);
|
159
|
+
source.add(
|
160
|
+
`${
|
161
|
+
generateContext.runtimeTemplate.supportsConst()
|
162
|
+
? "const"
|
163
|
+
: "var"
|
164
|
+
} ${identifier} = ${JSON.stringify(v)};\n`
|
165
|
+
);
|
166
|
+
}
|
167
|
+
return source;
|
168
|
+
}
|
169
|
+
|
170
|
+
const needNsObj =
|
171
|
+
this.esModule &&
|
172
|
+
generateContext.moduleGraph
|
173
|
+
.getExportsInfo(module)
|
174
|
+
.otherExportsInfo.getUsed(generateContext.runtime) !==
|
175
|
+
UsageState.Unused;
|
176
|
+
|
177
|
+
if (needNsObj) {
|
178
|
+
generateContext.runtimeRequirements.add(
|
179
|
+
RuntimeGlobals.makeNamespaceObject
|
180
|
+
);
|
181
|
+
}
|
182
|
+
|
183
|
+
const exports = [];
|
184
|
+
|
185
|
+
for (const [name, v] of cssData.exports) {
|
186
|
+
exports.push(`\t${JSON.stringify(name)}: ${JSON.stringify(v)}`);
|
187
|
+
}
|
188
|
+
|
189
|
+
return new RawSource(
|
190
|
+
`${needNsObj ? `${RuntimeGlobals.makeNamespaceObject}(` : ""}${
|
191
|
+
module.moduleArgument
|
192
|
+
}.exports = {\n${exports.join(",\n")}\n}${needNsObj ? ")" : ""};`
|
193
|
+
);
|
114
194
|
}
|
115
|
-
|
195
|
+
case "css": {
|
196
|
+
if (module.presentationalDependencies !== undefined) {
|
197
|
+
for (const dependency of module.presentationalDependencies) {
|
198
|
+
handleDependency(dependency);
|
199
|
+
}
|
200
|
+
}
|
116
201
|
|
117
|
-
|
118
|
-
/** @type {NonNullable<GenerateContext["getData"]>} */
|
119
|
-
(generateContext.getData)();
|
120
|
-
data.set("css-exports", cssExportsData);
|
202
|
+
generateContext.runtimeRequirements.add(RuntimeGlobals.hasCssModules);
|
121
203
|
|
122
|
-
|
204
|
+
return InitFragment.addToSource(source, initFragments, generateContext);
|
205
|
+
}
|
206
|
+
}
|
123
207
|
}
|
124
208
|
|
125
209
|
/**
|
@@ -127,7 +211,8 @@ class CssGenerator extends Generator {
|
|
127
211
|
* @returns {SourceTypes} available types (do not mutate)
|
128
212
|
*/
|
129
213
|
getTypes(module) {
|
130
|
-
|
214
|
+
// TODO, find a better way to prevent the original module from being removed after concatenation, maybe it is a bug
|
215
|
+
return this.exportsOnly ? JS_AND_CSS_EXPORT_TYPES : JS_AND_CSS_TYPES;
|
131
216
|
}
|
132
217
|
|
133
218
|
/**
|
@@ -136,13 +221,32 @@ class CssGenerator extends Generator {
|
|
136
221
|
* @returns {number} estimate size of the module
|
137
222
|
*/
|
138
223
|
getSize(module, type) {
|
139
|
-
|
224
|
+
switch (type) {
|
225
|
+
case "javascript": {
|
226
|
+
if (!module.buildInfo.cssData) {
|
227
|
+
return 42;
|
228
|
+
}
|
140
229
|
|
141
|
-
|
142
|
-
|
143
|
-
|
230
|
+
const exports = module.buildInfo.cssData.exports;
|
231
|
+
const stringifiedExports = JSON.stringify(
|
232
|
+
Array.from(exports).reduce((obj, [key, value]) => {
|
233
|
+
obj[key] = value;
|
234
|
+
return obj;
|
235
|
+
}, {})
|
236
|
+
);
|
237
|
+
|
238
|
+
return stringifiedExports.length + 42;
|
239
|
+
}
|
240
|
+
case "css": {
|
241
|
+
const originalSource = module.originalSource();
|
144
242
|
|
145
|
-
|
243
|
+
if (!originalSource) {
|
244
|
+
return 0;
|
245
|
+
}
|
246
|
+
|
247
|
+
return originalSource.size();
|
248
|
+
}
|
249
|
+
}
|
146
250
|
}
|
147
251
|
|
148
252
|
/**
|
@@ -13,6 +13,7 @@ const Template = require("../Template");
|
|
13
13
|
const compileBooleanMatcher = require("../util/compileBooleanMatcher");
|
14
14
|
const { chunkHasCss } = require("./CssModulesPlugin");
|
15
15
|
|
16
|
+
/** @typedef {import("../../declarations/WebpackOptions").Environment} Environment */
|
16
17
|
/** @typedef {import("../Chunk")} Chunk */
|
17
18
|
/** @typedef {import("../ChunkGraph")} ChunkGraph */
|
18
19
|
/** @typedef {import("../Compilation").RuntimeRequirementsContext} RuntimeRequirementsContext */
|
@@ -73,8 +74,7 @@ class CssLoadingRuntimeModule extends RuntimeModule {
|
|
73
74
|
outputOptions: {
|
74
75
|
crossOriginLoading,
|
75
76
|
uniqueName,
|
76
|
-
chunkLoadTimeout: loadTimeout
|
77
|
-
cssHeadDataCompression: withCompression
|
77
|
+
chunkLoadTimeout: loadTimeout
|
78
78
|
}
|
79
79
|
} = compilation;
|
80
80
|
const fn = RuntimeGlobals.ensureChunkHandlers;
|
@@ -98,25 +98,28 @@ class CssLoadingRuntimeModule extends RuntimeModule {
|
|
98
98
|
RuntimeGlobals.hmrDownloadUpdateHandlers
|
99
99
|
);
|
100
100
|
/** @type {Set<number | string | null>} */
|
101
|
-
const
|
102
|
-
/** @type {Set<number | string | null>} */
|
103
|
-
const initialChunkIdsWithoutCss = new Set();
|
101
|
+
const initialChunkIds = new Set();
|
104
102
|
for (const c of /** @type {Chunk} */ (chunk).getAllInitialChunks()) {
|
105
|
-
(chunkHasCss(c, chunkGraph)
|
106
|
-
|
107
|
-
|
108
|
-
).add(c.id);
|
103
|
+
if (chunkHasCss(c, chunkGraph)) {
|
104
|
+
initialChunkIds.add(c.id);
|
105
|
+
}
|
109
106
|
}
|
110
107
|
|
111
|
-
if (!withLoading && !withHmr
|
108
|
+
if (!withLoading && !withHmr) {
|
112
109
|
return null;
|
113
110
|
}
|
114
111
|
|
112
|
+
const environment =
|
113
|
+
/** @type {Environment} */
|
114
|
+
(compilation.outputOptions.environment);
|
115
|
+
const isNeutralPlatform = runtimeTemplate.isNeutralPlatform();
|
115
116
|
const withPrefetch =
|
116
117
|
this._runtimeRequirements.has(RuntimeGlobals.prefetchChunkHandlers) &&
|
118
|
+
(environment.document || isNeutralPlatform) &&
|
117
119
|
chunk.hasChildByOrder(chunkGraph, "prefetch", true, chunkHasCss);
|
118
120
|
const withPreload =
|
119
121
|
this._runtimeRequirements.has(RuntimeGlobals.preloadChunkHandlers) &&
|
122
|
+
(environment.document || isNeutralPlatform) &&
|
120
123
|
chunk.hasChildByOrder(chunkGraph, "preload", true, chunkHasCss);
|
121
124
|
|
122
125
|
const { linkPreload, linkPrefetch } =
|
@@ -168,178 +171,86 @@ class CssLoadingRuntimeModule extends RuntimeModule {
|
|
168
171
|
: ""
|
169
172
|
]);
|
170
173
|
|
171
|
-
/** @type {(str: string) => number} */
|
172
|
-
const cc = str => str.charCodeAt(0);
|
173
|
-
const name = uniqueName
|
174
|
-
? runtimeTemplate.concatenation(
|
175
|
-
"--webpack-",
|
176
|
-
{ expr: "uniqueName" },
|
177
|
-
"-",
|
178
|
-
{ expr: "chunkId" }
|
179
|
-
)
|
180
|
-
: runtimeTemplate.concatenation("--webpack-", { expr: "chunkId" });
|
181
|
-
|
182
174
|
return Template.asString([
|
183
175
|
"// object to store loaded and loading chunks",
|
184
176
|
"// undefined = chunk not loaded, null = chunk preloaded/prefetched",
|
185
177
|
"// [resolve, reject, Promise] = chunk loading, 0 = chunk loaded",
|
186
178
|
`var installedChunks = ${
|
187
179
|
stateExpression ? `${stateExpression} = ${stateExpression} || ` : ""
|
188
|
-
}{
|
189
|
-
|
190
|
-
id => `${JSON.stringify(id)}:0`
|
191
|
-
|
180
|
+
}{`,
|
181
|
+
Template.indent(
|
182
|
+
Array.from(initialChunkIds, id => `${JSON.stringify(id)}: 0`).join(
|
183
|
+
",\n"
|
184
|
+
)
|
185
|
+
),
|
186
|
+
"};",
|
192
187
|
"",
|
193
188
|
uniqueName
|
194
189
|
? `var uniqueName = ${JSON.stringify(
|
195
190
|
runtimeTemplate.outputOptions.uniqueName
|
196
191
|
)};`
|
197
192
|
: "// data-webpack is not used as build has no uniqueName",
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
"while(j > -1 && !data) {",
|
211
|
-
Template.indent([
|
212
|
-
"var style = cssRules[j--].style;",
|
213
|
-
"if(!style) continue;",
|
214
|
-
"data = style.getPropertyValue(name);"
|
215
|
-
]),
|
216
|
-
"}"
|
217
|
-
]),
|
218
|
-
"}catch(e){}",
|
219
|
-
"if(!data) {",
|
220
|
-
Template.indent([
|
221
|
-
"data = getComputedStyle(document.head).getPropertyValue(name);"
|
222
|
-
]),
|
223
|
-
"}",
|
224
|
-
"if(!data) return [];",
|
225
|
-
withCompression
|
226
|
-
? Template.asString([
|
227
|
-
// LZW decode
|
228
|
-
`var map = {}, char = data[0], oldPhrase = char, decoded = char, code = 256, maxCode = ${"\uFFFF".charCodeAt(
|
229
|
-
0
|
230
|
-
)}, phrase;`,
|
231
|
-
"for (i = 1; i < data.length; i++) {",
|
193
|
+
withLoading || withHmr
|
194
|
+
? Template.asString([
|
195
|
+
'var loadingAttribute = "data-webpack-loading";',
|
196
|
+
`var loadStylesheet = ${runtimeTemplate.basicFunction(
|
197
|
+
`chunkId, url, done${
|
198
|
+
withFetchPriority ? ", fetchPriority" : ""
|
199
|
+
}${withHmr ? ", hmr" : ""}`,
|
200
|
+
[
|
201
|
+
'var link, needAttach, key = "chunk-" + chunkId;',
|
202
|
+
withHmr ? "if(!hmr) {" : "",
|
203
|
+
'var links = document.getElementsByTagName("link");',
|
204
|
+
"for(var i = 0; i < links.length; i++) {",
|
232
205
|
Template.indent([
|
233
|
-
"
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
206
|
+
"var l = links[i];",
|
207
|
+
`if(l.rel == "stylesheet" && (${
|
208
|
+
withHmr
|
209
|
+
? 'l.href.startsWith(url) || l.getAttribute("href").startsWith(url)'
|
210
|
+
: 'l.href == url || l.getAttribute("href") == url'
|
211
|
+
}${
|
212
|
+
uniqueName
|
213
|
+
? ' || l.getAttribute("data-webpack") == uniqueName + ":" + key'
|
214
|
+
: ""
|
215
|
+
})) { link = l; break; }`
|
240
216
|
]),
|
241
217
|
"}",
|
242
|
-
"
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
[
|
279
|
-
'var link, needAttach, key = "chunk-" + chunkId;',
|
280
|
-
withHmr ? "if(!hmr) {" : "",
|
281
|
-
'var links = document.getElementsByTagName("link");',
|
282
|
-
"for(var i = 0; i < links.length; i++) {",
|
283
|
-
Template.indent([
|
284
|
-
"var l = links[i];",
|
285
|
-
`if(l.rel == "stylesheet" && (${
|
286
|
-
withHmr
|
287
|
-
? 'l.href.startsWith(url) || l.getAttribute("href").startsWith(url)'
|
288
|
-
: 'l.href == url || l.getAttribute("href") == url'
|
289
|
-
}${
|
290
|
-
uniqueName
|
291
|
-
? ' || l.getAttribute("data-webpack") == uniqueName + ":" + key'
|
292
|
-
: ""
|
293
|
-
})) { link = l; break; }`
|
294
|
-
]),
|
295
|
-
"}",
|
296
|
-
"if(!done) return link;",
|
297
|
-
withHmr ? "}" : "",
|
298
|
-
"if(!link) {",
|
299
|
-
Template.indent([
|
300
|
-
"needAttach = true;",
|
301
|
-
createStylesheet.call(code, /** @type {Chunk} */ (this.chunk))
|
302
|
-
]),
|
303
|
-
"}",
|
304
|
-
`var onLinkComplete = ${runtimeTemplate.basicFunction(
|
305
|
-
"prev, event",
|
306
|
-
Template.asString([
|
307
|
-
"link.onerror = link.onload = null;",
|
308
|
-
"link.removeAttribute(loadingAttribute);",
|
309
|
-
"clearTimeout(timeout);",
|
310
|
-
'if(event && event.type != "load") link.parentNode.removeChild(link)',
|
311
|
-
"done(event);",
|
312
|
-
"if(prev) return prev(event);"
|
313
|
-
])
|
314
|
-
)};`,
|
315
|
-
"if(link.getAttribute(loadingAttribute)) {",
|
316
|
-
Template.indent([
|
317
|
-
`var timeout = setTimeout(onLinkComplete.bind(null, undefined, { type: 'timeout', target: link }), ${loadTimeout});`,
|
318
|
-
"link.onerror = onLinkComplete.bind(null, link.onerror);",
|
319
|
-
"link.onload = onLinkComplete.bind(null, link.onload);"
|
320
|
-
]),
|
321
|
-
"} else onLinkComplete(undefined, { type: 'load', target: link });", // We assume any existing stylesheet is render blocking
|
322
|
-
withHmr ? "hmr ? document.head.insertBefore(link, hmr) :" : "",
|
323
|
-
"needAttach && document.head.appendChild(link);",
|
324
|
-
"return link;"
|
325
|
-
]
|
326
|
-
)};`,
|
327
|
-
initialChunkIdsWithCss.size > 2
|
328
|
-
? `${JSON.stringify(
|
329
|
-
Array.from(initialChunkIdsWithCss)
|
330
|
-
)}.forEach(loadCssChunkData.bind(null, ${
|
331
|
-
RuntimeGlobals.moduleFactories
|
332
|
-
}, 0));`
|
333
|
-
: initialChunkIdsWithCss.size > 0
|
334
|
-
? `${Array.from(
|
335
|
-
initialChunkIdsWithCss,
|
336
|
-
id =>
|
337
|
-
`loadCssChunkData(${
|
338
|
-
RuntimeGlobals.moduleFactories
|
339
|
-
}, 0, ${JSON.stringify(id)});`
|
340
|
-
).join("")}`
|
341
|
-
: "// no initial css",
|
342
|
-
"",
|
218
|
+
"if(!done) return link;",
|
219
|
+
withHmr ? "}" : "",
|
220
|
+
"if(!link) {",
|
221
|
+
Template.indent([
|
222
|
+
"needAttach = true;",
|
223
|
+
createStylesheet.call(code, /** @type {Chunk} */ (this.chunk))
|
224
|
+
]),
|
225
|
+
"}",
|
226
|
+
`var onLinkComplete = ${runtimeTemplate.basicFunction(
|
227
|
+
"prev, event",
|
228
|
+
Template.asString([
|
229
|
+
"link.onerror = link.onload = null;",
|
230
|
+
"link.removeAttribute(loadingAttribute);",
|
231
|
+
"clearTimeout(timeout);",
|
232
|
+
'if(event && event.type != "load") link.parentNode.removeChild(link)',
|
233
|
+
"done(event);",
|
234
|
+
"if(prev) return prev(event);"
|
235
|
+
])
|
236
|
+
)};`,
|
237
|
+
"if(link.getAttribute(loadingAttribute)) {",
|
238
|
+
Template.indent([
|
239
|
+
`var timeout = setTimeout(onLinkComplete.bind(null, undefined, { type: 'timeout', target: link }), ${loadTimeout});`,
|
240
|
+
"link.onerror = onLinkComplete.bind(null, link.onerror);",
|
241
|
+
"link.onload = onLinkComplete.bind(null, link.onload);"
|
242
|
+
]),
|
243
|
+
"} else onLinkComplete(undefined, { type: 'load', target: link });", // We assume any existing stylesheet is render blocking
|
244
|
+
withHmr && withFetchPriority
|
245
|
+
? 'if (hmr && hmr.getAttribute("fetchpriority")) link.setAttribute("fetchpriority", hmr.getAttribute("fetchpriority"));'
|
246
|
+
: "",
|
247
|
+
withHmr ? "hmr ? document.head.insertBefore(link, hmr) :" : "",
|
248
|
+
"needAttach && document.head.appendChild(link);",
|
249
|
+
"return link;"
|
250
|
+
]
|
251
|
+
)};`
|
252
|
+
])
|
253
|
+
: "",
|
343
254
|
withLoading
|
344
255
|
? Template.asString([
|
345
256
|
`${fn}.css = ${runtimeTemplate.basicFunction(
|
@@ -391,7 +302,7 @@ class CssLoadingRuntimeModule extends RuntimeModule {
|
|
391
302
|
]),
|
392
303
|
"} else {",
|
393
304
|
Template.indent([
|
394
|
-
|
305
|
+
"installedChunks[chunkId] = 0;",
|
395
306
|
"installedChunkData[0]();"
|
396
307
|
]),
|
397
308
|
"}"
|
@@ -401,9 +312,17 @@ class CssLoadingRuntimeModule extends RuntimeModule {
|
|
401
312
|
"}"
|
402
313
|
]
|
403
314
|
)};`,
|
404
|
-
|
405
|
-
|
406
|
-
|
315
|
+
isNeutralPlatform
|
316
|
+
? "if (typeof document !== 'undefined') {"
|
317
|
+
: "",
|
318
|
+
Template.indent([
|
319
|
+
`loadStylesheet(chunkId, url, loadingEnded${
|
320
|
+
withFetchPriority ? ", fetchPriority" : ""
|
321
|
+
});`
|
322
|
+
]),
|
323
|
+
isNeutralPlatform
|
324
|
+
? "} else { loadingEnded({ type: 'load' }); }"
|
325
|
+
: ""
|
407
326
|
]),
|
408
327
|
"} else installedChunks[chunkId] = 0;"
|
409
328
|
]),
|
@@ -426,6 +345,9 @@ class CssLoadingRuntimeModule extends RuntimeModule {
|
|
426
345
|
}) {`,
|
427
346
|
Template.indent([
|
428
347
|
"installedChunks[chunkId] = null;",
|
348
|
+
isNeutralPlatform
|
349
|
+
? "if (typeof document === 'undefined') return;"
|
350
|
+
: "",
|
429
351
|
linkPrefetch.call(
|
430
352
|
Template.asString([
|
431
353
|
"var link = document.createElement('link');",
|
@@ -462,6 +384,9 @@ class CssLoadingRuntimeModule extends RuntimeModule {
|
|
462
384
|
}) {`,
|
463
385
|
Template.indent([
|
464
386
|
"installedChunks[chunkId] = null;",
|
387
|
+
isNeutralPlatform
|
388
|
+
? "if (typeof document === 'undefined') return;"
|
389
|
+
: "",
|
465
390
|
linkPreload.call(
|
466
391
|
Template.asString([
|
467
392
|
"var link = document.createElement('link');",
|
@@ -500,32 +425,20 @@ class CssLoadingRuntimeModule extends RuntimeModule {
|
|
500
425
|
"var oldTags = [];",
|
501
426
|
"var newTags = [];",
|
502
427
|
`var applyHandler = ${runtimeTemplate.basicFunction("options", [
|
503
|
-
`return { dispose: ${runtimeTemplate.basicFunction(
|
504
|
-
"",
|
505
|
-
[]
|
506
|
-
)}, apply: ${runtimeTemplate.basicFunction("", [
|
507
|
-
"var moduleIds = [];",
|
508
|
-
`newTags.forEach(${runtimeTemplate.expressionFunction(
|
509
|
-
"info[1].sheet.disabled = false",
|
510
|
-
"info"
|
511
|
-
)});`,
|
428
|
+
`return { dispose: ${runtimeTemplate.basicFunction("", [
|
512
429
|
"while(oldTags.length) {",
|
513
430
|
Template.indent([
|
514
431
|
"var oldTag = oldTags.pop();",
|
515
432
|
"if(oldTag.parentNode) oldTag.parentNode.removeChild(oldTag);"
|
516
433
|
]),
|
517
|
-
"}"
|
434
|
+
"}"
|
435
|
+
])}, apply: ${runtimeTemplate.basicFunction("", [
|
518
436
|
"while(newTags.length) {",
|
519
437
|
Template.indent([
|
520
|
-
"var
|
521
|
-
|
522
|
-
`chunkModuleIds.forEach(${runtimeTemplate.expressionFunction(
|
523
|
-
"moduleIds.push(id)",
|
524
|
-
"id"
|
525
|
-
)});`
|
438
|
+
"var newTag = newTags.pop();",
|
439
|
+
"newTag.sheet.disabled = false"
|
526
440
|
]),
|
527
|
-
"}"
|
528
|
-
"return moduleIds;"
|
441
|
+
"}"
|
529
442
|
])} };`
|
530
443
|
])}`,
|
531
444
|
`var cssTextKey = ${runtimeTemplate.returningFunction(
|
@@ -534,12 +447,15 @@ class CssLoadingRuntimeModule extends RuntimeModule {
|
|
534
447
|
"r"
|
535
448
|
)}).join()`,
|
536
449
|
"link"
|
537
|
-
)}
|
450
|
+
)};`,
|
538
451
|
`${
|
539
452
|
RuntimeGlobals.hmrDownloadUpdateHandlers
|
540
453
|
}.css = ${runtimeTemplate.basicFunction(
|
541
454
|
"chunkIds, removedChunks, removedModules, promises, applyHandlers, updatedModulesList",
|
542
455
|
[
|
456
|
+
isNeutralPlatform
|
457
|
+
? "if (typeof document === 'undefined') return;"
|
458
|
+
: "",
|
543
459
|
"applyHandlers.push(applyHandler);",
|
544
460
|
`chunkIds.forEach(${runtimeTemplate.basicFunction("chunkId", [
|
545
461
|
`var filename = ${RuntimeGlobals.getChunkCssFilename}(chunkId);`,
|
@@ -565,20 +481,14 @@ class CssLoadingRuntimeModule extends RuntimeModule {
|
|
565
481
|
"} else {",
|
566
482
|
Template.indent([
|
567
483
|
"try { if(cssTextKey(oldTag) == cssTextKey(link)) { if(link.parentNode) link.parentNode.removeChild(link); return resolve(); } } catch(e) {}",
|
568
|
-
"var factories = {};",
|
569
|
-
"loadCssChunkData(factories, link, chunkId);",
|
570
|
-
`Object.keys(factories).forEach(${runtimeTemplate.expressionFunction(
|
571
|
-
"updatedModulesList.push(id)",
|
572
|
-
"id"
|
573
|
-
)})`,
|
574
484
|
"link.sheet.disabled = true;",
|
575
485
|
"oldTags.push(oldTag);",
|
576
|
-
"newTags.push(
|
486
|
+
"newTags.push(link);",
|
577
487
|
"resolve();"
|
578
488
|
]),
|
579
489
|
"}"
|
580
490
|
]
|
581
|
-
)}, oldTag);`
|
491
|
+
)}, ${withFetchPriority ? "undefined," : ""} oldTag);`
|
582
492
|
]
|
583
493
|
)}));`
|
584
494
|
])});`
|