webpack 5.85.1 → 5.87.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 -2
- package/lib/APIPlugin.js +150 -99
- package/lib/CaseSensitiveModulesWarning.js +3 -1
- package/lib/Chunk.js +35 -17
- package/lib/ChunkGroup.js +11 -6
- package/lib/Compiler.js +4 -3
- package/lib/ConcatenationScope.js +2 -2
- package/lib/ConditionalInitFragment.js +11 -1
- package/lib/ConstPlugin.js +57 -29
- package/lib/ContextModule.js +4 -2
- package/lib/ContextModuleFactory.js +1 -0
- package/lib/DependenciesBlock.js +1 -1
- package/lib/DllModule.js +6 -0
- package/lib/EvalSourceMapDevToolPlugin.js +2 -1
- package/lib/ExternalModule.js +15 -8
- package/lib/FlagEntryExportAsUsedPlugin.js +4 -0
- package/lib/Module.js +7 -1
- package/lib/ModuleDependencyError.js +4 -2
- package/lib/ModuleDependencyWarning.js +4 -2
- package/lib/ModuleGraph.js +31 -24
- package/lib/ModuleGraphConnection.js +19 -6
- package/lib/ModuleInfoHeaderPlugin.js +9 -2
- package/lib/ModuleNotFoundError.js +5 -2
- package/lib/ModuleStoreError.js +2 -1
- package/lib/ModuleTypeConstants.js +7 -0
- package/lib/MultiWatching.js +4 -0
- package/lib/ProgressPlugin.js +71 -15
- package/lib/RuntimeGlobals.js +5 -0
- package/lib/RuntimePlugin.js +2 -1
- package/lib/RuntimeTemplate.js +20 -2
- package/lib/WebpackError.js +6 -5
- package/lib/WebpackOptionsApply.js +4 -2
- package/lib/WebpackOptionsDefaulter.js +10 -3
- package/lib/config/defaults.js +31 -2
- package/lib/css/CssExportsGenerator.js +9 -0
- package/lib/css/CssGenerator.js +1 -1
- package/lib/css/CssLoadingRuntimeModule.js +13 -6
- package/lib/css/CssModulesPlugin.js +42 -14
- package/lib/css/CssParser.js +12 -0
- package/lib/dependencies/ConstDependency.js +2 -2
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +19 -0
- package/lib/dependencies/ImportParserPlugin.js +25 -1
- package/lib/dependencies/JsonExportsDependency.js +1 -1
- package/lib/ids/SyncModuleIdsPlugin.js +1 -0
- package/lib/javascript/BasicEvaluatedExpression.js +23 -15
- package/lib/javascript/CommonJsChunkFormatPlugin.js +6 -2
- package/lib/javascript/JavascriptModulesPlugin.js +1 -0
- package/lib/javascript/JavascriptParser.js +118 -58
- package/lib/javascript/JavascriptParserHelpers.js +37 -15
- package/lib/json/JsonData.js +2 -2
- package/lib/json/JsonParser.js +25 -12
- package/lib/node/ReadFileCompileAsyncWasmPlugin.js +2 -1
- package/lib/optimize/AggressiveMergingPlugin.js +8 -0
- package/lib/optimize/AggressiveSplittingPlugin.js +9 -2
- package/lib/optimize/EnsureChunkConditionsPlugin.js +3 -0
- package/lib/optimize/FlagIncludedChunksPlugin.js +11 -5
- package/lib/optimize/InnerGraph.js +4 -4
- package/lib/optimize/LimitChunkCountPlugin.js +29 -4
- package/lib/optimize/MangleExportsPlugin.js +1 -1
- package/lib/optimize/MinMaxSizeWarning.js +5 -0
- package/lib/optimize/ModuleConcatenationPlugin.js +59 -2
- package/lib/optimize/RealContentHashPlugin.js +80 -30
- package/lib/optimize/RemoveParentModulesPlugin.js +6 -0
- package/lib/optimize/RuntimeChunkPlugin.js +9 -1
- package/lib/optimize/SideEffectsFlagPlugin.js +10 -1
- package/lib/optimize/SplitChunksPlugin.js +71 -31
- package/lib/performance/SizeLimitsPlugin.js +7 -4
- package/lib/prefetch/ChunkPrefetchFunctionRuntimeModule.js +3 -1
- package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +3 -1
- package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +5 -2
- package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +3 -1
- package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +3 -1
- package/lib/rules/BasicEffectRulePlugin.js +4 -0
- package/lib/rules/BasicMatcherRulePlugin.js +5 -0
- package/lib/rules/RuleSetCompiler.js +3 -3
- package/lib/rules/UseEffectRulePlugin.js +6 -4
- package/lib/runtime/AsyncModuleRuntimeModule.js +4 -1
- package/lib/runtime/AutoPublicPathRuntimeModule.js +3 -1
- package/lib/runtime/BaseUriRuntimeModule.js +2 -2
- package/lib/runtime/CompatGetDefaultExportRuntimeModule.js +4 -1
- package/lib/runtime/CompatRuntimeModule.js +6 -1
- package/lib/runtime/CreateFakeNamespaceObjectRuntimeModule.js +4 -1
- package/lib/runtime/CreateScriptRuntimeModule.js +3 -1
- package/lib/runtime/CreateScriptUrlRuntimeModule.js +3 -1
- package/lib/runtime/DefinePropertyGettersRuntimeModule.js +4 -1
- package/lib/runtime/EnsureChunkRuntimeModule.js +14 -3
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +5 -9
- package/lib/runtime/GetFullHashRuntimeModule.js +3 -2
- package/lib/runtime/GetMainFilenameRuntimeModule.js +4 -1
- package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +3 -1
- package/lib/runtime/HasOwnPropertyRuntimeModule.js +4 -1
- package/lib/runtime/LoadScriptRuntimeModule.js +63 -47
- package/lib/runtime/MakeNamespaceObjectRuntimeModule.js +4 -1
- package/lib/runtime/OnChunksLoadedRuntimeModule.js +3 -1
- package/lib/runtime/PublicPathRuntimeModule.js +3 -1
- package/lib/runtime/RelativeUrlRuntimeModule.js +4 -1
- package/lib/runtime/RuntimeIdRuntimeModule.js +5 -1
- package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +8 -2
- package/lib/runtime/StartupEntrypointRuntimeModule.js +2 -1
- package/lib/serialization/BinaryMiddleware.js +143 -1
- package/lib/serialization/ErrorObjectSerializer.js +3 -0
- package/lib/serialization/ObjectMiddleware.js +9 -3
- package/lib/serialization/types.js +1 -1
- package/lib/sharing/ConsumeSharedFallbackDependency.js +3 -0
- package/lib/sharing/ConsumeSharedRuntimeModule.js +13 -4
- package/lib/sharing/ProvideSharedDependency.js +11 -0
- package/lib/sharing/ProvideSharedModule.js +4 -0
- package/lib/sharing/ProvideSharedPlugin.js +22 -21
- package/lib/sharing/ShareRuntimeModule.js +11 -4
- package/lib/sharing/resolveMatchedConfigs.js +1 -1
- package/lib/sharing/utils.js +32 -5
- package/lib/util/AsyncQueue.js +4 -2
- package/lib/util/ParallelismFactorCalculator.js +10 -0
- package/lib/util/Semaphore.js +1 -1
- package/lib/util/createHash.js +30 -9
- package/lib/util/deprecation.js +10 -3
- package/lib/util/deterministicGrouping.js +50 -11
- package/lib/util/findGraphRoots.js +4 -2
- package/lib/util/memoize.js +3 -3
- package/lib/util/processAsyncTree.js +7 -1
- package/lib/util/registerExternalSerializer.js +1 -1
- package/lib/util/runtime.js +14 -1
- package/lib/util/smartGrouping.js +1 -1
- package/lib/validateSchema.js +6 -2
- package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +5 -1
- package/lib/wasm-async/AsyncWebAssemblyParser.js +7 -3
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +13 -6
- package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +3 -1
- package/lib/wasm-sync/WebAssemblyGenerator.js +1 -0
- package/lib/wasm-sync/WebAssemblyParser.js +6 -2
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +13 -3
- package/lib/webpack.js +11 -2
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +14 -15
- package/module.d.ts +1 -0
- package/package.json +4 -4
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +51 -5
- package/schemas/plugins/css/CssGeneratorOptions.json +1 -1
- package/schemas/plugins/css/CssParserOptions.json +1 -1
- package/types.d.ts +476 -218
@@ -15,10 +15,16 @@ const JavascriptModulesPlugin = require("./javascript/JavascriptModulesPlugin");
|
|
15
15
|
/** @typedef {import("./ExportsInfo")} ExportsInfo */
|
16
16
|
/** @typedef {import("./ExportsInfo").ExportInfo} ExportInfo */
|
17
17
|
/** @typedef {import("./Module")} Module */
|
18
|
+
/** @typedef {import("./Module").BuildMeta} BuildMeta */
|
18
19
|
/** @typedef {import("./ModuleGraph")} ModuleGraph */
|
19
20
|
/** @typedef {import("./ModuleTemplate")} ModuleTemplate */
|
20
21
|
/** @typedef {import("./RequestShortener")} RequestShortener */
|
21
22
|
|
23
|
+
/**
|
24
|
+
* @template T
|
25
|
+
* @param {Iterable<T>} iterable iterable
|
26
|
+
* @returns {string} joined with comma
|
27
|
+
*/
|
22
28
|
const joinIterableWithComma = iterable => {
|
23
29
|
// This is more performant than Array.from().join(", ")
|
24
30
|
// as it doesn't create an array
|
@@ -139,7 +145,7 @@ const printExportsInfoToSource = (
|
|
139
145
|
}
|
140
146
|
};
|
141
147
|
|
142
|
-
/** @type {WeakMap<RequestShortener, WeakMap<Module, { header: RawSource, full: WeakMap<Source, CachedSource> }>>} */
|
148
|
+
/** @type {WeakMap<RequestShortener, WeakMap<Module, { header: RawSource | undefined, full: WeakMap<Source, CachedSource> }>>} */
|
143
149
|
const caches = new WeakMap();
|
144
150
|
|
145
151
|
class ModuleInfoHeaderPlugin {
|
@@ -197,7 +203,8 @@ class ModuleInfoHeaderPlugin {
|
|
197
203
|
}
|
198
204
|
source.add(header);
|
199
205
|
if (verbose) {
|
200
|
-
const exportsType = module.buildMeta
|
206
|
+
const exportsType = /** @type {BuildMeta} */ (module.buildMeta)
|
207
|
+
.exportsType;
|
201
208
|
source.add(
|
202
209
|
Template.toComment(
|
203
210
|
exportsType
|
@@ -43,7 +43,7 @@ const previouslyPolyfilledBuiltinModules = {
|
|
43
43
|
|
44
44
|
class ModuleNotFoundError extends WebpackError {
|
45
45
|
/**
|
46
|
-
* @param {Module} module module tied to dependency
|
46
|
+
* @param {Module | null} module module tied to dependency
|
47
47
|
* @param {Error&any} err error thrown
|
48
48
|
* @param {DependencyLocation} loc location of dependency
|
49
49
|
*/
|
@@ -54,7 +54,10 @@ class ModuleNotFoundError extends WebpackError {
|
|
54
54
|
const match = err.message.match(/Can't resolve '([^']+)'/);
|
55
55
|
if (match) {
|
56
56
|
const request = match[1];
|
57
|
-
const alias =
|
57
|
+
const alias =
|
58
|
+
previouslyPolyfilledBuiltinModules[
|
59
|
+
/** @type {keyof previouslyPolyfilledBuiltinModules} */ (request)
|
60
|
+
];
|
58
61
|
if (alias) {
|
59
62
|
const pathIndex = alias.indexOf("/");
|
60
63
|
const dependency = pathIndex > 0 ? alias.slice(0, pathIndex) : alias;
|
package/lib/ModuleStoreError.js
CHANGED
@@ -16,6 +16,7 @@ class ModuleStoreError extends WebpackError {
|
|
16
16
|
*/
|
17
17
|
constructor(module, err) {
|
18
18
|
let message = "Module storing failed: ";
|
19
|
+
/** @type {string | undefined} */
|
19
20
|
let details = undefined;
|
20
21
|
if (err !== null && typeof err === "object") {
|
21
22
|
if (typeof err.stack === "string" && err.stack) {
|
@@ -33,7 +34,7 @@ class ModuleStoreError extends WebpackError {
|
|
33
34
|
super(message);
|
34
35
|
|
35
36
|
this.name = "ModuleStoreError";
|
36
|
-
this.details = details;
|
37
|
+
this.details = /** @type {string | undefined} */ (details);
|
37
38
|
this.module = module;
|
38
39
|
this.error = err;
|
39
40
|
}
|
@@ -60,6 +60,12 @@ const CSS_MODULE_TYPE_GLOBAL = "css/global";
|
|
60
60
|
*/
|
61
61
|
const CSS_MODULE_TYPE_MODULE = "css/module";
|
62
62
|
|
63
|
+
/**
|
64
|
+
* @type {Readonly<"css/auto">}
|
65
|
+
* This is the module type used for CSS files, the module will be parsed as CSS modules if it's filename contains `.module.` or `.modules.`.
|
66
|
+
*/
|
67
|
+
const CSS_MODULE_TYPE_AUTO = "css/auto";
|
68
|
+
|
63
69
|
/**
|
64
70
|
* @type {Readonly<"asset">}
|
65
71
|
* This is the module type used for automatically choosing between `asset/inline`, `asset/resource` based on asset size limit (8096).
|
@@ -152,6 +158,7 @@ exports.WEBASSEMBLY_MODULE_TYPE_SYNC = WEBASSEMBLY_MODULE_TYPE_SYNC;
|
|
152
158
|
exports.CSS_MODULE_TYPE = CSS_MODULE_TYPE;
|
153
159
|
exports.CSS_MODULE_TYPE_GLOBAL = CSS_MODULE_TYPE_GLOBAL;
|
154
160
|
exports.CSS_MODULE_TYPE_MODULE = CSS_MODULE_TYPE_MODULE;
|
161
|
+
exports.CSS_MODULE_TYPE_AUTO = CSS_MODULE_TYPE_AUTO;
|
155
162
|
exports.WEBPACK_MODULE_TYPE_RUNTIME = WEBPACK_MODULE_TYPE_RUNTIME;
|
156
163
|
exports.WEBPACK_MODULE_TYPE_FALLBACK = WEBPACK_MODULE_TYPE_FALLBACK;
|
157
164
|
exports.WEBPACK_MODULE_TYPE_REMOTE = WEBPACK_MODULE_TYPE_REMOTE;
|
package/lib/MultiWatching.js
CHANGED
package/lib/ProgressPlugin.js
CHANGED
@@ -11,9 +11,20 @@ const NormalModule = require("./NormalModule");
|
|
11
11
|
const createSchemaValidation = require("./util/create-schema-validation");
|
12
12
|
const { contextify } = require("./util/identifier");
|
13
13
|
|
14
|
+
/** @typedef {import("tapable").Tap} Tap */
|
14
15
|
/** @typedef {import("../declarations/plugins/ProgressPlugin").HandlerFunction} HandlerFunction */
|
15
16
|
/** @typedef {import("../declarations/plugins/ProgressPlugin").ProgressPluginArgument} ProgressPluginArgument */
|
16
17
|
/** @typedef {import("../declarations/plugins/ProgressPlugin").ProgressPluginOptions} ProgressPluginOptions */
|
18
|
+
/** @typedef {import("./Dependency")} Dependency */
|
19
|
+
/** @typedef {import("./Entrypoint").EntryOptions} EntryOptions */
|
20
|
+
/** @typedef {import("./Module")} Module */
|
21
|
+
/** @typedef {import("./logging/Logger").Logger} Logger */
|
22
|
+
|
23
|
+
/**
|
24
|
+
* @typedef {Object} CountsData
|
25
|
+
* @property {number} modulesCount modules count
|
26
|
+
* @property {number} dependenciesCount dependencies count
|
27
|
+
*/
|
17
28
|
|
18
29
|
const validate = createSchemaValidation(
|
19
30
|
require("../schemas/plugins/ProgressPlugin.check.js"),
|
@@ -23,14 +34,31 @@ const validate = createSchemaValidation(
|
|
23
34
|
baseDataPath: "options"
|
24
35
|
}
|
25
36
|
);
|
37
|
+
|
38
|
+
/**
|
39
|
+
* @param {number} a a
|
40
|
+
* @param {number} b b
|
41
|
+
* @param {number} c c
|
42
|
+
* @returns {number} median
|
43
|
+
*/
|
26
44
|
const median3 = (a, b, c) => {
|
27
45
|
return a + b + c - Math.max(a, b, c) - Math.min(a, b, c);
|
28
46
|
};
|
29
47
|
|
48
|
+
/**
|
49
|
+
* @param {boolean | null | undefined} profile need profile
|
50
|
+
* @param {Logger} logger logger
|
51
|
+
* @returns {defaultHandler} default handler
|
52
|
+
*/
|
30
53
|
const createDefaultHandler = (profile, logger) => {
|
31
|
-
/** @type {{ value: string, time: number }[]} */
|
54
|
+
/** @type {{ value: string | undefined, time: number }[]} */
|
32
55
|
const lastStateInfo = [];
|
33
56
|
|
57
|
+
/**
|
58
|
+
* @param {number} percentage percentage
|
59
|
+
* @param {string} msg message
|
60
|
+
* @param {...string} args additional arguments
|
61
|
+
*/
|
34
62
|
const defaultHandler = (percentage, msg, ...args) => {
|
35
63
|
if (profile) {
|
36
64
|
if (percentage === 0) {
|
@@ -95,18 +123,18 @@ const createDefaultHandler = (profile, logger) => {
|
|
95
123
|
|
96
124
|
/**
|
97
125
|
* @callback ReportProgress
|
98
|
-
* @param {number} p
|
99
|
-
* @param {...string}
|
126
|
+
* @param {number} p percentage
|
127
|
+
* @param {...string} args additional arguments
|
100
128
|
* @returns {void}
|
101
129
|
*/
|
102
130
|
|
103
|
-
/** @type {WeakMap<Compiler,ReportProgress>} */
|
131
|
+
/** @type {WeakMap<Compiler, ReportProgress | undefined>} */
|
104
132
|
const progressReporters = new WeakMap();
|
105
133
|
|
106
134
|
class ProgressPlugin {
|
107
135
|
/**
|
108
136
|
* @param {Compiler} compiler the current compiler
|
109
|
-
* @returns {ReportProgress} a progress reporter, if any
|
137
|
+
* @returns {ReportProgress | undefined} a progress reporter, if any
|
110
138
|
*/
|
111
139
|
static getReporter(compiler) {
|
112
140
|
return progressReporters.get(compiler);
|
@@ -288,6 +316,9 @@ class ProgressPlugin {
|
|
288
316
|
};
|
289
317
|
|
290
318
|
// only used when showActiveModules is set
|
319
|
+
/**
|
320
|
+
* @param {Module} module the module
|
321
|
+
*/
|
291
322
|
const moduleBuild = module => {
|
292
323
|
const ident = module.identifier();
|
293
324
|
if (ident) {
|
@@ -297,11 +328,18 @@ class ProgressPlugin {
|
|
297
328
|
}
|
298
329
|
};
|
299
330
|
|
331
|
+
/**
|
332
|
+
* @param {Dependency} entry entry dependency
|
333
|
+
* @param {EntryOptions} options options object
|
334
|
+
*/
|
300
335
|
const entryAdd = (entry, options) => {
|
301
336
|
entriesCount++;
|
302
337
|
if (entriesCount < 5 || entriesCount % 10 === 0) updateThrottled();
|
303
338
|
};
|
304
339
|
|
340
|
+
/**
|
341
|
+
* @param {Module} module the module
|
342
|
+
*/
|
305
343
|
const moduleDone = module => {
|
306
344
|
doneModules++;
|
307
345
|
if (showActiveModules) {
|
@@ -321,6 +359,10 @@ class ProgressPlugin {
|
|
321
359
|
if (doneModules < 50 || doneModules % 100 === 0) updateThrottled();
|
322
360
|
};
|
323
361
|
|
362
|
+
/**
|
363
|
+
* @param {Dependency} entry entry dependency
|
364
|
+
* @param {EntryOptions} options options object
|
365
|
+
*/
|
324
366
|
const entryDone = (entry, options) => {
|
325
367
|
doneEntries++;
|
326
368
|
update();
|
@@ -330,6 +372,7 @@ class ProgressPlugin {
|
|
330
372
|
.getCache("ProgressPlugin")
|
331
373
|
.getItemCache("counts", null);
|
332
374
|
|
375
|
+
/** @type {Promise<CountsData> | undefined} */
|
333
376
|
let cacheGetPromise;
|
334
377
|
|
335
378
|
compiler.hooks.beforeCompile.tap("ProgressPlugin", () => {
|
@@ -352,15 +395,17 @@ class ProgressPlugin {
|
|
352
395
|
|
353
396
|
compiler.hooks.afterCompile.tapPromise("ProgressPlugin", compilation => {
|
354
397
|
if (compilation.compiler.isChild()) return Promise.resolve();
|
355
|
-
return cacheGetPromise.then(
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
398
|
+
return /** @type {Promise<CountsData>} */ (cacheGetPromise).then(
|
399
|
+
async oldData => {
|
400
|
+
if (
|
401
|
+
!oldData ||
|
402
|
+
oldData.modulesCount !== modulesCount ||
|
403
|
+
oldData.dependenciesCount !== dependenciesCount
|
404
|
+
) {
|
405
|
+
await cache.storePromise({ modulesCount, dependenciesCount });
|
406
|
+
}
|
362
407
|
}
|
363
|
-
|
408
|
+
);
|
364
409
|
});
|
365
410
|
|
366
411
|
compiler.hooks.compilation.tap("ProgressPlugin", compilation => {
|
@@ -463,9 +508,9 @@ class ProgressPlugin {
|
|
463
508
|
};
|
464
509
|
const numberOfHooks = Object.keys(hooks).length;
|
465
510
|
Object.keys(hooks).forEach((name, idx) => {
|
466
|
-
const title = hooks[name];
|
511
|
+
const title = hooks[/** @type {keyof typeof hooks} */ (name)];
|
467
512
|
const percentage = (idx / numberOfHooks) * 0.25 + 0.7;
|
468
|
-
compilation.hooks[name].intercept({
|
513
|
+
compilation.hooks[/** @type {keyof typeof hooks} */ (name)].intercept({
|
469
514
|
name: "ProgressPlugin",
|
470
515
|
call() {
|
471
516
|
handler(percentage, "sealing", title);
|
@@ -500,6 +545,12 @@ class ProgressPlugin {
|
|
500
545
|
handler(0.65, "building");
|
501
546
|
}
|
502
547
|
});
|
548
|
+
/**
|
549
|
+
* @param {TODO} hook hook
|
550
|
+
* @param {number} progress progress from 0 to 1
|
551
|
+
* @param {string} category category
|
552
|
+
* @param {string} name name
|
553
|
+
*/
|
503
554
|
const interceptHook = (hook, progress, category, name) => {
|
504
555
|
hook.intercept({
|
505
556
|
name: "ProgressPlugin",
|
@@ -516,6 +567,9 @@ class ProgressPlugin {
|
|
516
567
|
error() {
|
517
568
|
handler(progress, category, name);
|
518
569
|
},
|
570
|
+
/**
|
571
|
+
* @param {Tap} tap tap
|
572
|
+
*/
|
519
573
|
tap(tap) {
|
520
574
|
progressReporters.set(compiler, (p, ...args) => {
|
521
575
|
handler(progress, category, name, tap.name, ...args);
|
@@ -610,4 +664,6 @@ ProgressPlugin.defaultOptions = {
|
|
610
664
|
entries: true
|
611
665
|
};
|
612
666
|
|
667
|
+
ProgressPlugin.createDefaultHandler = createDefaultHandler;
|
668
|
+
|
613
669
|
module.exports = ProgressPlugin;
|
package/lib/RuntimeGlobals.js
CHANGED
@@ -188,6 +188,11 @@ exports.createScriptUrl = "__webpack_require__.tu";
|
|
188
188
|
*/
|
189
189
|
exports.getTrustedTypesPolicy = "__webpack_require__.tt";
|
190
190
|
|
191
|
+
/**
|
192
|
+
* a flag when a chunk has a fetch priority
|
193
|
+
*/
|
194
|
+
exports.hasFetchPriority = "has fetch priority";
|
195
|
+
|
191
196
|
/**
|
192
197
|
* the chunk name of the chunk with the runtime
|
193
198
|
*/
|
package/lib/RuntimePlugin.js
CHANGED
@@ -377,9 +377,10 @@ class RuntimePlugin {
|
|
377
377
|
if (withCreateScriptUrl) {
|
378
378
|
set.add(RuntimeGlobals.createScriptUrl);
|
379
379
|
}
|
380
|
+
const withFetchPriority = set.has(RuntimeGlobals.hasFetchPriority);
|
380
381
|
compilation.addRuntimeModule(
|
381
382
|
chunk,
|
382
|
-
new LoadScriptRuntimeModule(withCreateScriptUrl)
|
383
|
+
new LoadScriptRuntimeModule(withCreateScriptUrl, withFetchPriority)
|
383
384
|
);
|
384
385
|
return true;
|
385
386
|
});
|
package/lib/RuntimeTemplate.js
CHANGED
@@ -939,11 +939,29 @@ class RuntimeTemplate {
|
|
939
939
|
if (chunks.length === 1) {
|
940
940
|
const chunkId = JSON.stringify(chunks[0].id);
|
941
941
|
runtimeRequirements.add(RuntimeGlobals.ensureChunk);
|
942
|
-
|
942
|
+
|
943
|
+
const fetchPriority = chunkGroup.options.fetchPriority;
|
944
|
+
|
945
|
+
if (fetchPriority) {
|
946
|
+
runtimeRequirements.add(RuntimeGlobals.hasFetchPriority);
|
947
|
+
}
|
948
|
+
|
949
|
+
return `${RuntimeGlobals.ensureChunk}(${comment}${chunkId}${
|
950
|
+
fetchPriority ? `, ${JSON.stringify(fetchPriority)}` : ""
|
951
|
+
})`;
|
943
952
|
} else if (chunks.length > 0) {
|
944
953
|
runtimeRequirements.add(RuntimeGlobals.ensureChunk);
|
954
|
+
|
955
|
+
const fetchPriority = chunkGroup.options.fetchPriority;
|
956
|
+
|
957
|
+
if (fetchPriority) {
|
958
|
+
runtimeRequirements.add(RuntimeGlobals.hasFetchPriority);
|
959
|
+
}
|
960
|
+
|
945
961
|
const requireChunkId = chunk =>
|
946
|
-
`${RuntimeGlobals.ensureChunk}(${JSON.stringify(chunk.id)}
|
962
|
+
`${RuntimeGlobals.ensureChunk}(${JSON.stringify(chunk.id)}${
|
963
|
+
fetchPriority ? `, ${JSON.stringify(fetchPriority)}` : ""
|
964
|
+
})`;
|
947
965
|
return `Promise.all(${comment.trim()}[${chunks
|
948
966
|
.map(requireChunkId)
|
949
967
|
.join(", ")}])`;
|
package/lib/WebpackError.js
CHANGED
@@ -22,16 +22,17 @@ class WebpackError extends Error {
|
|
22
22
|
constructor(message) {
|
23
23
|
super(message);
|
24
24
|
|
25
|
+
/** @type {string | undefined} */
|
25
26
|
this.details = undefined;
|
26
|
-
/** @type {Module} */
|
27
|
+
/** @type {Module | undefined | null} */
|
27
28
|
this.module = undefined;
|
28
|
-
/** @type {DependencyLocation} */
|
29
|
+
/** @type {DependencyLocation | undefined} */
|
29
30
|
this.loc = undefined;
|
30
|
-
/** @type {boolean} */
|
31
|
+
/** @type {boolean | undefined} */
|
31
32
|
this.hideStack = undefined;
|
32
|
-
/** @type {Chunk} */
|
33
|
+
/** @type {Chunk | undefined} */
|
33
34
|
this.chunk = undefined;
|
34
|
-
/** @type {string} */
|
35
|
+
/** @type {string | undefined} */
|
35
36
|
this.file = undefined;
|
36
37
|
}
|
37
38
|
|
@@ -368,7 +368,9 @@ class WebpackOptionsApply extends OptionsApply {
|
|
368
368
|
const NodeStuffPlugin = require("./NodeStuffPlugin");
|
369
369
|
new NodeStuffPlugin(options.node).apply(compiler);
|
370
370
|
}
|
371
|
-
new APIPlugin(
|
371
|
+
new APIPlugin({
|
372
|
+
module: options.output.module
|
373
|
+
}).apply(compiler);
|
372
374
|
new ExportsInfoApiPlugin().apply(compiler);
|
373
375
|
new WebpackIsIncludedPlugin().apply(compiler);
|
374
376
|
new ConstPlugin().apply(compiler);
|
@@ -564,7 +566,7 @@ class WebpackOptionsApply extends OptionsApply {
|
|
564
566
|
for (const minimizer of options.optimization.minimizer) {
|
565
567
|
if (typeof minimizer === "function") {
|
566
568
|
minimizer.call(compiler, compiler);
|
567
|
-
} else if (minimizer !== "...") {
|
569
|
+
} else if (minimizer !== "..." && minimizer) {
|
568
570
|
minimizer.apply(compiler);
|
569
571
|
}
|
570
572
|
}
|
@@ -8,11 +8,18 @@
|
|
8
8
|
const { applyWebpackOptionsDefaults } = require("./config/defaults");
|
9
9
|
const { getNormalizedWebpackOptions } = require("./config/normalization");
|
10
10
|
|
11
|
+
/** @typedef {import("./config/normalization").WebpackOptions} WebpackOptions */
|
12
|
+
/** @typedef {import("./config/normalization").WebpackOptionsNormalized} WebpackOptionsNormalized */
|
13
|
+
|
11
14
|
class WebpackOptionsDefaulter {
|
15
|
+
/**
|
16
|
+
* @param {WebpackOptions} options webpack options
|
17
|
+
* @returns {WebpackOptionsNormalized} normalized webpack options
|
18
|
+
*/
|
12
19
|
process(options) {
|
13
|
-
|
14
|
-
applyWebpackOptionsDefaults(
|
15
|
-
return
|
20
|
+
const normalizedOptions = getNormalizedWebpackOptions(options);
|
21
|
+
applyWebpackOptionsDefaults(normalizedOptions);
|
22
|
+
return normalizedOptions;
|
16
23
|
}
|
17
24
|
}
|
18
25
|
|
package/lib/config/defaults.js
CHANGED
@@ -298,7 +298,10 @@ const applyWebpackOptionsDefaults = options => {
|
|
298
298
|
cache,
|
299
299
|
context: /** @type {Context} */ (options.context),
|
300
300
|
targetProperties,
|
301
|
-
mode: /** @type {Mode} */ (options.mode)
|
301
|
+
mode: /** @type {Mode} */ (options.mode),
|
302
|
+
css:
|
303
|
+
/** @type {NonNullable<ExperimentsNormalized["css"]>} */
|
304
|
+
(options.experiments.css)
|
302
305
|
}),
|
303
306
|
options.resolve
|
304
307
|
);
|
@@ -533,6 +536,7 @@ const applyJavascriptParserOptionsDefaults = (
|
|
533
536
|
D(parserOptions, "dynamicImportMode", "lazy");
|
534
537
|
D(parserOptions, "dynamicImportPrefetch", false);
|
535
538
|
D(parserOptions, "dynamicImportPreload", false);
|
539
|
+
D(parserOptions, "dynamicImportFetchPriority", false);
|
536
540
|
D(parserOptions, "createRequire", isNode);
|
537
541
|
if (futureDefaults) D(parserOptions, "exportsPresence", "error");
|
538
542
|
};
|
@@ -1398,9 +1402,16 @@ const applyOptimizationDefaults = (
|
|
1398
1402
|
* @param {string} options.context build context
|
1399
1403
|
* @param {TargetProperties | false} options.targetProperties target properties
|
1400
1404
|
* @param {Mode} options.mode mode
|
1405
|
+
* @param {CssExperimentOptions|false} options.css is css enabled
|
1401
1406
|
* @returns {ResolveOptions} resolve options
|
1402
1407
|
*/
|
1403
|
-
const getResolveDefaults = ({
|
1408
|
+
const getResolveDefaults = ({
|
1409
|
+
cache,
|
1410
|
+
context,
|
1411
|
+
targetProperties,
|
1412
|
+
mode,
|
1413
|
+
css
|
1414
|
+
}) => {
|
1404
1415
|
/** @type {string[]} */
|
1405
1416
|
const conditions = ["webpack"];
|
1406
1417
|
|
@@ -1468,6 +1479,24 @@ const getResolveDefaults = ({ cache, context, targetProperties, mode }) => {
|
|
1468
1479
|
}
|
1469
1480
|
};
|
1470
1481
|
|
1482
|
+
if (css) {
|
1483
|
+
const styleConditions = [];
|
1484
|
+
|
1485
|
+
styleConditions.push("webpack");
|
1486
|
+
styleConditions.push(mode === "development" ? "development" : "production");
|
1487
|
+
styleConditions.push("style");
|
1488
|
+
|
1489
|
+
resolveOptions.byDependency["css-import"] = {
|
1490
|
+
// We avoid using any main files because we have to be consistent with CSS `@import`
|
1491
|
+
// and CSS `@import` does not handle `main` files in directories,
|
1492
|
+
// you should always specify the full URL for styles
|
1493
|
+
mainFiles: [],
|
1494
|
+
mainFields: ["style", "..."],
|
1495
|
+
conditionNames: styleConditions,
|
1496
|
+
extensions: [".css"]
|
1497
|
+
};
|
1498
|
+
}
|
1499
|
+
|
1471
1500
|
return resolveOptions;
|
1472
1501
|
};
|
1473
1502
|
|
@@ -19,6 +19,11 @@ const Template = require("../Template");
|
|
19
19
|
/** @typedef {import("../NormalModule")} NormalModule */
|
20
20
|
/** @typedef {import("../util/Hash")} Hash */
|
21
21
|
|
22
|
+
/**
|
23
|
+
* @template T
|
24
|
+
* @typedef {import("../InitFragment")<T>} InitFragment
|
25
|
+
*/
|
26
|
+
|
22
27
|
const TYPES = new Set(["javascript"]);
|
23
28
|
|
24
29
|
class CssExportsGenerator extends Generator {
|
@@ -36,6 +41,7 @@ class CssExportsGenerator extends Generator {
|
|
36
41
|
*/
|
37
42
|
generate(module, generateContext) {
|
38
43
|
const source = new ReplaceSource(new RawSource(""));
|
44
|
+
/** @type {InitFragment<TODO>[]} */
|
39
45
|
const initFragments = [];
|
40
46
|
const cssExports = new Map();
|
41
47
|
|
@@ -57,6 +63,9 @@ class CssExportsGenerator extends Generator {
|
|
57
63
|
cssExports
|
58
64
|
};
|
59
65
|
|
66
|
+
/**
|
67
|
+
* @param {Dependency} dependency the dependency
|
68
|
+
*/
|
60
69
|
const handleDependency = dependency => {
|
61
70
|
const constructor = /** @type {new (...args: any[]) => Dependency} */ (
|
62
71
|
dependency.constructor
|
package/lib/css/CssGenerator.js
CHANGED
@@ -30,7 +30,7 @@ class CssGenerator extends Generator {
|
|
30
30
|
* @returns {Source} generated code
|
31
31
|
*/
|
32
32
|
generate(module, generateContext) {
|
33
|
-
const originalSource = module.originalSource();
|
33
|
+
const originalSource = /** @type {Source} */ (module.originalSource());
|
34
34
|
const source = new ReplaceSource(originalSource);
|
35
35
|
/** @type {InitFragment[]} */
|
36
36
|
const initFragments = [];
|
@@ -14,6 +14,7 @@ const compileBooleanMatcher = require("../util/compileBooleanMatcher");
|
|
14
14
|
const { chunkHasCss } = require("./CssModulesPlugin");
|
15
15
|
|
16
16
|
/** @typedef {import("../Chunk")} Chunk */
|
17
|
+
/** @typedef {import("../ChunkGraph")} ChunkGraph */
|
17
18
|
/** @typedef {import("../Compilation").RuntimeRequirementsContext} RuntimeRequirementsContext */
|
18
19
|
|
19
20
|
/**
|
@@ -67,10 +68,15 @@ class CssLoadingRuntimeModule extends RuntimeModule {
|
|
67
68
|
uniqueName,
|
68
69
|
chunkLoadTimeout: loadTimeout
|
69
70
|
}
|
70
|
-
} = compilation;
|
71
|
+
} = /** @type {Compilation} */ (compilation);
|
71
72
|
const fn = RuntimeGlobals.ensureChunkHandlers;
|
72
73
|
const conditionMap = chunkGraph.getChunkConditionMap(
|
73
|
-
chunk,
|
74
|
+
/** @type {Chunk} */ (chunk),
|
75
|
+
/**
|
76
|
+
* @param {Chunk} chunk the chunk
|
77
|
+
* @param {ChunkGraph} chunkGraph the chunk graph
|
78
|
+
* @returns {boolean} true, if the chunk has css
|
79
|
+
*/
|
74
80
|
(chunk, chunkGraph) =>
|
75
81
|
!!chunkGraph.getChunkModulesIterableBySourceType(chunk, "css")
|
76
82
|
);
|
@@ -87,7 +93,7 @@ class CssLoadingRuntimeModule extends RuntimeModule {
|
|
87
93
|
const initialChunkIdsWithCss = new Set();
|
88
94
|
/** @type {Set<number | string | null>} */
|
89
95
|
const initialChunkIdsWithoutCss = new Set();
|
90
|
-
for (const c of chunk.getAllInitialChunks()) {
|
96
|
+
for (const c of /** @type {Chunk} */ (chunk).getAllInitialChunks()) {
|
91
97
|
(chunkHasCss(c, chunkGraph)
|
92
98
|
? initialChunkIdsWithCss
|
93
99
|
: initialChunkIdsWithoutCss
|
@@ -98,8 +104,9 @@ class CssLoadingRuntimeModule extends RuntimeModule {
|
|
98
104
|
return null;
|
99
105
|
}
|
100
106
|
|
101
|
-
const { createStylesheet } =
|
102
|
-
|
107
|
+
const { createStylesheet } = CssLoadingRuntimeModule.getCompilationHooks(
|
108
|
+
/** @type {Compilation} */ (compilation)
|
109
|
+
);
|
103
110
|
|
104
111
|
const stateExpression = withHmr
|
105
112
|
? `${RuntimeGlobals.hmrRuntimeStatePrefix}_css`
|
@@ -239,7 +246,7 @@ class CssLoadingRuntimeModule extends RuntimeModule {
|
|
239
246
|
"if(!link) {",
|
240
247
|
Template.indent([
|
241
248
|
"needAttach = true;",
|
242
|
-
createStylesheet.call(code, this.chunk)
|
249
|
+
createStylesheet.call(code, /** @type {Chunk} */ (this.chunk))
|
243
250
|
]),
|
244
251
|
"}",
|
245
252
|
`var onLinkComplete = ${runtimeTemplate.basicFunction(
|