webpack 5.90.3 → 5.92.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of webpack might be problematic. Click here for more details.
- package/README.md +5 -5
- package/bin/webpack.js +6 -3
- package/lib/APIPlugin.js +14 -6
- package/lib/AutomaticPrefetchPlugin.js +1 -1
- package/lib/BannerPlugin.js +3 -1
- package/lib/Cache.js +8 -2
- package/lib/CacheFacade.js +3 -3
- package/lib/Chunk.js +7 -4
- package/lib/ChunkGraph.js +52 -25
- package/lib/ChunkGroup.js +23 -17
- package/lib/CleanPlugin.js +8 -6
- package/lib/Compilation.js +295 -120
- package/lib/Compiler.js +223 -87
- package/lib/ConcatenationScope.js +3 -3
- package/lib/ConditionalInitFragment.js +4 -5
- package/lib/ContextModule.js +95 -41
- package/lib/ContextModuleFactory.js +4 -2
- package/lib/ContextReplacementPlugin.js +3 -2
- package/lib/DefinePlugin.js +18 -6
- package/lib/Dependency.js +12 -10
- package/lib/DependencyTemplate.js +17 -7
- package/lib/DllModule.js +1 -0
- package/lib/DllReferencePlugin.js +7 -3
- package/lib/EntryOptionPlugin.js +4 -1
- package/lib/EntryPlugin.js +6 -1
- package/lib/Entrypoint.js +1 -1
- package/lib/EvalDevToolModulePlugin.js +11 -0
- package/lib/ExportsInfo.js +23 -8
- package/lib/ExternalModule.js +160 -35
- package/lib/ExternalModuleFactoryPlugin.js +37 -2
- package/lib/FileSystemInfo.js +69 -42
- package/lib/FlagDependencyExportsPlugin.js +21 -7
- package/lib/Generator.js +4 -4
- package/lib/HookWebpackError.js +2 -2
- package/lib/HotModuleReplacementPlugin.js +108 -45
- package/lib/IgnorePlugin.js +4 -1
- package/lib/InitFragment.js +5 -3
- package/lib/LibManifestPlugin.js +17 -9
- package/lib/Module.js +41 -14
- package/lib/ModuleFactory.js +3 -3
- package/lib/ModuleFilenameHelpers.js +30 -17
- package/lib/ModuleGraph.js +60 -31
- package/lib/ModuleGraphConnection.js +2 -1
- package/lib/MultiCompiler.js +62 -9
- package/lib/NodeStuffPlugin.js +14 -3
- package/lib/NormalModule.js +13 -13
- package/lib/NormalModuleFactory.js +18 -9
- package/lib/NormalModuleReplacementPlugin.js +5 -1
- package/lib/Parser.js +1 -1
- package/lib/PlatformPlugin.js +39 -0
- package/lib/ProgressPlugin.js +1 -1
- package/lib/ProvidePlugin.js +3 -1
- package/lib/RawModule.js +2 -1
- package/lib/RecordIdsPlugin.js +4 -4
- package/lib/ResolverFactory.js +6 -4
- package/lib/RuntimeModule.js +4 -4
- package/lib/RuntimePlugin.js +1 -0
- package/lib/RuntimeTemplate.js +124 -52
- package/lib/SourceMapDevToolPlugin.js +4 -1
- package/lib/Stats.js +11 -4
- package/lib/Template.js +5 -5
- package/lib/TemplatedPathPlugin.js +48 -7
- package/lib/Watching.js +67 -60
- package/lib/WebpackError.js +6 -6
- package/lib/WebpackOptionsApply.js +18 -5
- package/lib/asset/AssetGenerator.js +15 -0
- package/lib/asset/RawDataUrlModule.js +3 -1
- package/lib/async-modules/AwaitDependenciesInitFragment.js +2 -2
- package/lib/buildChunkGraph.js +120 -67
- package/lib/cache/IdleFileCachePlugin.js +8 -3
- package/lib/cache/MemoryCachePlugin.js +1 -1
- package/lib/cache/MemoryWithGcCachePlugin.js +6 -2
- package/lib/cache/PackFileCacheStrategy.js +51 -18
- package/lib/cache/ResolverCachePlugin.js +22 -14
- package/lib/cache/getLazyHashedEtag.js +2 -2
- package/lib/cli.js +5 -5
- package/lib/config/browserslistTargetHandler.js +7 -1
- package/lib/config/defaults.js +108 -34
- package/lib/config/normalization.js +3 -1
- package/lib/config/target.js +18 -11
- package/lib/container/ContainerEntryDependency.js +2 -1
- package/lib/container/ContainerEntryModule.js +4 -2
- package/lib/container/ContainerPlugin.js +14 -10
- package/lib/container/FallbackModule.js +1 -1
- package/lib/container/RemoteRuntimeModule.js +12 -3
- package/lib/css/CssExportsGenerator.js +68 -25
- package/lib/css/CssGenerator.js +34 -6
- package/lib/css/CssLoadingRuntimeModule.js +217 -98
- package/lib/css/CssModulesPlugin.js +238 -107
- package/lib/css/CssParser.js +24 -15
- package/lib/css/walkCssTokens.js +1 -1
- package/lib/debug/ProfilingPlugin.js +28 -3
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +9 -5
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +4 -1
- package/lib/dependencies/CommonJsDependencyHelpers.js +2 -1
- package/lib/dependencies/CommonJsExportRequireDependency.js +33 -18
- package/lib/dependencies/CommonJsExportsDependency.js +13 -5
- package/lib/dependencies/CommonJsExportsParserPlugin.js +20 -15
- package/lib/dependencies/CommonJsImportsParserPlugin.js +1 -2
- package/lib/dependencies/ContextDependencyHelpers.js +49 -29
- package/lib/dependencies/ContextElementDependency.js +8 -1
- package/lib/dependencies/CssExportDependency.js +2 -2
- package/lib/dependencies/CssLocalIdentifierDependency.js +71 -9
- package/lib/dependencies/CssUrlDependency.js +10 -7
- package/lib/dependencies/ExportsInfoDependency.js +5 -4
- package/lib/dependencies/ExternalModuleDependency.js +4 -2
- package/lib/dependencies/ExternalModuleInitFragment.js +5 -3
- package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +4 -4
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +43 -23
- package/lib/dependencies/HarmonyExportHeaderDependency.js +1 -1
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +73 -32
- package/lib/dependencies/HarmonyExportInitFragment.js +10 -2
- package/lib/dependencies/HarmonyImportDependency.js +28 -12
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +70 -19
- package/lib/dependencies/HarmonyImportSideEffectDependency.js +7 -6
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +47 -35
- package/lib/dependencies/ImportDependency.js +9 -2
- package/lib/dependencies/ImportEagerDependency.js +4 -2
- package/lib/dependencies/ImportMetaContextDependency.js +7 -0
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +25 -14
- package/lib/dependencies/ImportMetaPlugin.js +1 -1
- package/lib/dependencies/ImportParserPlugin.js +15 -5
- package/lib/dependencies/ImportWeakDependency.js +4 -2
- package/lib/dependencies/LoaderDependency.js +2 -1
- package/lib/dependencies/LoaderImportDependency.js +2 -1
- package/lib/dependencies/LoaderPlugin.js +2 -2
- package/lib/dependencies/ModuleDependency.js +4 -5
- package/lib/dependencies/PureExpressionDependency.js +64 -47
- package/lib/dependencies/RequireContextPlugin.js +1 -1
- package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +26 -14
- package/lib/dependencies/RequireEnsureDependency.js +1 -1
- package/lib/dependencies/URLDependency.js +7 -4
- package/lib/dependencies/WorkerDependency.js +1 -1
- package/lib/dependencies/WorkerPlugin.js +2 -1
- package/lib/dependencies/getFunctionExpression.js +3 -1
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +92 -3
- package/lib/hmr/LazyCompilationPlugin.js +2 -2
- package/lib/ids/ChunkModuleIdRangePlugin.js +1 -1
- package/lib/ids/DeterministicChunkIdsPlugin.js +1 -1
- package/lib/ids/DeterministicModuleIdsPlugin.js +1 -1
- package/lib/ids/IdHelpers.js +6 -6
- package/lib/ids/NamedChunkIdsPlugin.js +1 -1
- package/lib/ids/NamedModuleIdsPlugin.js +1 -1
- package/lib/ids/SyncModuleIdsPlugin.js +2 -2
- package/lib/index.js +11 -0
- package/lib/javascript/BasicEvaluatedExpression.js +2 -2
- package/lib/javascript/ChunkHelpers.js +2 -2
- package/lib/javascript/CommonJsChunkFormatPlugin.js +1 -1
- package/lib/javascript/JavascriptGenerator.js +0 -1
- package/lib/javascript/JavascriptModulesPlugin.js +174 -17
- package/lib/javascript/JavascriptParser.js +204 -71
- package/lib/javascript/JavascriptParserHelpers.js +1 -1
- package/lib/javascript/StartupHelpers.js +22 -5
- package/lib/library/AbstractLibraryPlugin.js +2 -2
- package/lib/library/AmdLibraryPlugin.js +2 -2
- package/lib/library/AssignLibraryPlugin.js +3 -3
- package/lib/library/ExportPropertyLibraryPlugin.js +2 -2
- package/lib/library/JsonpLibraryPlugin.js +2 -2
- package/lib/library/ModuleLibraryPlugin.js +2 -2
- package/lib/library/SystemLibraryPlugin.js +2 -2
- package/lib/library/UmdLibraryPlugin.js +33 -12
- package/lib/logging/Logger.js +27 -2
- package/lib/logging/createConsoleLogger.js +13 -9
- package/lib/node/CommonJsChunkLoadingPlugin.js +2 -1
- package/lib/node/NodeEnvironmentPlugin.js +14 -8
- package/lib/node/NodeTemplatePlugin.js +1 -1
- package/lib/node/NodeWatchFileSystem.js +37 -26
- package/lib/node/ReadFileChunkLoadingRuntimeModule.js +2 -1
- package/lib/node/ReadFileCompileWasmPlugin.js +1 -1
- package/lib/node/RequireChunkLoadingRuntimeModule.js +2 -1
- package/lib/node/nodeConsole.js +24 -1
- package/lib/optimize/AggressiveMergingPlugin.js +1 -1
- package/lib/optimize/AggressiveSplittingPlugin.js +1 -0
- package/lib/optimize/ConcatenatedModule.js +140 -121
- package/lib/optimize/EnsureChunkConditionsPlugin.js +1 -1
- package/lib/optimize/InnerGraph.js +8 -3
- package/lib/optimize/InnerGraphPlugin.js +36 -13
- package/lib/optimize/LimitChunkCountPlugin.js +1 -2
- package/lib/optimize/ModuleConcatenationPlugin.js +13 -3
- package/lib/optimize/RealContentHashPlugin.js +3 -3
- package/lib/optimize/RemoveParentModulesPlugin.js +1 -0
- package/lib/optimize/RuntimeChunkPlugin.js +6 -1
- package/lib/optimize/SideEffectsFlagPlugin.js +48 -17
- package/lib/optimize/SplitChunksPlugin.js +10 -10
- package/lib/performance/SizeLimitsPlugin.js +13 -2
- package/lib/rules/ObjectMatcherRulePlugin.js +15 -1
- package/lib/rules/RuleSetCompiler.js +9 -7
- package/lib/runtime/EnsureChunkRuntimeModule.js +2 -1
- package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +2 -1
- package/lib/runtime/LoadScriptRuntimeModule.js +1 -1
- package/lib/runtime/StartupChunkDependenciesPlugin.js +1 -1
- package/lib/schemes/HttpUriPlugin.js +1 -1
- package/lib/serialization/BinaryMiddleware.js +4 -4
- package/lib/serialization/FileMiddleware.js +4 -3
- package/lib/serialization/NullPrototypeObjectSerializer.js +2 -2
- package/lib/serialization/ObjectMiddleware.js +8 -5
- package/lib/serialization/PlainObjectSerializer.js +2 -2
- package/lib/serialization/Serializer.js +19 -0
- package/lib/serialization/SerializerMiddleware.js +2 -2
- package/lib/serialization/SingleItemMiddleware.js +2 -2
- package/lib/serialization/types.js +1 -1
- package/lib/sharing/ConsumeSharedModule.js +2 -2
- package/lib/sharing/ConsumeSharedPlugin.js +17 -3
- package/lib/sharing/ConsumeSharedRuntimeModule.js +9 -2
- package/lib/sharing/ProvideSharedPlugin.js +13 -6
- package/lib/sharing/resolveMatchedConfigs.js +3 -3
- package/lib/sharing/utils.js +13 -6
- package/lib/stats/DefaultStatsFactoryPlugin.js +20 -20
- package/lib/stats/DefaultStatsPrinterPlugin.js +1 -1
- package/lib/stats/StatsFactory.js +2 -2
- package/lib/stats/StatsPrinter.js +6 -6
- package/lib/util/ArrayQueue.js +14 -21
- package/lib/util/AsyncQueue.js +1 -1
- package/lib/util/Queue.js +8 -2
- package/lib/util/SortableSet.js +16 -4
- package/lib/util/StackedCacheMap.js +26 -0
- package/lib/util/TupleQueue.js +8 -2
- package/lib/util/WeakTupleMap.js +57 -13
- package/lib/util/binarySearchBounds.js +1 -1
- package/lib/util/cleverMerge.js +26 -13
- package/lib/util/comparators.js +37 -15
- package/lib/util/conventions.js +129 -0
- package/lib/util/createHash.js +3 -5
- package/lib/util/deprecation.js +3 -3
- package/lib/util/deterministicGrouping.js +2 -2
- package/lib/util/findGraphRoots.js +1 -1
- package/lib/util/fs.js +383 -69
- package/lib/util/hash/BatchedHash.js +3 -0
- package/lib/util/hash/xxhash64.js +2 -2
- package/lib/util/identifier.js +5 -5
- package/lib/util/mergeScope.js +79 -0
- package/lib/util/runtime.js +2 -17
- package/lib/util/semver.js +3 -0
- package/lib/util/smartGrouping.js +3 -3
- package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +4 -2
- package/lib/wasm-async/AsyncWebAssemblyGenerator.js +1 -1
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +4 -2
- package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +3 -3
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +16 -7
- package/lib/wasm-sync/WebAssemblyGenerator.js +40 -19
- package/lib/wasm-sync/WebAssemblyModulesPlugin.js +1 -1
- package/lib/wasm-sync/WebAssemblyParser.js +7 -4
- package/lib/wasm-sync/WebAssemblyUtils.js +2 -1
- package/lib/web/FetchCompileWasmPlugin.js +1 -1
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +3 -2
- package/lib/webpack.js +19 -6
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +2 -1
- package/package.json +40 -39
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +97 -8
- package/schemas/plugins/BannerPlugin.check.js +1 -1
- package/schemas/plugins/BannerPlugin.json +5 -1
- package/schemas/plugins/css/CssAutoGeneratorOptions.check.js +1 -1
- package/schemas/plugins/css/CssGeneratorOptions.check.js +1 -1
- package/schemas/plugins/css/CssGlobalGeneratorOptions.check.js +1 -1
- package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +1 -1
- package/types.d.ts +1826 -639
@@ -12,25 +12,47 @@ const Chunk = require("./Chunk");
|
|
12
12
|
const Module = require("./Module");
|
13
13
|
const { parseResource } = require("./util/identifier");
|
14
14
|
|
15
|
+
/** @typedef {import("./ChunkGraph")} ChunkGraph */
|
15
16
|
/** @typedef {import("./Compilation").AssetInfo} AssetInfo */
|
16
17
|
/** @typedef {import("./Compilation").PathData} PathData */
|
17
18
|
/** @typedef {import("./Compiler")} Compiler */
|
18
19
|
|
19
20
|
const REGEXP = /\[\\*([\w:]+)\\*\]/gi;
|
20
21
|
|
22
|
+
/**
|
23
|
+
* @param {string | number} id id
|
24
|
+
* @returns {string | number} result
|
25
|
+
*/
|
21
26
|
const prepareId = id => {
|
22
27
|
if (typeof id !== "string") return id;
|
23
28
|
|
24
29
|
if (/^"\s\+*.*\+\s*"$/.test(id)) {
|
25
30
|
const match = /^"\s\+*\s*(.*)\s*\+\s*"$/.exec(id);
|
26
31
|
|
27
|
-
return `" + (${
|
32
|
+
return `" + (${
|
33
|
+
/** @type {string[]} */ (match)[1]
|
34
|
+
} + "").replace(/(^[.-]|[^a-zA-Z0-9_-])+/g, "_") + "`;
|
28
35
|
}
|
29
36
|
|
30
37
|
return id.replace(/(^[.-]|[^a-zA-Z0-9_-])+/g, "_");
|
31
38
|
};
|
32
39
|
|
40
|
+
/**
|
41
|
+
* @callback ReplacerFunction
|
42
|
+
* @param {string} match
|
43
|
+
* @param {string | undefined} arg
|
44
|
+
* @param {string} input
|
45
|
+
*/
|
46
|
+
|
47
|
+
/**
|
48
|
+
* @param {ReplacerFunction} replacer replacer
|
49
|
+
* @param {((arg0: number) => string) | undefined} handler handler
|
50
|
+
* @param {AssetInfo | undefined} assetInfo asset info
|
51
|
+
* @param {string} hashName hash name
|
52
|
+
* @returns {ReplacerFunction} hash replacer function
|
53
|
+
*/
|
33
54
|
const hashLength = (replacer, handler, assetInfo, hashName) => {
|
55
|
+
/** @type {ReplacerFunction} */
|
34
56
|
const fn = (match, arg, input) => {
|
35
57
|
let result;
|
36
58
|
const length = arg && parseInt(arg, 10);
|
@@ -58,7 +80,15 @@ const hashLength = (replacer, handler, assetInfo, hashName) => {
|
|
58
80
|
return fn;
|
59
81
|
};
|
60
82
|
|
83
|
+
/** @typedef {(match: string, arg?: string, input?: string) => string} Replacer */
|
84
|
+
|
85
|
+
/**
|
86
|
+
* @param {string | number | null | undefined | (() => string | number | null | undefined)} value value
|
87
|
+
* @param {boolean=} allowEmpty allow empty
|
88
|
+
* @returns {Replacer} replacer
|
89
|
+
*/
|
61
90
|
const replacer = (value, allowEmpty) => {
|
91
|
+
/** @type {Replacer} */
|
62
92
|
const fn = (match, arg, input) => {
|
63
93
|
if (typeof value === "function") {
|
64
94
|
value = value();
|
@@ -81,6 +111,12 @@ const replacer = (value, allowEmpty) => {
|
|
81
111
|
|
82
112
|
const deprecationCache = new Map();
|
83
113
|
const deprecatedFunction = (() => () => {})();
|
114
|
+
/**
|
115
|
+
* @param {Function} fn function
|
116
|
+
* @param {string} message message
|
117
|
+
* @param {string} code code
|
118
|
+
* @returns {function(...any[]): void} function with deprecation output
|
119
|
+
*/
|
84
120
|
const deprecated = (fn, message, code) => {
|
85
121
|
let d = deprecationCache.get(message);
|
86
122
|
if (d === undefined) {
|
@@ -96,7 +132,7 @@ const deprecated = (fn, message, code) => {
|
|
96
132
|
/**
|
97
133
|
* @param {string | function(PathData, AssetInfo=): string} path the raw path
|
98
134
|
* @param {PathData} data context data
|
99
|
-
* @param {AssetInfo} assetInfo extra info about the asset (will be written to)
|
135
|
+
* @param {AssetInfo | undefined} assetInfo extra info about the asset (will be written to)
|
100
136
|
* @returns {string} the interpolated path
|
101
137
|
*/
|
102
138
|
const replacePathVariables = (path, data, assetInfo) => {
|
@@ -227,7 +263,7 @@ const replacePathVariables = (path, data, assetInfo) => {
|
|
227
263
|
),
|
228
264
|
data.contentHashWithLength ||
|
229
265
|
("contentHashWithLength" in chunk && chunk.contentHashWithLength
|
230
|
-
? chunk.contentHashWithLength[contentHashType]
|
266
|
+
? chunk.contentHashWithLength[/** @type {string} */ (contentHashType)]
|
231
267
|
: undefined),
|
232
268
|
assetInfo,
|
233
269
|
"contenthash"
|
@@ -255,13 +291,18 @@ const replacePathVariables = (path, data, assetInfo) => {
|
|
255
291
|
|
256
292
|
const idReplacer = replacer(() =>
|
257
293
|
prepareId(
|
258
|
-
module instanceof Module
|
294
|
+
module instanceof Module
|
295
|
+
? /** @type {ChunkGraph} */ (chunkGraph).getModuleId(module)
|
296
|
+
: module.id
|
259
297
|
)
|
260
298
|
);
|
261
299
|
const moduleHashReplacer = hashLength(
|
262
300
|
replacer(() =>
|
263
301
|
module instanceof Module
|
264
|
-
? chunkGraph.getRenderedModuleHash(
|
302
|
+
? /** @type {ChunkGraph} */ (chunkGraph).getRenderedModuleHash(
|
303
|
+
module,
|
304
|
+
data.runtime
|
305
|
+
)
|
265
306
|
: module.hash
|
266
307
|
),
|
267
308
|
"hashWithLength" in module ? module.hashWithLength : undefined,
|
@@ -269,7 +310,7 @@ const replacePathVariables = (path, data, assetInfo) => {
|
|
269
310
|
"modulehash"
|
270
311
|
);
|
271
312
|
const contentHashReplacer = hashLength(
|
272
|
-
replacer(data.contentHash),
|
313
|
+
replacer(/** @type {string} */ (data.contentHash)),
|
273
314
|
undefined,
|
274
315
|
assetInfo,
|
275
316
|
"contenthash"
|
@@ -300,7 +341,7 @@ const replacePathVariables = (path, data, assetInfo) => {
|
|
300
341
|
if (typeof data.runtime === "string") {
|
301
342
|
replacements.set(
|
302
343
|
"runtime",
|
303
|
-
replacer(() => prepareId(data.runtime))
|
344
|
+
replacer(() => prepareId(/** @type {string} */ (data.runtime)))
|
304
345
|
);
|
305
346
|
} else {
|
306
347
|
replacements.set("runtime", replacer("_"));
|
package/lib/Watching.js
CHANGED
@@ -13,11 +13,12 @@ const Stats = require("./Stats");
|
|
13
13
|
/** @typedef {import("./FileSystemInfo").FileSystemInfoEntry} FileSystemInfoEntry */
|
14
14
|
/** @typedef {import("./WebpackError")} WebpackError */
|
15
15
|
/** @typedef {import("./logging/Logger").Logger} Logger */
|
16
|
+
/** @typedef {import("./util/fs").WatchFileSystem} WatchFileSystem */
|
16
17
|
|
17
18
|
/**
|
18
19
|
* @template T
|
19
20
|
* @callback Callback
|
20
|
-
* @param {
|
21
|
+
* @param {Error | null} err
|
21
22
|
* @param {T=} result
|
22
23
|
*/
|
23
24
|
|
@@ -171,8 +172,16 @@ class Watching {
|
|
171
172
|
this._invalidReported = false;
|
172
173
|
this.compiler.hooks.watchRun.callAsync(this.compiler, err => {
|
173
174
|
if (err) return this._done(err);
|
174
|
-
|
175
|
-
|
175
|
+
/**
|
176
|
+
* @param {Error | null} err error
|
177
|
+
* @param {Compilation=} _compilation compilation
|
178
|
+
* @returns {void}
|
179
|
+
*/
|
180
|
+
const onCompiled = (err, _compilation) => {
|
181
|
+
if (err) return this._done(err, _compilation);
|
182
|
+
|
183
|
+
const compilation = /** @type {Compilation} */ (_compilation);
|
184
|
+
|
176
185
|
if (this.invalid) return this._done(null, compilation);
|
177
186
|
|
178
187
|
if (this.compiler.hooks.shouldEmit.call(compilation) === false) {
|
@@ -195,7 +204,9 @@ class Watching {
|
|
195
204
|
if (compilation.hooks.needAdditionalPass.call()) {
|
196
205
|
compilation.needAdditionalPass = true;
|
197
206
|
|
198
|
-
compilation.startTime =
|
207
|
+
compilation.startTime = /** @type {number} */ (
|
208
|
+
this.startTime
|
209
|
+
);
|
199
210
|
compilation.endTime = Date.now();
|
200
211
|
logger.time("done hook");
|
201
212
|
const stats = new Stats(compilation);
|
@@ -239,10 +250,12 @@ class Watching {
|
|
239
250
|
_done(err, compilation) {
|
240
251
|
this.running = false;
|
241
252
|
|
242
|
-
const logger =
|
253
|
+
const logger =
|
254
|
+
/** @type {Logger} */
|
255
|
+
(compilation && compilation.getLogger("webpack.Watching"));
|
243
256
|
|
244
|
-
/** @type {Stats |
|
245
|
-
let stats =
|
257
|
+
/** @type {Stats | undefined} */
|
258
|
+
let stats = undefined;
|
246
259
|
|
247
260
|
/**
|
248
261
|
* @param {Error} err error
|
@@ -267,13 +280,11 @@ class Watching {
|
|
267
280
|
!(this._isBlocked() && (this.blocked = true))
|
268
281
|
) {
|
269
282
|
if (compilation) {
|
270
|
-
|
271
|
-
(logger).time("storeBuildDependencies");
|
283
|
+
logger.time("storeBuildDependencies");
|
272
284
|
this.compiler.cache.storeBuildDependencies(
|
273
285
|
compilation.buildDependencies,
|
274
286
|
err => {
|
275
|
-
|
276
|
-
(logger).timeEnd("storeBuildDependencies");
|
287
|
+
logger.timeEnd("storeBuildDependencies");
|
277
288
|
if (err) return handleError(err);
|
278
289
|
this._go();
|
279
290
|
}
|
@@ -285,7 +296,7 @@ class Watching {
|
|
285
296
|
}
|
286
297
|
|
287
298
|
if (compilation) {
|
288
|
-
compilation.startTime = this.startTime;
|
299
|
+
compilation.startTime = /** @type {number} */ (this.startTime);
|
289
300
|
compilation.endTime = Date.now();
|
290
301
|
stats = new Stats(compilation);
|
291
302
|
}
|
@@ -294,28 +305,22 @@ class Watching {
|
|
294
305
|
|
295
306
|
const cbs = this.callbacks;
|
296
307
|
this.callbacks = [];
|
297
|
-
|
298
|
-
(logger).time("done hook");
|
308
|
+
logger.time("done hook");
|
299
309
|
this.compiler.hooks.done.callAsync(/** @type {Stats} */ (stats), err => {
|
300
|
-
|
301
|
-
(logger).timeEnd("done hook");
|
310
|
+
logger.timeEnd("done hook");
|
302
311
|
if (err) return handleError(err, cbs);
|
303
|
-
this.handler(null,
|
304
|
-
|
305
|
-
(logger).time("storeBuildDependencies");
|
312
|
+
this.handler(null, stats);
|
313
|
+
logger.time("storeBuildDependencies");
|
306
314
|
this.compiler.cache.storeBuildDependencies(
|
307
315
|
/** @type {Compilation} */
|
308
316
|
(compilation).buildDependencies,
|
309
317
|
err => {
|
310
|
-
|
311
|
-
(logger).timeEnd("storeBuildDependencies");
|
318
|
+
logger.timeEnd("storeBuildDependencies");
|
312
319
|
if (err) return handleError(err, cbs);
|
313
|
-
|
314
|
-
(logger).time("beginIdle");
|
320
|
+
logger.time("beginIdle");
|
315
321
|
this.compiler.cache.beginIdle();
|
316
322
|
this.compiler.idle = true;
|
317
|
-
|
318
|
-
(logger).timeEnd("beginIdle");
|
323
|
+
logger.timeEnd("beginIdle");
|
319
324
|
process.nextTick(() => {
|
320
325
|
if (!this.closed) {
|
321
326
|
this.watch(
|
@@ -343,43 +348,45 @@ class Watching {
|
|
343
348
|
*/
|
344
349
|
watch(files, dirs, missing) {
|
345
350
|
this.pausedWatcher = null;
|
346
|
-
this.watcher =
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
changedFiles,
|
357
|
-
removedFiles
|
358
|
-
) => {
|
359
|
-
if (err) {
|
360
|
-
this.compiler.modifiedFiles = undefined;
|
361
|
-
this.compiler.removedFiles = undefined;
|
362
|
-
this.compiler.fileTimestamps = undefined;
|
363
|
-
this.compiler.contextTimestamps = undefined;
|
364
|
-
this.compiler.fsStartTime = undefined;
|
365
|
-
return this.handler(err);
|
366
|
-
}
|
367
|
-
this._invalidate(
|
351
|
+
this.watcher =
|
352
|
+
/** @type {WatchFileSystem} */
|
353
|
+
(this.compiler.watchFileSystem).watch(
|
354
|
+
files,
|
355
|
+
dirs,
|
356
|
+
missing,
|
357
|
+
/** @type {number} */ (this.lastWatcherStartTime),
|
358
|
+
this.watchOptions,
|
359
|
+
(
|
360
|
+
err,
|
368
361
|
fileTimeInfoEntries,
|
369
362
|
contextTimeInfoEntries,
|
370
363
|
changedFiles,
|
371
364
|
removedFiles
|
372
|
-
)
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
365
|
+
) => {
|
366
|
+
if (err) {
|
367
|
+
this.compiler.modifiedFiles = undefined;
|
368
|
+
this.compiler.removedFiles = undefined;
|
369
|
+
this.compiler.fileTimestamps = undefined;
|
370
|
+
this.compiler.contextTimestamps = undefined;
|
371
|
+
this.compiler.fsStartTime = undefined;
|
372
|
+
return this.handler(err);
|
373
|
+
}
|
374
|
+
this._invalidate(
|
375
|
+
fileTimeInfoEntries,
|
376
|
+
contextTimeInfoEntries,
|
377
|
+
changedFiles,
|
378
|
+
removedFiles
|
379
|
+
);
|
380
|
+
this._onChange();
|
381
|
+
},
|
382
|
+
(fileName, changeTime) => {
|
383
|
+
if (!this._invalidReported) {
|
384
|
+
this._invalidReported = true;
|
385
|
+
this.compiler.hooks.invalid.call(fileName, changeTime);
|
386
|
+
}
|
387
|
+
this._onInvalid();
|
379
388
|
}
|
380
|
-
|
381
|
-
}
|
382
|
-
);
|
389
|
+
);
|
383
390
|
}
|
384
391
|
|
385
392
|
/**
|
@@ -452,7 +459,7 @@ class Watching {
|
|
452
459
|
return;
|
453
460
|
}
|
454
461
|
/**
|
455
|
-
* @param {
|
462
|
+
* @param {WebpackError | null} err error if any
|
456
463
|
* @param {Compilation=} compilation compilation if any
|
457
464
|
*/
|
458
465
|
const finalCallback = (err, compilation) => {
|
@@ -466,7 +473,7 @@ class Watching {
|
|
466
473
|
this.compiler.contextTimestamps = undefined;
|
467
474
|
this.compiler.fsStartTime = undefined;
|
468
475
|
/**
|
469
|
-
* @param {
|
476
|
+
* @param {WebpackError | null} err error if any
|
470
477
|
*/
|
471
478
|
const shutdown = err => {
|
472
479
|
this.compiler.hooks.watchClose.call();
|
@@ -508,7 +515,7 @@ class Watching {
|
|
508
515
|
this.invalid = true;
|
509
516
|
this._done = finalCallback;
|
510
517
|
} else {
|
511
|
-
finalCallback();
|
518
|
+
finalCallback(null);
|
512
519
|
}
|
513
520
|
}
|
514
521
|
}
|
package/lib/WebpackError.js
CHANGED
@@ -22,17 +22,17 @@ class WebpackError extends Error {
|
|
22
22
|
constructor(message) {
|
23
23
|
super(message);
|
24
24
|
|
25
|
-
/** @type {string
|
25
|
+
/** @type {string=} */
|
26
26
|
this.details = undefined;
|
27
|
-
/** @type {Module |
|
27
|
+
/** @type {(Module | null)=} */
|
28
28
|
this.module = undefined;
|
29
|
-
/** @type {DependencyLocation
|
29
|
+
/** @type {DependencyLocation=} */
|
30
30
|
this.loc = undefined;
|
31
|
-
/** @type {boolean
|
31
|
+
/** @type {boolean=} */
|
32
32
|
this.hideStack = undefined;
|
33
|
-
/** @type {Chunk
|
33
|
+
/** @type {Chunk=} */
|
34
34
|
this.chunk = undefined;
|
35
|
-
/** @type {string
|
35
|
+
/** @type {string=} */
|
36
36
|
this.file = undefined;
|
37
37
|
}
|
38
38
|
|
@@ -57,6 +57,8 @@ const { cleverMerge } = require("./util/cleverMerge");
|
|
57
57
|
|
58
58
|
/** @typedef {import("../declarations/WebpackOptions").WebpackOptionsNormalized} WebpackOptions */
|
59
59
|
/** @typedef {import("./Compiler")} Compiler */
|
60
|
+
/** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */
|
61
|
+
/** @typedef {import("./util/fs").IntermediateFileSystem} IntermediateFileSystem */
|
60
62
|
|
61
63
|
class WebpackOptionsApply extends OptionsApply {
|
62
64
|
constructor() {
|
@@ -455,7 +457,10 @@ class WebpackOptionsApply extends OptionsApply {
|
|
455
457
|
}
|
456
458
|
if (options.optimization.runtimeChunk) {
|
457
459
|
const RuntimeChunkPlugin = require("./optimize/RuntimeChunkPlugin");
|
458
|
-
new RuntimeChunkPlugin(
|
460
|
+
new RuntimeChunkPlugin(
|
461
|
+
/** @type {{ name?: (entrypoint: { name: string }) => string }} */
|
462
|
+
(options.optimization.runtimeChunk)
|
463
|
+
).apply(compiler);
|
459
464
|
}
|
460
465
|
if (!options.optimization.emitOnErrors) {
|
461
466
|
const NoEmitOnErrorsPlugin = require("./NoEmitOnErrorsPlugin");
|
@@ -649,7 +654,9 @@ class WebpackOptionsApply extends OptionsApply {
|
|
649
654
|
new IdleFileCachePlugin(
|
650
655
|
new PackFileCacheStrategy({
|
651
656
|
compiler,
|
652
|
-
fs:
|
657
|
+
fs: /** @type {IntermediateFileSystem} */ (
|
658
|
+
compiler.intermediateFileSystem
|
659
|
+
),
|
653
660
|
context: options.context,
|
654
661
|
cacheLocation: cacheOptions.cacheLocation,
|
655
662
|
version: cacheOptions.version,
|
@@ -694,14 +701,18 @@ class WebpackOptionsApply extends OptionsApply {
|
|
694
701
|
.for("normal")
|
695
702
|
.tap("WebpackOptionsApply", resolveOptions => {
|
696
703
|
resolveOptions = cleverMerge(options.resolve, resolveOptions);
|
697
|
-
resolveOptions.fileSystem =
|
704
|
+
resolveOptions.fileSystem =
|
705
|
+
/** @type {InputFileSystem} */
|
706
|
+
(compiler.inputFileSystem);
|
698
707
|
return resolveOptions;
|
699
708
|
});
|
700
709
|
compiler.resolverFactory.hooks.resolveOptions
|
701
710
|
.for("context")
|
702
711
|
.tap("WebpackOptionsApply", resolveOptions => {
|
703
712
|
resolveOptions = cleverMerge(options.resolve, resolveOptions);
|
704
|
-
resolveOptions.fileSystem =
|
713
|
+
resolveOptions.fileSystem =
|
714
|
+
/** @type {InputFileSystem} */
|
715
|
+
(compiler.inputFileSystem);
|
705
716
|
resolveOptions.resolveToContext = true;
|
706
717
|
return resolveOptions;
|
707
718
|
});
|
@@ -709,7 +720,9 @@ class WebpackOptionsApply extends OptionsApply {
|
|
709
720
|
.for("loader")
|
710
721
|
.tap("WebpackOptionsApply", resolveOptions => {
|
711
722
|
resolveOptions = cleverMerge(options.resolveLoader, resolveOptions);
|
712
|
-
resolveOptions.fileSystem =
|
723
|
+
resolveOptions.fileSystem =
|
724
|
+
/** @type {InputFileSystem} */
|
725
|
+
(compiler.inputFileSystem);
|
713
726
|
return resolveOptions;
|
714
727
|
});
|
715
728
|
compiler.hooks.afterResolvers.call(compiler);
|
@@ -12,6 +12,7 @@ const ConcatenationScope = require("../ConcatenationScope");
|
|
12
12
|
const Generator = require("../Generator");
|
13
13
|
const { ASSET_MODULE_TYPE } = require("../ModuleTypeConstants");
|
14
14
|
const RuntimeGlobals = require("../RuntimeGlobals");
|
15
|
+
const CssUrlDependency = require("../dependencies/CssUrlDependency");
|
15
16
|
const createHash = require("../util/createHash");
|
16
17
|
const { makePathsRelative } = require("../util/identifier");
|
17
18
|
const nonNumericOnlyHash = require("../util/nonNumericOnlyHash");
|
@@ -321,6 +322,7 @@ class AssetGenerator extends Generator {
|
|
321
322
|
}
|
322
323
|
);
|
323
324
|
let assetPath;
|
325
|
+
let assetPathForCss;
|
324
326
|
if (this.publicPath !== undefined) {
|
325
327
|
const { path, info } =
|
326
328
|
runtimeTemplate.compilation.getAssetPathWithInfo(
|
@@ -335,12 +337,24 @@ class AssetGenerator extends Generator {
|
|
335
337
|
);
|
336
338
|
assetInfo = mergeAssetInfo(assetInfo, info);
|
337
339
|
assetPath = JSON.stringify(path + filename);
|
340
|
+
assetPathForCss = path + filename;
|
338
341
|
} else {
|
339
342
|
runtimeRequirements.add(RuntimeGlobals.publicPath); // add __webpack_require__.p
|
340
343
|
assetPath = runtimeTemplate.concatenation(
|
341
344
|
{ expr: RuntimeGlobals.publicPath },
|
342
345
|
filename
|
343
346
|
);
|
347
|
+
const compilation = runtimeTemplate.compilation;
|
348
|
+
const path =
|
349
|
+
compilation.outputOptions.publicPath === "auto"
|
350
|
+
? CssUrlDependency.PUBLIC_PATH_AUTO
|
351
|
+
: compilation.getAssetPath(
|
352
|
+
compilation.outputOptions.publicPath,
|
353
|
+
{
|
354
|
+
hash: compilation.hash
|
355
|
+
}
|
356
|
+
);
|
357
|
+
assetPathForCss = path + filename;
|
344
358
|
}
|
345
359
|
assetInfo = {
|
346
360
|
sourceFilename,
|
@@ -371,6 +385,7 @@ class AssetGenerator extends Generator {
|
|
371
385
|
data.set("fullContentHash", fullHash);
|
372
386
|
data.set("filename", filename);
|
373
387
|
data.set("assetInfo", assetInfo);
|
388
|
+
data.set("assetPathForCss", assetPathForCss);
|
374
389
|
}
|
375
390
|
content = assetPath;
|
376
391
|
}
|
@@ -71,7 +71,9 @@ class RawDataUrlModule extends Module {
|
|
71
71
|
* @returns {string} a user readable identifier of the module
|
72
72
|
*/
|
73
73
|
readableIdentifier(requestShortener) {
|
74
|
-
return
|
74
|
+
return /** @type {string} */ (
|
75
|
+
requestShortener.shorten(this.readableIdentifierStr)
|
76
|
+
);
|
75
77
|
}
|
76
78
|
|
77
79
|
/**
|
@@ -13,7 +13,7 @@ const Template = require("../Template");
|
|
13
13
|
/** @typedef {import("../Generator").GenerateContext} GenerateContext */
|
14
14
|
|
15
15
|
/**
|
16
|
-
* @
|
16
|
+
* @extends {InitFragment<GenerateContext>}
|
17
17
|
*/
|
18
18
|
class AwaitDependenciesInitFragment extends InitFragment {
|
19
19
|
/**
|
@@ -43,7 +43,7 @@ class AwaitDependenciesInitFragment extends InitFragment {
|
|
43
43
|
|
44
44
|
/**
|
45
45
|
* @param {GenerateContext} context context
|
46
|
-
* @returns {string | Source} the source code that will be included as initialization code
|
46
|
+
* @returns {string | Source | undefined} the source code that will be included as initialization code
|
47
47
|
*/
|
48
48
|
getContent({ runtimeRequirements }) {
|
49
49
|
runtimeRequirements.add(RuntimeGlobals.module);
|