webpack 5.90.3 → 5.91.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 +5 -1
- package/lib/APIPlugin.js +8 -4
- package/lib/AutomaticPrefetchPlugin.js +1 -1
- package/lib/BannerPlugin.js +3 -1
- package/lib/Cache.js +7 -1
- package/lib/CacheFacade.js +3 -3
- package/lib/ChunkGraph.js +32 -18
- package/lib/ChunkGroup.js +14 -14
- package/lib/CleanPlugin.js +7 -5
- package/lib/Compilation.js +262 -93
- package/lib/Compiler.js +199 -83
- package/lib/ConditionalInitFragment.js +4 -5
- package/lib/ContextModule.js +2 -0
- package/lib/ContextModuleFactory.js +4 -2
- package/lib/ContextReplacementPlugin.js +3 -2
- package/lib/DefinePlugin.js +4 -2
- package/lib/Dependency.js +4 -2
- package/lib/DependencyTemplate.js +7 -2
- package/lib/DllModule.js +1 -0
- package/lib/DllReferencePlugin.js +6 -2
- package/lib/EntryOptionPlugin.js +4 -1
- package/lib/EntryPlugin.js +6 -1
- package/lib/Entrypoint.js +1 -1
- package/lib/ExportsInfo.js +1 -4
- package/lib/ExternalModule.js +118 -24
- package/lib/ExternalModuleFactoryPlugin.js +37 -2
- package/lib/FileSystemInfo.js +1 -1
- package/lib/Generator.js +2 -1
- package/lib/HookWebpackError.js +2 -2
- package/lib/InitFragment.js +5 -3
- package/lib/LibManifestPlugin.js +15 -7
- package/lib/Module.js +30 -2
- package/lib/ModuleFilenameHelpers.js +1 -1
- package/lib/ModuleGraph.js +56 -27
- package/lib/ModuleGraphConnection.js +2 -1
- package/lib/MultiCompiler.js +26 -8
- package/lib/NodeStuffPlugin.js +14 -3
- package/lib/NormalModule.js +3 -1
- package/lib/NormalModuleFactory.js +1 -1
- package/lib/NormalModuleReplacementPlugin.js +5 -1
- package/lib/ProvidePlugin.js +3 -1
- package/lib/RawModule.js +2 -1
- package/lib/ResolverFactory.js +3 -1
- package/lib/RuntimeModule.js +4 -4
- package/lib/RuntimePlugin.js +1 -0
- package/lib/RuntimeTemplate.js +102 -34
- package/lib/SourceMapDevToolPlugin.js +4 -1
- package/lib/Stats.js +10 -3
- package/lib/TemplatedPathPlugin.js +32 -6
- package/lib/Watching.js +67 -60
- package/lib/WebpackError.js +6 -6
- package/lib/WebpackOptionsApply.js +18 -5
- package/lib/asset/RawDataUrlModule.js +3 -1
- package/lib/async-modules/AwaitDependenciesInitFragment.js +2 -2
- package/lib/buildChunkGraph.js +117 -64
- 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 +49 -16
- package/lib/cache/ResolverCachePlugin.js +14 -6
- package/lib/cache/getLazyHashedEtag.js +1 -1
- package/lib/config/defaults.js +24 -1
- package/lib/config/normalization.js +3 -1
- package/lib/container/ContainerEntryDependency.js +2 -1
- package/lib/container/ContainerEntryModule.js +3 -1
- 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 +34 -17
- package/lib/css/CssGenerator.js +20 -2
- package/lib/css/CssLoadingRuntimeModule.js +212 -96
- package/lib/css/CssModulesPlugin.js +47 -13
- package/lib/debug/ProfilingPlugin.js +27 -2
- 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/CssLocalIdentifierDependency.js +63 -8
- package/lib/dependencies/CssUrlDependency.js +5 -3
- package/lib/dependencies/ExportsInfoDependency.js +4 -3
- 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 +44 -16
- package/lib/dependencies/HarmonyImportSideEffectDependency.js +7 -6
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +6 -5
- 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/ImportParserPlugin.js +12 -4
- package/lib/dependencies/ImportWeakDependency.js +4 -2
- package/lib/dependencies/LoaderDependency.js +2 -1
- package/lib/dependencies/LoaderImportDependency.js +2 -1
- package/lib/dependencies/ModuleDependency.js +4 -5
- package/lib/dependencies/PureExpressionDependency.js +4 -1
- 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/WorkerPlugin.js +2 -1
- package/lib/dependencies/getFunctionExpression.js +3 -1
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +2 -1
- package/lib/javascript/BasicEvaluatedExpression.js +2 -2
- package/lib/javascript/ChunkHelpers.js +2 -2
- package/lib/javascript/JavascriptParser.js +169 -57
- package/lib/javascript/JavascriptParserHelpers.js +1 -1
- package/lib/javascript/StartupHelpers.js +22 -5
- package/lib/logging/Logger.js +27 -2
- package/lib/logging/createConsoleLogger.js +11 -7
- package/lib/node/NodeEnvironmentPlugin.js +13 -7
- package/lib/node/NodeWatchFileSystem.js +37 -26
- package/lib/node/ReadFileChunkLoadingRuntimeModule.js +2 -1
- package/lib/node/RequireChunkLoadingRuntimeModule.js +2 -1
- package/lib/node/nodeConsole.js +24 -1
- package/lib/optimize/AggressiveSplittingPlugin.js +1 -0
- package/lib/optimize/ConcatenatedModule.js +138 -54
- package/lib/optimize/EnsureChunkConditionsPlugin.js +1 -1
- package/lib/optimize/InnerGraph.js +7 -2
- package/lib/optimize/InnerGraphPlugin.js +36 -13
- package/lib/optimize/ModuleConcatenationPlugin.js +12 -2
- package/lib/optimize/RemoveParentModulesPlugin.js +1 -0
- package/lib/optimize/RuntimeChunkPlugin.js +6 -1
- package/lib/optimize/SideEffectsFlagPlugin.js +46 -15
- package/lib/optimize/SplitChunksPlugin.js +2 -2
- package/lib/performance/SizeLimitsPlugin.js +11 -0
- package/lib/rules/ObjectMatcherRulePlugin.js +4 -0
- package/lib/runtime/EnsureChunkRuntimeModule.js +2 -1
- package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +2 -1
- package/lib/serialization/FileMiddleware.js +1 -0
- package/lib/serialization/ObjectMiddleware.js +2 -0
- package/lib/serialization/Serializer.js +19 -0
- package/lib/sharing/ConsumeSharedModule.js +1 -1
- package/lib/sharing/ConsumeSharedPlugin.js +17 -3
- package/lib/sharing/ConsumeSharedRuntimeModule.js +9 -2
- package/lib/sharing/ProvideSharedPlugin.js +12 -5
- package/lib/sharing/resolveMatchedConfigs.js +2 -2
- package/lib/sharing/utils.js +13 -6
- package/lib/util/StackedCacheMap.js +26 -0
- package/lib/util/WeakTupleMap.js +57 -13
- package/lib/util/cleverMerge.js +24 -11
- package/lib/util/comparators.js +34 -14
- package/lib/util/conventions.js +129 -0
- package/lib/util/fs.js +379 -65
- package/lib/util/hash/BatchedHash.js +3 -0
- package/lib/util/hash/xxhash64.js +2 -2
- package/lib/util/runtime.js +1 -1
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +4 -2
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +15 -6
- package/lib/wasm-sync/WebAssemblyGenerator.js +27 -6
- package/lib/wasm-sync/WebAssemblyParser.js +7 -4
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +2 -1
- package/lib/webpack.js +7 -3
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +2 -1
- package/package.json +25 -26
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +69 -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 +1668 -613
@@ -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 {Object}
|
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,41 @@ 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(0), phrase;`,
|
228
|
+
"for (i = 1; i < data.length; i++) {",
|
229
|
+
Template.indent([
|
230
|
+
"cc = data[i].charCodeAt(0);",
|
231
|
+
"if (cc < 256) phrase = data[i]; else phrase = map[cc] ? map[cc] : (oldPhrase + char);",
|
232
|
+
"decoded += phrase;",
|
233
|
+
"char = phrase.charAt(0);",
|
234
|
+
"map[code] = oldPhrase + char;",
|
235
|
+
"if (++code > maxCode) { code = 256; map = {}; }",
|
236
|
+
"oldPhrase = phrase;"
|
237
|
+
]),
|
238
|
+
"}",
|
239
|
+
"data = decoded;"
|
240
|
+
])
|
241
|
+
: "// css head data compression is disabled",
|
242
|
+
"for(i = 0; cc; i++) {",
|
191
243
|
Template.indent([
|
192
244
|
"cc = data.charCodeAt(i);",
|
193
|
-
`if(cc == ${cc("
|
245
|
+
`if(cc == ${cc(":")}) { token2 = token; token = ""; }`,
|
194
246
|
`else if(cc == ${cc(
|
195
|
-
"
|
196
|
-
)}) {
|
197
|
-
`else if(cc == ${cc("/")} || cc == ${cc(
|
198
|
-
"%"
|
199
|
-
)}) { token = token.replace(/^_/, ""); exports[token] = token; exportsWithId.push(token); if(cc == ${cc(
|
200
|
-
"%"
|
201
|
-
)}) exportsWithDashes.push(token); token = ""; }`,
|
247
|
+
"/"
|
248
|
+
)}) { token = token.replace(/^_/, ""); token2 = token2.replace(/^_/, ""); exports[token2] = token; token = ""; token2 = ""; }`,
|
202
249
|
`else if(!cc || cc == ${cc(
|
203
250
|
","
|
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
|
-
)}); ${
|
251
|
+
)}) { token = token.replace(/^_/, ""); ${
|
223
252
|
RuntimeGlobals.makeNamespaceObject
|
224
253
|
}(exports); target[token] = (${runtimeTemplate.basicFunction(
|
225
254
|
"exports, module",
|
226
255
|
`module.exports = exports;`
|
227
256
|
)}).bind(null, exports); ${
|
228
257
|
withHmr ? "moduleIds.push(token); " : ""
|
229
|
-
}token = "";
|
258
|
+
}token = ""; token2 = ""; exports = {}; }`,
|
230
259
|
`else if(cc == ${cc("\\")}) { token += data[++i] }`,
|
231
260
|
`else { token += data[i]; }`
|
232
261
|
]),
|
@@ -239,7 +268,9 @@ class CssLoadingRuntimeModule extends RuntimeModule {
|
|
239
268
|
)}`,
|
240
269
|
'var loadingAttribute = "data-webpack-loading";',
|
241
270
|
`var loadStylesheet = ${runtimeTemplate.basicFunction(
|
242
|
-
"chunkId, url, done" +
|
271
|
+
"chunkId, url, done" +
|
272
|
+
(withHmr ? ", hmr" : "") +
|
273
|
+
(withFetchPriority ? ", fetchPriority" : ""),
|
243
274
|
[
|
244
275
|
'var link, needAttach, key = "chunk-" + chunkId;',
|
245
276
|
withHmr ? "if(!hmr) {" : "",
|
@@ -307,74 +338,159 @@ class CssLoadingRuntimeModule extends RuntimeModule {
|
|
307
338
|
"",
|
308
339
|
withLoading
|
309
340
|
? 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 {",
|
341
|
+
`${fn}.css = ${runtimeTemplate.basicFunction(
|
342
|
+
`chunkId, promises${withFetchPriority ? " , fetchPriority" : ""}`,
|
343
|
+
[
|
344
|
+
"// css chunk loading",
|
345
|
+
`var installedChunkData = ${RuntimeGlobals.hasOwnProperty}(installedChunks, chunkId) ? installedChunks[chunkId] : undefined;`,
|
346
|
+
'if(installedChunkData !== 0) { // 0 means "already installed".',
|
320
347
|
Template.indent([
|
321
|
-
|
322
|
-
|
323
|
-
|
348
|
+
"",
|
349
|
+
'// a Promise means "currently loading".',
|
350
|
+
"if(installedChunkData) {",
|
351
|
+
Template.indent(["promises.push(installedChunkData[2]);"]),
|
352
|
+
"} else {",
|
324
353
|
Template.indent([
|
325
|
-
|
326
|
-
|
327
|
-
`
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
354
|
+
hasCssMatcher === true
|
355
|
+
? "if(true) { // all chunks have CSS"
|
356
|
+
: `if(${hasCssMatcher("chunkId")}) {`,
|
357
|
+
Template.indent([
|
358
|
+
"// setup Promise in chunk cache",
|
359
|
+
`var promise = new Promise(${runtimeTemplate.expressionFunction(
|
360
|
+
`installedChunkData = installedChunks[chunkId] = [resolve, reject]`,
|
361
|
+
"resolve, reject"
|
362
|
+
)});`,
|
363
|
+
"promises.push(installedChunkData[2] = promise);",
|
364
|
+
"",
|
365
|
+
"// start chunk loading",
|
366
|
+
`var url = ${RuntimeGlobals.publicPath} + ${RuntimeGlobals.getChunkCssFilename}(chunkId);`,
|
367
|
+
"// create error before stack unwound to get useful stacktrace later",
|
368
|
+
"var error = new Error();",
|
369
|
+
`var loadingEnded = ${runtimeTemplate.basicFunction(
|
370
|
+
"event",
|
371
|
+
[
|
372
|
+
`if(${RuntimeGlobals.hasOwnProperty}(installedChunks, chunkId)) {`,
|
344
373
|
Template.indent([
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
"var realHref = event && event.target && event.target.href;",
|
349
|
-
"error.message = 'Loading css chunk ' + chunkId + ' failed.\\n(' + errorType + ': ' + realHref + ')';",
|
350
|
-
"error.name = 'ChunkLoadError';",
|
351
|
-
"error.type = errorType;",
|
352
|
-
"error.request = realHref;",
|
353
|
-
"installedChunkData[1](error);"
|
354
|
-
]),
|
355
|
-
"} else {",
|
374
|
+
"installedChunkData = installedChunks[chunkId];",
|
375
|
+
"if(installedChunkData !== 0) installedChunks[chunkId] = undefined;",
|
376
|
+
"if(installedChunkData) {",
|
356
377
|
Template.indent([
|
357
|
-
|
358
|
-
|
378
|
+
'if(event.type !== "load") {',
|
379
|
+
Template.indent([
|
380
|
+
"var errorType = event && event.type;",
|
381
|
+
"var realHref = event && event.target && event.target.href;",
|
382
|
+
"error.message = 'Loading css chunk ' + chunkId + ' failed.\\n(' + errorType + ': ' + realHref + ')';",
|
383
|
+
"error.name = 'ChunkLoadError';",
|
384
|
+
"error.type = errorType;",
|
385
|
+
"error.request = realHref;",
|
386
|
+
"installedChunkData[1](error);"
|
387
|
+
]),
|
388
|
+
"} else {",
|
389
|
+
Template.indent([
|
390
|
+
`loadCssChunkData(${RuntimeGlobals.moduleFactories}, link, chunkId);`,
|
391
|
+
"installedChunkData[0]();"
|
392
|
+
]),
|
393
|
+
"}"
|
359
394
|
]),
|
360
395
|
"}"
|
361
396
|
]),
|
362
397
|
"}"
|
363
|
-
]
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
398
|
+
]
|
399
|
+
)};`,
|
400
|
+
`var link = loadStylesheet(chunkId, url, loadingEnded${
|
401
|
+
withFetchPriority ? ", fetchPriority" : ""
|
402
|
+
});`
|
403
|
+
]),
|
404
|
+
"} else installedChunks[chunkId] = 0;"
|
368
405
|
]),
|
369
|
-
"}
|
406
|
+
"}"
|
370
407
|
]),
|
371
408
|
"}"
|
372
|
-
]
|
373
|
-
|
374
|
-
])};`
|
409
|
+
]
|
410
|
+
)};`
|
375
411
|
])
|
376
412
|
: "// no chunk loading",
|
377
413
|
"",
|
414
|
+
withPrefetch && hasCssMatcher !== false
|
415
|
+
? `${
|
416
|
+
RuntimeGlobals.prefetchChunkHandlers
|
417
|
+
}.s = ${runtimeTemplate.basicFunction("chunkId", [
|
418
|
+
`if((!${
|
419
|
+
RuntimeGlobals.hasOwnProperty
|
420
|
+
}(installedChunks, chunkId) || installedChunks[chunkId] === undefined) && ${
|
421
|
+
hasCssMatcher === true ? "true" : hasCssMatcher("chunkId")
|
422
|
+
}) {`,
|
423
|
+
Template.indent([
|
424
|
+
"installedChunks[chunkId] = null;",
|
425
|
+
linkPrefetch.call(
|
426
|
+
Template.asString([
|
427
|
+
"var link = document.createElement('link');",
|
428
|
+
crossOriginLoading
|
429
|
+
? `link.crossOrigin = ${JSON.stringify(
|
430
|
+
crossOriginLoading
|
431
|
+
)};`
|
432
|
+
: "",
|
433
|
+
`if (${RuntimeGlobals.scriptNonce}) {`,
|
434
|
+
Template.indent(
|
435
|
+
`link.setAttribute("nonce", ${RuntimeGlobals.scriptNonce});`
|
436
|
+
),
|
437
|
+
"}",
|
438
|
+
'link.rel = "prefetch";',
|
439
|
+
'link.as = "style";',
|
440
|
+
`link.href = ${RuntimeGlobals.publicPath} + ${RuntimeGlobals.getChunkCssFilename}(chunkId);`
|
441
|
+
]),
|
442
|
+
chunk
|
443
|
+
),
|
444
|
+
"document.head.appendChild(link);"
|
445
|
+
]),
|
446
|
+
"}"
|
447
|
+
])};`
|
448
|
+
: "// no prefetching",
|
449
|
+
"",
|
450
|
+
withPreload && hasCssMatcher !== false
|
451
|
+
? `${
|
452
|
+
RuntimeGlobals.preloadChunkHandlers
|
453
|
+
}.s = ${runtimeTemplate.basicFunction("chunkId", [
|
454
|
+
`if((!${
|
455
|
+
RuntimeGlobals.hasOwnProperty
|
456
|
+
}(installedChunks, chunkId) || installedChunks[chunkId] === undefined) && ${
|
457
|
+
hasCssMatcher === true ? "true" : hasCssMatcher("chunkId")
|
458
|
+
}) {`,
|
459
|
+
Template.indent([
|
460
|
+
"installedChunks[chunkId] = null;",
|
461
|
+
linkPreload.call(
|
462
|
+
Template.asString([
|
463
|
+
"var link = document.createElement('link');",
|
464
|
+
"link.charset = 'utf-8';",
|
465
|
+
`if (${RuntimeGlobals.scriptNonce}) {`,
|
466
|
+
Template.indent(
|
467
|
+
`link.setAttribute("nonce", ${RuntimeGlobals.scriptNonce});`
|
468
|
+
),
|
469
|
+
"}",
|
470
|
+
'link.rel = "preload";',
|
471
|
+
'link.as = "style";',
|
472
|
+
`link.href = ${RuntimeGlobals.publicPath} + ${RuntimeGlobals.getChunkCssFilename}(chunkId);`,
|
473
|
+
crossOriginLoading
|
474
|
+
? crossOriginLoading === "use-credentials"
|
475
|
+
? 'link.crossOrigin = "use-credentials";'
|
476
|
+
: Template.asString([
|
477
|
+
"if (link.href.indexOf(window.location.origin + '/') !== 0) {",
|
478
|
+
Template.indent(
|
479
|
+
`link.crossOrigin = ${JSON.stringify(
|
480
|
+
crossOriginLoading
|
481
|
+
)};`
|
482
|
+
),
|
483
|
+
"}"
|
484
|
+
])
|
485
|
+
: ""
|
486
|
+
]),
|
487
|
+
chunk
|
488
|
+
),
|
489
|
+
"document.head.appendChild(link);"
|
490
|
+
]),
|
491
|
+
"}"
|
492
|
+
])};`
|
493
|
+
: "// no preloaded",
|
378
494
|
withHmr
|
379
495
|
? Template.asString([
|
380
496
|
"var oldTags = [];",
|
@@ -128,6 +128,35 @@ const escapeCss = (str, omitOptionalUnderscore) => {
|
|
128
128
|
: escaped;
|
129
129
|
};
|
130
130
|
|
131
|
+
/**
|
132
|
+
* @param {string} str string
|
133
|
+
* @returns {string} encoded string
|
134
|
+
*/
|
135
|
+
const LZWEncode = str => {
|
136
|
+
/** @type {Map<string, string>} */
|
137
|
+
const map = new Map();
|
138
|
+
let encoded = "";
|
139
|
+
let phrase = str[0];
|
140
|
+
let code = 256;
|
141
|
+
let maxCode = "\uffff".charCodeAt(0);
|
142
|
+
for (let i = 1; i < str.length; i++) {
|
143
|
+
const c = str[i];
|
144
|
+
if (map.has(phrase + c)) {
|
145
|
+
phrase += c;
|
146
|
+
} else {
|
147
|
+
encoded += phrase.length > 1 ? map.get(phrase) : phrase;
|
148
|
+
map.set(phrase + c, String.fromCharCode(code));
|
149
|
+
phrase = c;
|
150
|
+
if (++code > maxCode) {
|
151
|
+
code = 256;
|
152
|
+
map.clear();
|
153
|
+
}
|
154
|
+
}
|
155
|
+
}
|
156
|
+
encoded += phrase.length > 1 ? map.get(phrase) : phrase;
|
157
|
+
return encoded;
|
158
|
+
};
|
159
|
+
|
131
160
|
const plugin = "CssModulesPlugin";
|
132
161
|
|
133
162
|
class CssModulesPlugin {
|
@@ -213,8 +242,14 @@ class CssModulesPlugin {
|
|
213
242
|
validateGeneratorOptions[type](generatorOptions);
|
214
243
|
|
215
244
|
return generatorOptions.exportsOnly
|
216
|
-
? new CssExportsGenerator(
|
217
|
-
|
245
|
+
? new CssExportsGenerator(
|
246
|
+
generatorOptions.exportsConvention,
|
247
|
+
generatorOptions.localIdentName
|
248
|
+
)
|
249
|
+
: new CssGenerator(
|
250
|
+
generatorOptions.exportsConvention,
|
251
|
+
generatorOptions.localIdentName
|
252
|
+
);
|
218
253
|
});
|
219
254
|
normalModuleFactory.hooks.createModuleClass
|
220
255
|
.for(type)
|
@@ -326,6 +361,8 @@ class CssModulesPlugin {
|
|
326
361
|
chunkGraph,
|
327
362
|
codeGenerationResults,
|
328
363
|
uniqueName: compilation.outputOptions.uniqueName,
|
364
|
+
cssHeadDataCompression:
|
365
|
+
compilation.outputOptions.cssHeadDataCompression,
|
329
366
|
modules
|
330
367
|
}),
|
331
368
|
filenameTemplate: CssModulesPlugin.getChunkFilenameTemplate(
|
@@ -537,6 +574,7 @@ class CssModulesPlugin {
|
|
537
574
|
/**
|
538
575
|
* @param {Object} options options
|
539
576
|
* @param {string | undefined} options.uniqueName unique name
|
577
|
+
* @param {boolean | undefined} options.cssHeadDataCompression compress css head data
|
540
578
|
* @param {Chunk} options.chunk chunk
|
541
579
|
* @param {ChunkGraph} options.chunkGraph chunk graph
|
542
580
|
* @param {CodeGenerationResults} options.codeGenerationResults code generation results
|
@@ -545,6 +583,7 @@ class CssModulesPlugin {
|
|
545
583
|
*/
|
546
584
|
renderChunk({
|
547
585
|
uniqueName,
|
586
|
+
cssHeadDataCompression,
|
548
587
|
chunk,
|
549
588
|
chunkGraph,
|
550
589
|
codeGenerationResults,
|
@@ -618,16 +657,10 @@ class CssModulesPlugin {
|
|
618
657
|
metaData.push(
|
619
658
|
`${
|
620
659
|
exports
|
621
|
-
? Array.from(
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
return v === shortcutValue
|
626
|
-
? `${escapeCss(n)}/`
|
627
|
-
: v === "--" + shortcutValue
|
628
|
-
? `${escapeCss(n)}%`
|
629
|
-
: `${escapeCss(n)}(${escapeCss(v)})`;
|
630
|
-
}).join("")
|
660
|
+
? Array.from(
|
661
|
+
exports,
|
662
|
+
([n, v]) => `${escapeCss(n)}:${escapeCss(v)}/`
|
663
|
+
).join("")
|
631
664
|
: ""
|
632
665
|
}${escapeCss(moduleId)}`
|
633
666
|
);
|
@@ -637,11 +670,12 @@ class CssModulesPlugin {
|
|
637
670
|
throw e;
|
638
671
|
}
|
639
672
|
}
|
673
|
+
const metaDataStr = metaData.join(",");
|
640
674
|
source.add(
|
641
675
|
`head{--webpack-${escapeCss(
|
642
676
|
(uniqueName ? uniqueName + "-" : "") + chunk.id,
|
643
677
|
true
|
644
|
-
)}:${
|
678
|
+
)}:${cssHeadDataCompression ? LZWEncode(metaDataStr) : metaDataStr};}`
|
645
679
|
);
|
646
680
|
return source;
|
647
681
|
}
|
@@ -17,9 +17,15 @@ const createSchemaValidation = require("../util/create-schema-validation");
|
|
17
17
|
const { dirname, mkdirpSync } = require("../util/fs");
|
18
18
|
|
19
19
|
/** @typedef {import("../../declarations/plugins/debug/ProfilingPlugin").ProfilingPluginOptions} ProfilingPluginOptions */
|
20
|
+
/** @typedef {import("../Compilation")} Compilation */
|
20
21
|
/** @typedef {import("../Compiler")} Compiler */
|
22
|
+
/** @typedef {import("../ContextModuleFactory")} ContextModuleFactory */
|
23
|
+
/** @typedef {import("../ModuleFactory")} ModuleFactory */
|
24
|
+
/** @typedef {import("../NormalModuleFactory")} NormalModuleFactory */
|
21
25
|
/** @typedef {import("../util/fs").IntermediateFileSystem} IntermediateFileSystem */
|
22
26
|
|
27
|
+
/** @typedef {TODO} Inspector */
|
28
|
+
|
23
29
|
const validate = createSchemaValidation(
|
24
30
|
require("../../schemas/plugins/debug/ProfilingPlugin.check.js"),
|
25
31
|
() => require("../../schemas/plugins/debug/ProfilingPlugin.json"),
|
@@ -28,6 +34,8 @@ const validate = createSchemaValidation(
|
|
28
34
|
baseDataPath: "options"
|
29
35
|
}
|
30
36
|
);
|
37
|
+
|
38
|
+
/** @type {Inspector | undefined} */
|
31
39
|
let inspector = undefined;
|
32
40
|
|
33
41
|
try {
|
@@ -38,6 +46,9 @@ try {
|
|
38
46
|
}
|
39
47
|
|
40
48
|
class Profiler {
|
49
|
+
/**
|
50
|
+
* @param {Inspector} inspector inspector
|
51
|
+
*/
|
41
52
|
constructor(inspector) {
|
42
53
|
this.session = undefined;
|
43
54
|
this.inspector = inspector;
|
@@ -140,7 +151,7 @@ class Profiler {
|
|
140
151
|
*/
|
141
152
|
const createTrace = (fs, outputPath) => {
|
142
153
|
const trace = new Tracer();
|
143
|
-
const profiler = new Profiler(inspector);
|
154
|
+
const profiler = new Profiler(/** @type {Inspector} */ (inspector));
|
144
155
|
if (/\/|\\/.test(outputPath)) {
|
145
156
|
const dirPath = dirname(fs, outputPath);
|
146
157
|
mkdirpSync(fs, dirPath);
|
@@ -216,7 +227,8 @@ class ProfilingPlugin {
|
|
216
227
|
*/
|
217
228
|
apply(compiler) {
|
218
229
|
const tracer = createTrace(
|
219
|
-
|
230
|
+
/** @type {IntermediateFileSystem} */
|
231
|
+
(compiler.intermediateFileSystem),
|
220
232
|
this.outputPath
|
221
233
|
);
|
222
234
|
tracer.profiler.startProfiling();
|
@@ -320,6 +332,11 @@ class ProfilingPlugin {
|
|
320
332
|
}
|
321
333
|
}
|
322
334
|
|
335
|
+
/**
|
336
|
+
* @param {any} instance instance
|
337
|
+
* @param {Trace} tracer tracer
|
338
|
+
* @param {string} logLabel log label
|
339
|
+
*/
|
323
340
|
const interceptAllHooksFor = (instance, tracer, logLabel) => {
|
324
341
|
if (Reflect.has(instance, "hooks")) {
|
325
342
|
Object.keys(instance.hooks).forEach(hookName => {
|
@@ -331,6 +348,10 @@ const interceptAllHooksFor = (instance, tracer, logLabel) => {
|
|
331
348
|
}
|
332
349
|
};
|
333
350
|
|
351
|
+
/**
|
352
|
+
* @param {NormalModuleFactory} moduleFactory normal module factory
|
353
|
+
* @param {Trace} tracer tracer
|
354
|
+
*/
|
334
355
|
const interceptAllParserHooks = (moduleFactory, tracer) => {
|
335
356
|
const moduleTypes = [
|
336
357
|
JAVASCRIPT_MODULE_TYPE_AUTO,
|
@@ -350,6 +371,10 @@ const interceptAllParserHooks = (moduleFactory, tracer) => {
|
|
350
371
|
});
|
351
372
|
};
|
352
373
|
|
374
|
+
/**
|
375
|
+
* @param {Compilation} compilation compilation
|
376
|
+
* @param {Trace} tracer tracer
|
377
|
+
*/
|
353
378
|
const interceptAllJavascriptModulesPluginHooks = (compilation, tracer) => {
|
354
379
|
interceptAllHooksFor(
|
355
380
|
{
|
@@ -103,7 +103,7 @@ class AMDDefineDependencyParserPlugin {
|
|
103
103
|
/** @type {string} */ (param.string)
|
104
104
|
)
|
105
105
|
)
|
106
|
-
identifiers[idx] = param.string;
|
106
|
+
identifiers[/** @type {number} */ (idx)] = param.string;
|
107
107
|
const result = this.processItem(parser, expr, param, namedModule);
|
108
108
|
if (result === undefined) {
|
109
109
|
this.processContext(parser, expr, param);
|
@@ -113,7 +113,8 @@ class AMDDefineDependencyParserPlugin {
|
|
113
113
|
} else if (param.isConstArray()) {
|
114
114
|
/** @type {(string | LocalModuleDependency | AMDRequireItemDependency)[]} */
|
115
115
|
const deps = [];
|
116
|
-
|
116
|
+
/** @type {string[]} */
|
117
|
+
(param.array).forEach((request, idx) => {
|
117
118
|
let dep;
|
118
119
|
let localModule;
|
119
120
|
if (request === "require") {
|
@@ -151,7 +152,7 @@ class AMDDefineDependencyParserPlugin {
|
|
151
152
|
* @param {CallExpression} expr call expression
|
152
153
|
* @param {BasicEvaluatedExpression} param param
|
153
154
|
* @param {string=} namedModule named module
|
154
|
-
* @returns {boolean} result
|
155
|
+
* @returns {boolean | undefined} result
|
155
156
|
*/
|
156
157
|
processItem(parser, expr, param, namedModule) {
|
157
158
|
if (param.isConditional()) {
|
@@ -193,7 +194,10 @@ class AMDDefineDependencyParserPlugin {
|
|
193
194
|
localModule.flagUsed();
|
194
195
|
dep = new LocalModuleDependency(localModule, param.range, false);
|
195
196
|
} else {
|
196
|
-
dep = this.newRequireItemDependency(
|
197
|
+
dep = this.newRequireItemDependency(
|
198
|
+
/** @type {string} */ (param.string),
|
199
|
+
param.range
|
200
|
+
);
|
197
201
|
dep.optional = !!parser.scope.inTry;
|
198
202
|
parser.state.current.addDependency(dep);
|
199
203
|
return true;
|
@@ -377,7 +381,7 @@ class AMDDefineDependencyParserPlugin {
|
|
377
381
|
for (const [name, varInfo] of fnRenames) {
|
378
382
|
parser.setVariable(name, varInfo);
|
379
383
|
}
|
380
|
-
parser.scope.inTry = inTry;
|
384
|
+
parser.scope.inTry = /** @type {boolean} */ (inTry);
|
381
385
|
if (fn.callee.object.body.type === "BlockStatement") {
|
382
386
|
parser.detectMode(fn.callee.object.body.body);
|
383
387
|
const prev = parser.prevStatement;
|