@depup/webpack 5.109.0-depup.0 → 5.109.2-depup.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -4
- package/bin/webpack.js +12 -0
- package/changes.json +4 -4
- package/lib/ChunkGraph.js +17 -15
- package/lib/CleanPlugin.js +11 -9
- package/lib/CompatibilityPlugin.js +31 -0
- package/lib/Compilation.js +21 -5
- package/lib/Compiler.js +16 -4
- package/lib/DefinePlugin.js +47 -20
- package/lib/ExportsInfo.js +22 -5
- package/lib/ExternalModule.js +10 -7
- package/lib/FileSystemInfo.js +126 -26
- package/lib/FlagDependencyUsagePlugin.js +33 -12
- package/lib/InitFragment.js +20 -32
- package/lib/ModuleFilenameHelpers.js +13 -2
- package/lib/NormalModule.js +80 -71
- package/lib/NormalModuleFactory.js +8 -2
- package/lib/RuntimePlugin.js +40 -113
- package/lib/Template.js +23 -3
- package/lib/cache/PackFileCacheStrategy.js +259 -5
- package/lib/config/defaults.js +21 -2
- package/lib/container/HoistContainerReferencesPlugin.js +47 -55
- package/lib/container/ModuleFederationPlugin.js +15 -9
- package/lib/css/CssGenerator.js +8 -2
- package/lib/css/CssLoadingRuntimeModule.js +25 -12
- package/lib/css/CssModulesPlugin.js +29 -18
- package/lib/css/CssParser.js +135 -50
- package/lib/css/syntax.js +862 -765
- package/lib/dependencies/CommonJsExportRequireDependency.js +19 -0
- package/lib/dependencies/CommonJsFullRequireDependency.js +33 -4
- package/lib/dependencies/CommonJsImportsParserPlugin.js +2 -0
- package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +2 -1
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +17 -9
- package/lib/dependencies/HarmonyImportDependency.js +1 -1
- package/lib/dependencies/HarmonyImportGuard.js +2 -1
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +10 -7
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +15 -9
- package/lib/hmr/lazyCompilationBackend.js +19 -4
- package/lib/html/HtmlGenerator.js +23 -3
- package/lib/html/HtmlModulesPlugin.js +30 -12
- package/lib/html/syntax.js +2485 -2399
- package/lib/ids/IdHelpers.js +24 -10
- package/lib/javascript/JavascriptModulesPlugin.js +83 -49
- package/lib/javascript/JavascriptParser.js +49 -13
- package/lib/javascript/syntax.js +700 -43
- package/lib/node/ReadFileCompileAsyncWasmPlugin.js +10 -2
- package/lib/node/ReadFileCompileWasmPlugin.js +10 -2
- package/lib/optimize/AggressiveMergingPlugin.js +19 -15
- package/lib/optimize/ConcatenatedModule.js +19 -15
- package/lib/optimize/ModuleConcatenationPlugin.js +73 -24
- package/lib/optimize/RealContentHashPlugin.js +10 -7
- package/lib/optimize/SplitChunksPlugin.js +146 -44
- package/lib/prefetch/ResourceHintPlugin.js +96 -72
- package/lib/serialization/BinaryMiddleware.js +270 -938
- package/lib/serialization/FileMiddleware.js +299 -60
- package/lib/stats/DefaultStatsFactoryPlugin.js +204 -198
- package/lib/stats/DefaultStatsPrinterPlugin.js +24 -166
- package/lib/stats/StatsFactory.js +31 -9
- package/lib/util/identifier.js +21 -1
- package/package.json +10 -10
- package/schemas/WebpackOptions.json +110 -55
- package/types.d.ts +832 -247
|
@@ -100,6 +100,67 @@ const compilationResolvers = new WeakMap();
|
|
|
100
100
|
// magic comments still work — they route through `applyParsedHints`.
|
|
101
101
|
const DEFAULT_ASSETS_EXCLUDE_REGEXP = /\.(?:webmanifest|pdf|txt)(?:\?.*)?$/i;
|
|
102
102
|
|
|
103
|
+
// Initial-graph auto hints target JS chunk output files only.
|
|
104
|
+
const JS_CHUNK_FILE_REGEXP = /\.m?jsx?$/i;
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* True for the URL-referenced-asset deps that can carry resource-hint flags.
|
|
108
|
+
* Type guard so callers keep the narrowed union without re-listing the classes.
|
|
109
|
+
* @param {import("../Dependency")} dep dependency
|
|
110
|
+
* @returns {dep is URLDependency | CssUrlDependency | HtmlSourceDependency} whether it is a URL asset dep
|
|
111
|
+
*/
|
|
112
|
+
const isUrlAssetDep = (dep) =>
|
|
113
|
+
dep instanceof URLDependency ||
|
|
114
|
+
dep instanceof CssUrlDependency ||
|
|
115
|
+
dep instanceof HtmlSourceDependency;
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* True for the CSS / HTML URL-asset deps whose templates don't run for JS
|
|
119
|
+
* output — the plugin lifts their hint flags into JS runtime requirements
|
|
120
|
+
* itself. JS `URLDependency` lifts its own, so it is excluded here.
|
|
121
|
+
* @param {import("../Dependency")} dep dependency
|
|
122
|
+
* @returns {dep is CssUrlDependency | HtmlSourceDependency} whether it is a CSS/HTML URL asset dep
|
|
123
|
+
*/
|
|
124
|
+
const isCssOrHtmlUrlAssetDep = (dep) =>
|
|
125
|
+
dep instanceof CssUrlDependency || dep instanceof HtmlSourceDependency;
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Entry chunk name for a hint's `hostChunks` (Vite's `hostId`); the id is a
|
|
129
|
+
* stable fallback for unnamed chunks.
|
|
130
|
+
* @param {import("../Chunk")} chunk chunk
|
|
131
|
+
* @returns {string} name or stringified id
|
|
132
|
+
*/
|
|
133
|
+
const chunkHostName = (chunk) => chunk.name || String(chunk.id);
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Walk `chunks` × their modules × dependencies and yield each distinct
|
|
137
|
+
* URL-asset module carrying a prefetch/preload flag, deduping targets within a
|
|
138
|
+
* single call. One shared walk for the entrypoint-hint and HTML-hint passes,
|
|
139
|
+
* which would otherwise each re-implement the same 4-level nesting.
|
|
140
|
+
* @param {Compilation} compilation compilation
|
|
141
|
+
* @param {Iterable<import("../Chunk")>} chunks chunks to scan
|
|
142
|
+
* @returns {IterableIterator<{ dep: URLDependency | CssUrlDependency | HtmlSourceDependency, target: Module, chunk: import("../Chunk") }>} hinted assets
|
|
143
|
+
*/
|
|
144
|
+
function* iterateHintedUrlAssets(compilation, chunks) {
|
|
145
|
+
const { chunkGraph, moduleGraph } = compilation;
|
|
146
|
+
/** @type {WeakSet<Module>} */
|
|
147
|
+
const seen = new WeakSet();
|
|
148
|
+
for (const chunk of chunks) {
|
|
149
|
+
for (const module of chunkGraph.getChunkModulesIterable(chunk)) {
|
|
150
|
+
const deps = module.dependencies;
|
|
151
|
+
if (!deps) continue;
|
|
152
|
+
for (const dep of deps) {
|
|
153
|
+
if (!isUrlAssetDep(dep)) continue;
|
|
154
|
+
if (!dep.prefetch && !dep.preload) continue;
|
|
155
|
+
const target = moduleGraph.getModule(dep);
|
|
156
|
+
if (!target || seen.has(target)) continue;
|
|
157
|
+
seen.add(target);
|
|
158
|
+
yield { dep, target, chunk };
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
103
164
|
/**
|
|
104
165
|
* Merge the matching `UrlHintRule`s for a request. Rules match by
|
|
105
166
|
* `test`/`include`/`exclude` (omit all three → matches everything); later
|
|
@@ -238,13 +299,13 @@ const collectEntrypointHints = (compilation, entryName, hints) => {
|
|
|
238
299
|
for (const chunk of entrypoint.chunks) {
|
|
239
300
|
if (chunk === entryChunk) continue;
|
|
240
301
|
for (const file of chunk.files) {
|
|
241
|
-
if (
|
|
302
|
+
if (!JS_CHUNK_FILE_REGEXP.test(file)) continue;
|
|
242
303
|
const href = publicPath + file;
|
|
243
304
|
/** @type {EntrypointHint} */
|
|
244
305
|
const h = {
|
|
245
306
|
rel,
|
|
246
307
|
href,
|
|
247
|
-
hostChunks: [
|
|
308
|
+
hostChunks: [chunkHostName(chunk)]
|
|
248
309
|
};
|
|
249
310
|
if (rel === "preload") h.as = "script";
|
|
250
311
|
push(h);
|
|
@@ -256,45 +317,30 @@ const collectEntrypointHints = (compilation, entryName, hints) => {
|
|
|
256
317
|
// runtime via `dynamicImportPrefetch/Preload` parser options).
|
|
257
318
|
/** @type {Set<import("../Chunk")>} */
|
|
258
319
|
const chunkSet = new Set(entrypoint.chunks);
|
|
259
|
-
const
|
|
260
|
-
if (
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
d.asAttribute ||
|
|
284
|
-
ResourceHintRuntimeModule.guessAsAttribute(d.request);
|
|
285
|
-
/** @type {EntrypointHint} */
|
|
286
|
-
const h = {
|
|
287
|
-
rel: d.preload ? "preload" : "prefetch",
|
|
288
|
-
href: publicPath + buildInfo.filename,
|
|
289
|
-
hostChunks: [chunk.name || String(chunk.id)]
|
|
290
|
-
};
|
|
291
|
-
if (asAttr) h.as = asAttr;
|
|
292
|
-
if (d.typeAttribute) h.type = d.typeAttribute;
|
|
293
|
-
if (d.mediaAttribute) h.media = d.mediaAttribute;
|
|
294
|
-
if (d.fetchPriority) h.fetchPriority = d.fetchPriority;
|
|
295
|
-
push(h);
|
|
296
|
-
}
|
|
297
|
-
}
|
|
320
|
+
const runtimeChunk = entrypoint.getRuntimeChunk();
|
|
321
|
+
if (runtimeChunk) chunkSet.add(runtimeChunk);
|
|
322
|
+
for (const { dep, target, chunk } of iterateHintedUrlAssets(
|
|
323
|
+
compilation,
|
|
324
|
+
chunkSet
|
|
325
|
+
)) {
|
|
326
|
+
const buildInfo =
|
|
327
|
+
/** @type {{ filename?: string }} */
|
|
328
|
+
(target.buildInfo);
|
|
329
|
+
if (!buildInfo || !buildInfo.filename) continue;
|
|
330
|
+
const asAttribute =
|
|
331
|
+
dep.asAttribute ||
|
|
332
|
+
ResourceHintRuntimeModule.guessAsAttribute(dep.request);
|
|
333
|
+
/** @type {EntrypointHint} */
|
|
334
|
+
const h = {
|
|
335
|
+
rel: dep.preload ? "preload" : "prefetch",
|
|
336
|
+
href: publicPath + buildInfo.filename,
|
|
337
|
+
hostChunks: [chunkHostName(chunk)]
|
|
338
|
+
};
|
|
339
|
+
if (asAttribute) h.as = asAttribute;
|
|
340
|
+
if (dep.typeAttribute) h.type = dep.typeAttribute;
|
|
341
|
+
if (dep.mediaAttribute) h.media = dep.mediaAttribute;
|
|
342
|
+
if (dep.fetchPriority) h.fetchPriority = dep.fetchPriority;
|
|
343
|
+
push(h);
|
|
298
344
|
}
|
|
299
345
|
// `hostType`: `"html"` iff the entrypoint has an extracted HTML page
|
|
300
346
|
// (any `HtmlEntryDependency` with elementKind `script`/`script-module` on
|
|
@@ -493,33 +539,16 @@ class ResourceHintPlugin {
|
|
|
493
539
|
const chunks = new Set(entrypoint.chunks);
|
|
494
540
|
const entry = entrypoint.getEntrypointChunk();
|
|
495
541
|
if (entry) chunks.add(entry);
|
|
496
|
-
const
|
|
497
|
-
if (
|
|
542
|
+
const runtimeChunk = entrypoint.getRuntimeChunk();
|
|
543
|
+
if (runtimeChunk) chunks.add(runtimeChunk);
|
|
498
544
|
/** @type {HtmlHintedAsset[]} */
|
|
499
545
|
const hinted = [];
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
)
|
|
506
|
-
if (!m.dependencies) continue;
|
|
507
|
-
for (const d of m.dependencies) {
|
|
508
|
-
if (
|
|
509
|
-
!(d instanceof URLDependency) &&
|
|
510
|
-
!(d instanceof CssUrlDependency) &&
|
|
511
|
-
!(d instanceof HtmlSourceDependency)
|
|
512
|
-
) {
|
|
513
|
-
continue;
|
|
514
|
-
}
|
|
515
|
-
if (!d.prefetch && !d.preload) continue;
|
|
516
|
-
const t = compilation.moduleGraph.getModule(d);
|
|
517
|
-
if (!t || seen.has(t)) continue;
|
|
518
|
-
seen.add(t);
|
|
519
|
-
anyHtmlHinted.add(t);
|
|
520
|
-
hinted.push({ module: t, dep: d });
|
|
521
|
-
}
|
|
522
|
-
}
|
|
546
|
+
for (const { dep: assetDep, target } of iterateHintedUrlAssets(
|
|
547
|
+
compilation,
|
|
548
|
+
chunks
|
|
549
|
+
)) {
|
|
550
|
+
anyHtmlHinted.add(target);
|
|
551
|
+
hinted.push({ module: target, dep: assetDep });
|
|
523
552
|
}
|
|
524
553
|
// Multiple HtmlEntryDeps may share an entryName (e.g. a
|
|
525
554
|
// `<script>` and a `<link rel="modulepreload">` for the
|
|
@@ -571,12 +600,7 @@ class ResourceHintPlugin {
|
|
|
571
600
|
(module).dependencies;
|
|
572
601
|
if (!deps) continue;
|
|
573
602
|
for (const dep of deps) {
|
|
574
|
-
if (
|
|
575
|
-
!(dep instanceof CssUrlDependency) &&
|
|
576
|
-
!(dep instanceof HtmlSourceDependency)
|
|
577
|
-
) {
|
|
578
|
-
continue;
|
|
579
|
-
}
|
|
603
|
+
if (!isCssOrHtmlUrlAssetDep(dep)) continue;
|
|
580
604
|
if (dep.prefetch) hasPrefetch = true;
|
|
581
605
|
if (dep.preload) hasPreload = true;
|
|
582
606
|
if (hasPrefetch && hasPreload) break;
|