webpack 5.112.0 → 5.112.1
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/bin/webpack.js +13 -7
- package/lib/Compilation.js +152 -60
- package/lib/Compiler.js +12 -25
- package/lib/asset/AssetBytesGenerator.js +14 -6
- package/lib/asset/AssetBytesParser.js +10 -8
- package/lib/asset/AssetGenerator.js +36 -48
- package/lib/asset/AssetModule.js +11 -0
- package/lib/asset/AssetModulesPlugin.js +5 -4
- package/lib/asset/AssetParser.js +8 -8
- package/lib/asset/AssetSourceGenerator.js +16 -8
- package/lib/asset/AssetSourceParser.js +10 -8
- package/lib/asset/WebManifestGenerator.js +11 -6
- package/lib/asset/WebManifestParser.js +3 -3
- package/lib/async-modules/AsyncModuleHelpers.js +8 -2
- package/lib/async-modules/InferAsyncModulesPlugin.js +7 -2
- package/lib/cache/CacheFacade.js +1 -1
- package/lib/cache/PackFileCacheStrategy.js +6 -10
- package/lib/cache/ResolverCachePlugin.js +58 -8
- package/lib/config/WebpackOptionsApply.js +8 -28
- package/lib/config/cli.js +9 -6
- package/lib/config/defaults.js +24 -13
- package/lib/config/getClaimedAssetTypes.js +2 -2
- package/lib/config/target.js +1 -1
- package/lib/context/ContextModule.js +1 -1
- package/lib/context/ContextModuleFactory.js +1 -1
- package/lib/context/ContextReplacementPlugin.js +3 -9
- package/lib/css/CssGenerator.js +40 -37
- package/lib/css/CssModule.js +10 -0
- package/lib/css/CssModulesPlugin.js +2 -2
- package/lib/css/CssParser.js +33 -32
- package/lib/css/conventions.js +1 -1
- package/lib/css/data.js +224 -219
- package/lib/css/syntax-parser.js +1159 -298
- package/lib/css/syntax-printer.js +90 -35
- package/lib/debug/ProfilingPlugin.js +65 -43
- package/lib/define/DefinePlugin.js +10 -15
- package/lib/define/DotenvPlugin.js +10 -6
- package/lib/define/EnvironmentPlugin.js +4 -2
- package/lib/dependencies/amd/AMDDefineDependencyParserPlugin.js +1 -2
- package/lib/dependencies/amd/AMDRequireDependenciesBlockParserPlugin.js +4 -1
- package/lib/dependencies/commonjs/CommonJsExportRequireDependency.js +1 -4
- package/lib/dependencies/commonjs/CommonJsExportsParserPlugin.js +18 -33
- package/lib/dependencies/commonjs/CommonJsImportsParserPlugin.js +1 -3
- package/lib/dependencies/commonjs/CommonJsObjectExportDependency.js +4 -4
- package/lib/dependencies/commonjs/CommonJsPlugin.js +2 -5
- package/lib/dependencies/commonjs/RequireEnsureDependenciesBlockParserPlugin.js +4 -1
- package/lib/dependencies/context/ImportMetaContextDependencyParserPlugin.js +1 -2
- package/lib/dependencies/context/ImportMetaGlobDependencyParserPlugin.js +4 -7
- package/lib/dependencies/context/ImportMetaGlobHelpers.js +8 -10
- package/lib/dependencies/core/CachedConstDependency.js +9 -6
- package/lib/dependencies/css/CssIcssExportDependency.js +6 -7
- package/lib/dependencies/css/CssIcssImportDependency.js +1 -3
- package/lib/dependencies/css/CssUrlDependency.js +2 -6
- package/lib/dependencies/esm/ESMDetectionParserPlugin.js +2 -4
- package/lib/dependencies/esm/ESMExportExpressionDependency.js +2 -2
- package/lib/dependencies/esm/ESMExportImportedSpecifierDependency.js +16 -18
- package/lib/dependencies/esm/ESMExportSpecifierDependency.js +20 -3
- package/lib/dependencies/esm/ESMExports.js +2 -10
- package/lib/dependencies/esm/ESMImportDependency.js +17 -2
- package/lib/dependencies/esm/ESMImportDependencyParserPlugin.js +6 -17
- package/lib/dependencies/esm/ESMImportGuard.js +11 -23
- package/lib/dependencies/esm/ESMImportSideEffectDependency.js +1 -1
- package/lib/dependencies/esm/ESMImportSpecifierDependency.js +4 -1
- package/lib/dependencies/esm/ESMLiveExportDependency.js +311 -0
- package/lib/dependencies/esm/ESMLiveExportParserPlugin.js +862 -0
- package/lib/dependencies/esm/ESMModulesPlugin.js +1 -3
- package/lib/dependencies/esm/TopLevelAwaitDependency.js +1 -8
- package/lib/dependencies/helpers/DynamicExports.js +4 -6
- package/lib/dependencies/html/HtmlEntryDependency.js +5 -14
- package/lib/dependencies/html/HtmlInlineHtmlDependency.js +1 -4
- package/lib/dependencies/html/HtmlInlineScriptDependency.js +2 -6
- package/lib/dependencies/html/HtmlInlineStyleDependency.js +1 -4
- package/lib/dependencies/import/ImportParserPlugin.js +3 -6
- package/lib/dependencies/import-meta/ImportMetaPlugin.js +4 -6
- package/lib/dependencies/url/URLParserPlugin.js +1 -1
- package/lib/dependencies/worker/WorkerAndWorkletPlugin.js +51 -20
- package/lib/devtool/ModuleFilenameHelpers.js +1 -1
- package/lib/devtool/SourceMapDevToolPlugin.js +1 -1
- package/lib/dll/DelegatedModule.js +3 -3
- package/lib/dll/DllModule.js +3 -1
- package/lib/dll/DllReferencePlugin.js +1 -4
- package/lib/errors/AbstractMethodError.js +1 -1
- package/lib/errors/ErrorHelpers.js +2 -1
- package/lib/errors/HookWebpackError.js +2 -1
- package/lib/errors/JSONParseError.js +4 -4
- package/lib/errors/WebpackError.js +3 -2
- package/lib/esm/ModuleChunkFormatPlugin.js +36 -1
- package/lib/externals/ExternalModule.js +12 -9
- package/lib/externals/ExternalModuleFactoryPlugin.js +1 -2
- package/lib/externals/ExternalsPlugin.js +1 -1
- package/lib/fs/FileSystemInfo.js +4 -4
- package/lib/graph/AsyncDependenciesBlock.js +1 -1
- package/lib/graph/ChunkGraph.js +5 -0
- package/lib/graph/Dependency.js +8 -2
- package/lib/graph/ExportsInfo.js +1 -1
- package/lib/graph/ModuleGraph.js +14 -3
- package/lib/graph/buildChunkGraph.js +17 -19
- package/lib/graph/findGraphRoots.js +1 -1
- package/lib/hmr/HotModuleReplacement.runtime.js +10 -9
- package/lib/hmr/HotModuleReplacementPlugin.js +5 -11
- package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +16 -19
- package/lib/hmr/LazyCompilationPlugin.js +1 -7
- package/lib/html/HtmlGenerator.js +25 -17
- package/lib/html/HtmlModule.js +11 -1
- package/lib/html/HtmlModulesPlugin.js +12 -11
- package/lib/html/HtmlParser.js +10 -9
- package/lib/html/builtinEmbeddedRenderer.js +31 -33
- package/lib/html/data.js +42 -21
- package/lib/html/htmlMinify.js +4 -1
- package/lib/html/syntax-parser.js +34 -35
- package/lib/html/syntax-printer.js +2 -3
- package/lib/html/xmlMinify.js +4 -1
- package/lib/ids/HashedModuleIdsPlugin.js +1 -1
- package/lib/index.js +13 -12
- package/lib/javascript/APIPlugin.js +7 -13
- package/lib/javascript/BasicEvaluatedExpression.js +5 -5
- package/lib/javascript/CommonJsChunkFormatPlugin.js +2 -7
- package/lib/javascript/ConstPlugin.js +1 -1
- package/lib/javascript/JavascriptGenerator.js +16 -11
- package/lib/javascript/JavascriptMetaInfoPlugin.js +3 -15
- package/lib/javascript/JavascriptModule.js +10 -0
- package/lib/javascript/JavascriptModulesPlugin.js +2 -4
- package/lib/javascript/JavascriptParser.js +99 -11
- package/lib/javascript/ScopeAnalyzer.js +183 -107
- package/lib/javascript/UseStrictPlugin.js +2 -5
- package/lib/javascript/jsMinify.js +1 -1
- package/lib/javascript/regexp.js +2 -2
- package/lib/javascript/syntax-parser.js +2114 -1506
- package/lib/javascript/syntax-printer-data.js +167 -1
- package/lib/javascript/syntax-printer.js +9554 -2782
- package/lib/json/JsonGenerator.js +15 -7
- package/lib/json/JsonModule.js +11 -0
- package/lib/json/JsonParser.js +7 -6
- package/lib/library/AssignLibraryPlugin.js +1 -1
- package/lib/library/JsonpLibraryPlugin.js +1 -1
- package/lib/library/ModuleLibraryPlugin.js +399 -23
- package/lib/loaders/LoaderRunner.js +76 -38
- package/lib/loaders/loadLoader.js +16 -10
- package/lib/module/Generator.js +17 -9
- package/lib/module/Module.js +2 -2
- package/lib/module/NormalModule.js +7 -5
- package/lib/module/NormalModuleFactory.js +11 -17
- package/lib/module/Parser.js +9 -2
- package/lib/module/extractSourceMap.js +69 -18
- package/lib/module/findCaseMismatch.js +2 -2
- package/lib/node/ExternalModuleInitFragment.js +2 -2
- package/lib/node/ReadFileCompileAsyncWasmPlugin.js +4 -12
- package/lib/node/ReadFileCompileWasmPlugin.js +2 -6
- package/lib/node/nodeConsole.js +4 -3
- package/lib/optimize/CircularModulesPlugin.js +1 -1
- package/lib/optimize/ConcatenatedModule.js +2 -6
- package/lib/optimize/FlagDependencyExportsPlugin.js +6 -11
- package/lib/optimize/FlagDependencyUsagePlugin.js +28 -3
- package/lib/optimize/InlineExports.js +4 -7
- package/lib/optimize/LazyBarrels.js +41 -5
- package/lib/optimize/ModuleConcatenationPlugin.js +8 -10
- package/lib/optimize/RealContentHashPlugin.js +2 -6
- package/lib/optimize/SideEffectsFlagPlugin.js +7 -21
- package/lib/optimize/SplitChunksPlugin.js +11 -24
- package/lib/optimize/TupleQueue.js +1 -1
- package/lib/output/CleanPlugin.js +3 -1
- package/lib/output/CopyPlugin.js +3 -4
- package/lib/performance/EvalUsagePlugin.js +1 -3
- package/lib/performance/HotspotsPlugin.js +33 -9
- package/lib/performance/PureAnnotationsPlugin.js +16 -10
- package/lib/performance/TopLevelThisPlugin.js +17 -9
- package/lib/prefetch/ResourceHintPlugin.js +1 -1
- package/lib/provide/ProvidedDependency.js +36 -4
- package/lib/rules/BasicEffectRulePlugin.js +1 -1
- package/lib/rules/RuleSetCompiler.js +15 -5
- package/lib/rules/UseEffectRulePlugin.js +1 -3
- package/lib/runtime/AsyncModuleRuntimeModule.js +7 -1
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +1 -5
- package/lib/runtime/RuntimeGlobals.js +6 -0
- package/lib/runtime/RuntimePlugin.js +2 -0
- package/lib/schemes/HttpUriPlugin.js +1 -2
- package/lib/schemes/VirtualUrlPlugin.js +3 -1
- package/lib/serialization/AggregateErrorSerializer.js +3 -3
- package/lib/serialization/BinaryMiddleware.js +4 -1
- package/lib/serialization/ErrorObjectSerializer.js +2 -5
- package/lib/serialization/ObjectMiddleware.js +17 -15
- package/lib/serialization/PlainObjectSerializer.js +3 -7
- package/lib/serialization/Serializer.js +21 -11
- package/lib/serialization/SerializerMiddleware.js +8 -6
- package/lib/stats/DefaultStatsFactoryPlugin.js +35 -35
- package/lib/stats/DefaultStatsPresetPlugin.js +2 -6
- package/lib/stats/DefaultStatsPrinterPlugin.js +12 -11
- package/lib/stats/StatsFactory.js +194 -24
- package/lib/stats/StatsPrinter.js +126 -13
- package/lib/template/DependencyTemplate.js +1 -1
- package/lib/template/RuntimeTemplate.js +13 -32
- package/lib/template/Template.js +1 -1
- package/lib/util/SourceProcessor.js +98 -15
- package/lib/util/WeakTupleMap.js +10 -4
- package/lib/util/cleverMerge.js +61 -33
- package/lib/util/comparators.js +9 -5
- package/lib/util/dataURL.js +2 -0
- package/lib/util/deprecation.js +4 -3
- package/lib/util/globUtils.js +1 -4
- package/lib/util/internalSerializables.js +2 -0
- package/lib/util/makeSerializable.js +6 -4
- package/lib/util/memoize.js +1 -1
- package/lib/util/parseJson.js +2 -2
- package/lib/util/serialization.js +31 -27
- package/lib/wasm/AsyncWasmModule.js +12 -2
- package/lib/wasm/AsyncWebAssemblyGenerator.js +12 -4
- package/lib/wasm/AsyncWebAssemblyJavascriptGenerator.js +13 -5
- package/lib/wasm/AsyncWebAssemblyParser.js +7 -5
- package/lib/wasm/UniversalCompileAsyncWasmPlugin.js +2 -6
- package/lib/wasm-sync/SyncWasmModule.js +16 -1
- package/lib/wasm-sync/WebAssemblyGenerator.js +15 -10
- package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +13 -5
- package/lib/wasm-sync/WebAssemblyParser.js +10 -12
- package/lib/web/FetchCompileAsyncWasmPlugin.js +4 -12
- package/lib/web/FetchCompileWasmPlugin.js +2 -6
- package/package.json +16 -18
- package/schemas/WebpackOptions.check.js +3 -3
- package/schemas/WebpackOptions.json +2 -2
- package/schemas/plugins/BannerPlugin.check.js +3 -3
- package/schemas/plugins/HtmlGeneratorOptions.check.js +3 -3
- package/schemas/plugins/HtmlParserOptions.check.js +3 -3
- package/schemas/plugins/IgnorePlugin.check.js +3 -3
- package/schemas/plugins/LoaderOptionsPlugin.check.js +3 -3
- package/schemas/plugins/ManifestPlugin.check.js +3 -3
- package/schemas/plugins/ProgressPlugin.check.js +3 -3
- package/schemas/plugins/SSRManifestPlugin.check.js +3 -3
- package/schemas/plugins/SourceMapDevToolPlugin.check.js +3 -3
- package/schemas/plugins/WatchIgnorePlugin.check.js +3 -3
- package/schemas/plugins/asset/AssetGeneratorOptions.check.js +3 -3
- package/schemas/plugins/asset/AssetInlineGeneratorOptions.check.js +3 -3
- package/schemas/plugins/asset/AssetParserOptions.check.js +3 -3
- package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.js +3 -3
- package/schemas/plugins/container/ContainerPlugin.check.js +3 -3
- package/schemas/plugins/container/ContainerReferencePlugin.check.js +3 -3
- package/schemas/plugins/container/ExternalsType.check.js +3 -3
- package/schemas/plugins/container/ModuleFederationPlugin.check.js +3 -3
- package/schemas/plugins/css/CssAutoOrModuleParserOptions.check.js +3 -3
- package/schemas/plugins/css/CssGeneratorOptions.check.js +3 -3
- package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +3 -3
- package/schemas/plugins/css/CssModuleParserOptions.check.js +3 -3
- package/schemas/plugins/css/CssParserOptions.check.js +3 -3
- package/schemas/plugins/debug/ProfilingPlugin.check.js +3 -3
- package/schemas/plugins/define/DotenvPluginOptions.check.js +7 -0
- package/schemas/plugins/define/DotenvPluginOptions.json +3 -0
- package/schemas/plugins/dll/DllPlugin.check.js +3 -3
- package/schemas/plugins/dll/DllReferencePlugin.check.js +3 -3
- package/schemas/plugins/ids/HashedModuleIdsPlugin.check.js +3 -3
- package/schemas/plugins/ids/OccurrenceChunkIdsPlugin.check.js +3 -3
- package/schemas/plugins/ids/OccurrenceModuleIdsPlugin.check.js +3 -3
- package/schemas/plugins/json/JsonModulesPluginGenerator.check.js +3 -3
- package/schemas/plugins/json/JsonModulesPluginParser.check.js +3 -3
- package/schemas/plugins/optimize/AggressiveSplittingPlugin.check.js +3 -3
- package/schemas/plugins/optimize/LimitChunkCountPlugin.check.js +3 -3
- package/schemas/plugins/optimize/MergeDuplicateChunksPlugin.check.js +3 -3
- package/schemas/plugins/optimize/MinChunkSizePlugin.check.js +3 -3
- package/schemas/plugins/output/CleanOptions.check.js +7 -0
- package/schemas/plugins/output/CleanOptions.json +3 -0
- package/schemas/plugins/schemes/HttpUriPlugin.check.js +3 -3
- package/schemas/plugins/schemes/VirtualUrlPlugin.check.js +3 -3
- package/schemas/plugins/sharing/ConsumeSharedPlugin.check.js +3 -3
- package/schemas/plugins/sharing/ProvideSharedPlugin.check.js +3 -3
- package/schemas/plugins/sharing/SharePlugin.check.js +3 -3
- package/types.d.ts +1482 -358
|
@@ -25,7 +25,6 @@ const makeSerializable = require("../util/makeSerializable");
|
|
|
25
25
|
* SnapshotOptions
|
|
26
26
|
* } from "../fs/FileSystemInfo"
|
|
27
27
|
*/
|
|
28
|
-
/** @import { ResolveOptionsWithDependencyType } from "../resolve/ResolverFactory" */
|
|
29
28
|
/**
|
|
30
29
|
* @import {
|
|
31
30
|
* ObjectDeserializerContext,
|
|
@@ -128,6 +127,10 @@ class ResolverCachePlugin {
|
|
|
128
127
|
let fileSystemInfo;
|
|
129
128
|
/** @type {SnapshotOptions | undefined} */
|
|
130
129
|
let snapshotOptions;
|
|
130
|
+
// paths the watcher reported for this build; a snapshot can miss them when
|
|
131
|
+
// the resolve read a cached file system state, e.g. inside a managed path
|
|
132
|
+
/** @type {Set<string> | undefined} */
|
|
133
|
+
let changedPaths;
|
|
131
134
|
let realResolves = 0;
|
|
132
135
|
let cachedResolves = 0;
|
|
133
136
|
let cacheInvalidResolves = 0;
|
|
@@ -137,10 +140,17 @@ class ResolverCachePlugin {
|
|
|
137
140
|
compiler.hooks.shutdown.tap(PLUGIN_NAME, () => {
|
|
138
141
|
fileSystemInfo = undefined;
|
|
139
142
|
snapshotOptions = undefined;
|
|
143
|
+
changedPaths = undefined;
|
|
140
144
|
});
|
|
141
145
|
compiler.hooks.thisCompilation.tap(PLUGIN_NAME, (compilation) => {
|
|
142
146
|
snapshotOptions = compilation.options.snapshot.resolve;
|
|
143
147
|
fileSystemInfo = compilation.fileSystemInfo;
|
|
148
|
+
const { modifiedFiles, removedFiles } = compiler;
|
|
149
|
+
changedPaths =
|
|
150
|
+
(modifiedFiles && modifiedFiles.size > 0) ||
|
|
151
|
+
(removedFiles && removedFiles.size > 0)
|
|
152
|
+
? new Set([...(modifiedFiles || []), ...(removedFiles || [])])
|
|
153
|
+
: undefined;
|
|
144
154
|
compilation.hooks.finishModules.tap(PLUGIN_NAME, () => {
|
|
145
155
|
if (realResolves + cachedResolves > 0) {
|
|
146
156
|
const logger = compilation.getLogger(`webpack.${PLUGIN_NAME}`);
|
|
@@ -157,6 +167,24 @@ class ResolverCachePlugin {
|
|
|
157
167
|
});
|
|
158
168
|
});
|
|
159
169
|
|
|
170
|
+
/**
|
|
171
|
+
* @param {InstanceType<Snapshot>} snapshot snapshot of a cached resolve
|
|
172
|
+
* @returns {boolean} true, when the watcher reported one of its paths
|
|
173
|
+
*/
|
|
174
|
+
const dependsOnChangedPath = (snapshot) => {
|
|
175
|
+
if (changedPaths === undefined) return false;
|
|
176
|
+
for (const iterable of [
|
|
177
|
+
snapshot.getMissingIterable(),
|
|
178
|
+
snapshot.getFileIterable(),
|
|
179
|
+
snapshot.getContextIterable()
|
|
180
|
+
]) {
|
|
181
|
+
for (const item of iterable) {
|
|
182
|
+
if (changedPaths.has(item)) return true;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
return false;
|
|
186
|
+
};
|
|
187
|
+
|
|
160
188
|
/** @typedef {(err?: Error | null, resolveRequest?: ResolveRequest | null) => void} Callback */
|
|
161
189
|
/** @typedef {ResolveRequest & { _ResolverCachePluginCacheMiss: true }} ResolveRequestWithCacheMiss */
|
|
162
190
|
|
|
@@ -227,9 +255,20 @@ class ResolverCachePlugin {
|
|
|
227
255
|
const fileDependencies = newResolveContext.fileDependencies;
|
|
228
256
|
const contextDependencies = newResolveContext.contextDependencies;
|
|
229
257
|
const missingDependencies = newResolveContext.missingDependencies;
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
258
|
+
const resolveResult = withYield ? yieldResult : result;
|
|
259
|
+
// the compiler was closed while resolving, e.g. after a bailed build
|
|
260
|
+
if (!fileSystemInfo) {
|
|
261
|
+
if (withYield && result) {
|
|
262
|
+
/** @type {ResolveRequest[]} */
|
|
263
|
+
(yieldResult).push(result);
|
|
264
|
+
}
|
|
265
|
+
return callback(
|
|
266
|
+
null,
|
|
267
|
+
/** @type {ResolveRequest} */
|
|
268
|
+
(resolveResult)
|
|
269
|
+
);
|
|
270
|
+
}
|
|
271
|
+
fileSystemInfo.createSnapshot(
|
|
233
272
|
resolveTime,
|
|
234
273
|
/** @type {Dependencies} */
|
|
235
274
|
(fileDependencies),
|
|
@@ -240,7 +279,6 @@ class ResolverCachePlugin {
|
|
|
240
279
|
snapshotOptions,
|
|
241
280
|
(err, snapshot) => {
|
|
242
281
|
if (err) return callback(err);
|
|
243
|
-
const resolveResult = withYield ? yieldResult : result;
|
|
244
282
|
// since we intercept resolve hook
|
|
245
283
|
// we still can get result in callback
|
|
246
284
|
if (withYield && result) {
|
|
@@ -287,9 +325,7 @@ class ResolverCachePlugin {
|
|
|
287
325
|
const activeRequests = new Map();
|
|
288
326
|
/** @type {Map<string, [ActiveRequest[], Yield[]]>} */
|
|
289
327
|
const activeRequestsWithYield = new Map();
|
|
290
|
-
const hook =
|
|
291
|
-
/** @type {SyncHook<[Resolver, ResolveOptions, ResolveOptionsWithDependencyType]>} */
|
|
292
|
-
(_hook);
|
|
328
|
+
const hook = _hook;
|
|
293
329
|
hook.tap(PLUGIN_NAME, (resolver, options, userOptions) => {
|
|
294
330
|
if (
|
|
295
331
|
/** @type {ResolveOptions & { cache: boolean }} */
|
|
@@ -416,6 +452,20 @@ class ResolverCachePlugin {
|
|
|
416
452
|
const processCacheResult = (err, cacheEntry) => {
|
|
417
453
|
if (err) return done(err);
|
|
418
454
|
|
|
455
|
+
// the compiler was closed while reading the cache
|
|
456
|
+
if (
|
|
457
|
+
cacheEntry &&
|
|
458
|
+
(!fileSystemInfo || dependsOnChangedPath(cacheEntry.snapshot))
|
|
459
|
+
) {
|
|
460
|
+
cacheInvalidResolves++;
|
|
461
|
+
return doRealResolve(
|
|
462
|
+
itemCache,
|
|
463
|
+
resolver,
|
|
464
|
+
resolveContext,
|
|
465
|
+
request,
|
|
466
|
+
done
|
|
467
|
+
);
|
|
468
|
+
}
|
|
419
469
|
if (cacheEntry) {
|
|
420
470
|
const { snapshot, result } = cacheEntry;
|
|
421
471
|
const fsInfo = /** @type {FileSystemInfo} */ (fileSystemInfo);
|
|
@@ -342,9 +342,7 @@ class WebpackOptionsApply extends OptionsApply {
|
|
|
342
342
|
}
|
|
343
343
|
}
|
|
344
344
|
|
|
345
|
-
const enabledChunkLoadingTypes =
|
|
346
|
-
/** @type {NonNullable<WebpackOptions["output"]["enabledChunkLoadingTypes"]>} */
|
|
347
|
-
(options.output.enabledChunkLoadingTypes);
|
|
345
|
+
const enabledChunkLoadingTypes = options.output.enabledChunkLoadingTypes;
|
|
348
346
|
|
|
349
347
|
if (enabledChunkLoadingTypes.length > 0) {
|
|
350
348
|
for (const type of enabledChunkLoadingTypes) {
|
|
@@ -354,9 +352,7 @@ class WebpackOptionsApply extends OptionsApply {
|
|
|
354
352
|
}
|
|
355
353
|
}
|
|
356
354
|
|
|
357
|
-
const enabledWasmLoadingTypes =
|
|
358
|
-
/** @type {NonNullable<WebpackOptions["output"]["enabledWasmLoadingTypes"]>} */
|
|
359
|
-
(options.output.enabledWasmLoadingTypes);
|
|
355
|
+
const enabledWasmLoadingTypes = options.output.enabledWasmLoadingTypes;
|
|
360
356
|
|
|
361
357
|
if (enabledWasmLoadingTypes.length > 0) {
|
|
362
358
|
for (const type of enabledWasmLoadingTypes) {
|
|
@@ -366,9 +362,7 @@ class WebpackOptionsApply extends OptionsApply {
|
|
|
366
362
|
}
|
|
367
363
|
}
|
|
368
364
|
|
|
369
|
-
const enabledLibraryTypes =
|
|
370
|
-
/** @type {NonNullable<WebpackOptions["output"]["enabledLibraryTypes"]>} */
|
|
371
|
-
(options.output.enabledLibraryTypes);
|
|
365
|
+
const enabledLibraryTypes = options.output.enabledLibraryTypes;
|
|
372
366
|
|
|
373
367
|
if (enabledLibraryTypes.length > 0) {
|
|
374
368
|
let once = true;
|
|
@@ -755,9 +749,7 @@ class WebpackOptionsApply extends OptionsApply {
|
|
|
755
749
|
hashFunction:
|
|
756
750
|
/** @type {NonNullable<WebpackOptions["output"]["hashFunction"]>} */
|
|
757
751
|
(options.output.hashFunction),
|
|
758
|
-
hashDigest:
|
|
759
|
-
/** @type {NonNullable<WebpackOptions["output"]["hashDigest"]>} */
|
|
760
|
-
(options.output.hashDigest),
|
|
752
|
+
hashDigest: options.output.hashDigest,
|
|
761
753
|
onDemand: !options.optimization.realContentHash
|
|
762
754
|
}).apply(compiler);
|
|
763
755
|
}
|
|
@@ -1115,26 +1107,14 @@ class WebpackOptionsApply extends OptionsApply {
|
|
|
1115
1107
|
} = require("../util/globUtils");
|
|
1116
1108
|
|
|
1117
1109
|
return compileRelativeGlobPaths(paths, (pattern) =>
|
|
1118
|
-
createPathGlobPrefixRegExp(
|
|
1119
|
-
pattern,
|
|
1120
|
-
/** @type {string} */ (options.context)
|
|
1121
|
-
)
|
|
1110
|
+
createPathGlobPrefixRegExp(pattern, options.context)
|
|
1122
1111
|
);
|
|
1123
1112
|
};
|
|
1124
1113
|
const snapshotOptions = {
|
|
1125
1114
|
...options.snapshot,
|
|
1126
|
-
managedPaths: compileSnapshotPaths(
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
),
|
|
1130
|
-
immutablePaths: compileSnapshotPaths(
|
|
1131
|
-
/** @type {NonNullable<WebpackOptions["snapshot"]["immutablePaths"]>} */
|
|
1132
|
-
(options.snapshot.immutablePaths)
|
|
1133
|
-
),
|
|
1134
|
-
unmanagedPaths: compileSnapshotPaths(
|
|
1135
|
-
/** @type {NonNullable<WebpackOptions["snapshot"]["unmanagedPaths"]>} */
|
|
1136
|
-
(options.snapshot.unmanagedPaths)
|
|
1137
|
-
)
|
|
1115
|
+
managedPaths: compileSnapshotPaths(options.snapshot.managedPaths),
|
|
1116
|
+
immutablePaths: compileSnapshotPaths(options.snapshot.immutablePaths),
|
|
1117
|
+
unmanagedPaths: compileSnapshotPaths(options.snapshot.unmanagedPaths)
|
|
1138
1118
|
};
|
|
1139
1119
|
|
|
1140
1120
|
new AddManagedPathsPlugin(
|
package/lib/config/cli.js
CHANGED
|
@@ -229,8 +229,10 @@ const getArguments = (schema = webpackSchema) => {
|
|
|
229
229
|
description: undefined,
|
|
230
230
|
simpleType:
|
|
231
231
|
/** @type {SimpleType} */
|
|
232
|
-
(/** @type {
|
|
233
|
-
multiple: /** @type {boolean} */ (
|
|
232
|
+
(/** @type {SimpleType | undefined} */ (undefined)),
|
|
233
|
+
multiple: /** @type {boolean} */ (
|
|
234
|
+
/** @type {boolean | undefined} */ (undefined)
|
|
235
|
+
)
|
|
234
236
|
};
|
|
235
237
|
};
|
|
236
238
|
|
|
@@ -278,8 +280,10 @@ const getArguments = (schema = webpackSchema) => {
|
|
|
278
280
|
description: undefined,
|
|
279
281
|
simpleType:
|
|
280
282
|
/** @type {SimpleType} */
|
|
281
|
-
(/** @type {
|
|
282
|
-
multiple: /** @type {boolean} */ (
|
|
283
|
+
(/** @type {SimpleType | undefined} */ (undefined)),
|
|
284
|
+
multiple: /** @type {boolean} */ (
|
|
285
|
+
/** @type {boolean | undefined} */ (undefined)
|
|
286
|
+
)
|
|
283
287
|
};
|
|
284
288
|
}
|
|
285
289
|
|
|
@@ -440,8 +444,7 @@ const getArguments = (schema = webpackSchema) => {
|
|
|
440
444
|
|
|
441
445
|
for (let i = 0; i < items.length; i++) {
|
|
442
446
|
addedArguments += traverse(
|
|
443
|
-
|
|
444
|
-
(items[i]),
|
|
447
|
+
items[i],
|
|
445
448
|
schemaPath,
|
|
446
449
|
fullPath,
|
|
447
450
|
inArray,
|
package/lib/config/defaults.js
CHANGED
|
@@ -87,6 +87,8 @@ const {
|
|
|
87
87
|
*/
|
|
88
88
|
/** @import { WasmLoadingTypes } from "../wasm/EnableWasmLoadingPlugin" */
|
|
89
89
|
/** @import { PlatformTargetProperties, TargetProperties } from "./target" */
|
|
90
|
+
/** @import Compiler from "../Compiler" */
|
|
91
|
+
/** @typedef {Parameters<import("minimizer-webpack-plugin")["apply"]>[0]} MinimizerCompiler */
|
|
90
92
|
|
|
91
93
|
/**
|
|
92
94
|
* Defines the recursive non nullable type used by this module.
|
|
@@ -279,18 +281,20 @@ const A = (obj, prop, factory) => {
|
|
|
279
281
|
if (value === undefined) {
|
|
280
282
|
obj[prop] = factory();
|
|
281
283
|
} else if (Array.isArray(value)) {
|
|
282
|
-
/** @type {
|
|
284
|
+
/** @type {(T[P] extends (infer E)[] ? E : never)[] | undefined} */
|
|
283
285
|
let newArray;
|
|
284
286
|
for (let i = 0; i < value.length; i++) {
|
|
285
287
|
const item = value[i];
|
|
286
288
|
if (item === "...") {
|
|
287
289
|
if (newArray === undefined) {
|
|
288
290
|
newArray = value.slice(0, i);
|
|
289
|
-
obj[prop] = /** @type {T[P]} */ (
|
|
291
|
+
obj[prop] = /** @type {T[P]} */ (
|
|
292
|
+
/** @type {T[P] | NonNullable<typeof newArray>} */ (newArray)
|
|
293
|
+
);
|
|
290
294
|
}
|
|
291
295
|
const items =
|
|
292
|
-
/** @type {
|
|
293
|
-
(/** @type {
|
|
296
|
+
/** @type {NonNullable<typeof newArray>} */
|
|
297
|
+
(/** @type {T[P] | NonNullable<typeof newArray>} */ (factory()));
|
|
294
298
|
if (items !== undefined) {
|
|
295
299
|
for (const item of items) {
|
|
296
300
|
newArray.push(item);
|
|
@@ -1708,7 +1712,7 @@ const applyOutputDefaults = (
|
|
|
1708
1712
|
)
|
|
1709
1713
|
);
|
|
1710
1714
|
|
|
1711
|
-
const environment =
|
|
1715
|
+
const environment = output.environment;
|
|
1712
1716
|
/**
|
|
1713
1717
|
* Returns true, when v is truthy or undefined.
|
|
1714
1718
|
* @param {boolean | undefined} v value
|
|
@@ -2498,13 +2502,12 @@ const applyOptimizationDefaults = (
|
|
|
2498
2502
|
D(optimization, "realContentHash", production);
|
|
2499
2503
|
// A plugin assigning the object shorthand in `apply()` runs after
|
|
2500
2504
|
// normalization: it replaces `minimizeOptions`, keeping `minimize` boolean.
|
|
2501
|
-
const minimizeAssignedInApply =
|
|
2502
|
-
|
|
2503
|
-
|
|
2504
|
-
if (typeof minimizeAssignedInApply === "object") {
|
|
2505
|
-
optimization.minimizeOptions = /** @type {OptimizationMinimizeOptions} */ (
|
|
2506
|
-
minimizeAssignedInApply
|
|
2505
|
+
const minimizeAssignedInApply =
|
|
2506
|
+
/** @type {Optimization["minimize"] | OptimizationMinimizeOptions} */ (
|
|
2507
|
+
optimization.minimize
|
|
2507
2508
|
);
|
|
2509
|
+
if (typeof minimizeAssignedInApply === "object") {
|
|
2510
|
+
optimization.minimizeOptions = minimizeAssignedInApply;
|
|
2508
2511
|
optimization.minimize = true;
|
|
2509
2512
|
}
|
|
2510
2513
|
D(optimization, "minimize", production);
|
|
@@ -2613,7 +2616,11 @@ const applyOptimizationDefaults = (
|
|
|
2613
2616
|
test: assetNameTest(["[cm]?js"]),
|
|
2614
2617
|
minify: javascriptMinify,
|
|
2615
2618
|
minimizerOptions: javascriptOptions
|
|
2616
|
-
}).apply(
|
|
2619
|
+
}).apply(
|
|
2620
|
+
/** @type {MinimizerCompiler} */ (
|
|
2621
|
+
/** @type {Compiler | MinimizerCompiler} */ (compiler)
|
|
2622
|
+
)
|
|
2623
|
+
);
|
|
2617
2624
|
return;
|
|
2618
2625
|
}
|
|
2619
2626
|
/** @type {(typeof javascriptMinify | string)[]} */
|
|
@@ -2703,7 +2710,11 @@ const applyOptimizationDefaults = (
|
|
|
2703
2710
|
test: assetNameTest(extensions),
|
|
2704
2711
|
minify,
|
|
2705
2712
|
minimizerOptions
|
|
2706
|
-
}).apply(
|
|
2713
|
+
}).apply(
|
|
2714
|
+
/** @type {MinimizerCompiler} */ (
|
|
2715
|
+
/** @type {Compiler | MinimizerCompiler} */ (compiler)
|
|
2716
|
+
)
|
|
2717
|
+
);
|
|
2707
2718
|
}
|
|
2708
2719
|
}
|
|
2709
2720
|
]);
|
|
@@ -9,10 +9,10 @@ const { matchObject } = require("../devtool/ModuleFilenameHelpers");
|
|
|
9
9
|
|
|
10
10
|
/** @import Compiler from "../Compiler" */
|
|
11
11
|
/** @import { MatchObject } from "../devtool/ModuleFilenameHelpers" */
|
|
12
|
-
/** @typedef {MatchObject & { minimizer?: import("minimizer-webpack-plugin").InternalPluginOptions<
|
|
12
|
+
/** @typedef {MatchObject & { minimizer?: import("minimizer-webpack-plugin").InternalPluginOptions<import("terser").MinifyOptions>["minimizer"] }} MinimizerOptions */
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
|
-
* @param {
|
|
15
|
+
* @param {NonNullable<Compiler["options"]["optimization"]["minimizer"]>[number] | Compiler["options"]["plugins"][number]} candidate a configured plugin or minimizer entry
|
|
16
16
|
* @param {string} file probe filename
|
|
17
17
|
* @returns {boolean} whether the candidate minimizes that file
|
|
18
18
|
*/
|
package/lib/config/target.js
CHANGED
|
@@ -120,7 +120,7 @@ const getDefaultTarget = (context) => {
|
|
|
120
120
|
*/
|
|
121
121
|
const versionDependent = (major, minor) => {
|
|
122
122
|
if (!major) {
|
|
123
|
-
return () =>
|
|
123
|
+
return () => undefined;
|
|
124
124
|
}
|
|
125
125
|
/** @type {number} */
|
|
126
126
|
const nMajor = Number(major);
|
|
@@ -659,7 +659,7 @@ class ContextModule extends Module {
|
|
|
659
659
|
snapshotOptions,
|
|
660
660
|
(err, snapshot) => {
|
|
661
661
|
if (err) return callback(err);
|
|
662
|
-
/** @type {
|
|
662
|
+
/** @type {ContextModuleBuildInfo} */
|
|
663
663
|
(this.buildInfo).snapshot = snapshot;
|
|
664
664
|
callback();
|
|
665
665
|
}
|
|
@@ -82,17 +82,11 @@ class ContextReplacementPlugin {
|
|
|
82
82
|
newContentRecursive = undefined;
|
|
83
83
|
}
|
|
84
84
|
// new webpack.ContextReplacementPlugin(/selector/, './folder', false, /selector/);
|
|
85
|
-
this.newContentResource =
|
|
86
|
-
/** @type {string | undefined} */
|
|
87
|
-
(newContentResource);
|
|
85
|
+
this.newContentResource = newContentResource;
|
|
88
86
|
/** @type {boolean | undefined} */
|
|
89
|
-
this.newContentRecursive =
|
|
90
|
-
/** @type {boolean | undefined} */
|
|
91
|
-
(newContentRecursive);
|
|
87
|
+
this.newContentRecursive = newContentRecursive;
|
|
92
88
|
/** @type {RegExp | undefined} */
|
|
93
|
-
this.newContentRegExp =
|
|
94
|
-
/** @type {RegExp | undefined} */
|
|
95
|
-
(newContentRegExp);
|
|
89
|
+
this.newContentRegExp = newContentRegExp;
|
|
96
90
|
}
|
|
97
91
|
}
|
|
98
92
|
|
package/lib/css/CssGenerator.js
CHANGED
|
@@ -49,6 +49,7 @@ const CSS_TYPE_PREFIX = `${CSS_TYPE}/`;
|
|
|
49
49
|
|
|
50
50
|
const URL_SCHEME_REGEXP = /^(?:data|https?):/;
|
|
51
51
|
|
|
52
|
+
/** @import CssModule, { BuiltCssModule, CssNormalModule } from "./CssModule" */
|
|
52
53
|
/** @import { Source, RawSourceMap } from "webpack-sources" */
|
|
53
54
|
/**
|
|
54
55
|
* @import {
|
|
@@ -77,12 +78,6 @@ const URL_SCHEME_REGEXP = /^(?:data|https?):/;
|
|
|
77
78
|
/** @import NormalModule from "../module/NormalModule" */
|
|
78
79
|
/** @import Hash from "../util/Hash" */
|
|
79
80
|
/** @import { ModuleFactoryCacheEntry } from "./CssModulesPlugin" */
|
|
80
|
-
/**
|
|
81
|
-
* @import CssModule, {
|
|
82
|
-
* CssModuleBuildInfo,
|
|
83
|
-
* CssModuleBuildMeta
|
|
84
|
-
* } from "./CssModule"
|
|
85
|
-
*/
|
|
86
81
|
|
|
87
82
|
/** @typedef {{ line: number, column: number }} SourcePosition */
|
|
88
83
|
/** @typedef {Map<string, SourcePosition>} ExportLocsMap */
|
|
@@ -152,6 +147,14 @@ const buildExportsSourceMap = (
|
|
|
152
147
|
};
|
|
153
148
|
};
|
|
154
149
|
|
|
150
|
+
/**
|
|
151
|
+
* The module type the JSDoc inherited from `Generator` names.
|
|
152
|
+
* @typedef {CssNormalModule} TModule
|
|
153
|
+
*/
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* @extends {Generator<TModule>}
|
|
157
|
+
*/
|
|
155
158
|
class CssGenerator extends Generator {
|
|
156
159
|
/**
|
|
157
160
|
* Creates an instance of CssGenerator.
|
|
@@ -189,7 +192,7 @@ class CssGenerator extends Generator {
|
|
|
189
192
|
|
|
190
193
|
/**
|
|
191
194
|
* Returns the reason this module cannot be concatenated, when one exists.
|
|
192
|
-
* @param {
|
|
195
|
+
* @param {TModule} module module for which the bailout reason should be determined
|
|
193
196
|
* @param {ConcatenationBailoutReasonContext} context context
|
|
194
197
|
* @returns {string | undefined} reason why this module can't be concatenated, undefined when it can be concatenated
|
|
195
198
|
*/
|
|
@@ -224,7 +227,7 @@ class CssGenerator extends Generator {
|
|
|
224
227
|
|
|
225
228
|
/**
|
|
226
229
|
* Processes the provided module.
|
|
227
|
-
* @param {
|
|
230
|
+
* @param {TModule} module the module to generate
|
|
228
231
|
* @param {InitFragment<GenerateContext>[]} initFragments mutable list of init fragments
|
|
229
232
|
* @param {ReplaceSource} source the current replace source which can be modified
|
|
230
233
|
* @param {GenerateContext & { cssData: CssData }} generateContext the generateContext
|
|
@@ -233,7 +236,7 @@ class CssGenerator extends Generator {
|
|
|
233
236
|
sourceModule(module, initFragments, source, generateContext) {
|
|
234
237
|
// Only `dependency` varies across `template.apply` calls, so one context
|
|
235
238
|
// (and one lazy `chunkInitFragments` getter) serves the whole module.
|
|
236
|
-
/** @type {InitFragment<
|
|
239
|
+
/** @type {InitFragment<import("../javascript/JavascriptModulesPlugin").ChunkRenderContext>[] | undefined} */
|
|
237
240
|
let chunkInitFragments;
|
|
238
241
|
/** @type {CssDependencyTemplateContext} */
|
|
239
242
|
const templateContext = {
|
|
@@ -280,12 +283,13 @@ class CssGenerator extends Generator {
|
|
|
280
283
|
|
|
281
284
|
/**
|
|
282
285
|
* Generates generated code for this runtime module.
|
|
283
|
-
* @param {
|
|
286
|
+
* @param {TModule} module module for which the code should be generated
|
|
284
287
|
* @param {GenerateContext} generateContext context for generate
|
|
285
288
|
* @returns {Source | null} generated code
|
|
286
289
|
*/
|
|
287
290
|
generate(module, generateContext) {
|
|
288
291
|
const exportType = /** @type {CssModule} */ (module).exportType || "link";
|
|
292
|
+
const { buildInfo, buildMeta } = /** @type {BuiltCssModule} */ (module);
|
|
289
293
|
const source =
|
|
290
294
|
generateContext.type === JAVASCRIPT_TYPE && exportType === "link"
|
|
291
295
|
? new ReplaceSource(new RawSource(""))
|
|
@@ -314,8 +318,7 @@ class CssGenerator extends Generator {
|
|
|
314
318
|
case JAVASCRIPT_TYPE: {
|
|
315
319
|
const compilation = generateContext.runtimeTemplate.compilation;
|
|
316
320
|
const devtool = compilation.options.devtool;
|
|
317
|
-
const isCssModule =
|
|
318
|
-
.isCssModule;
|
|
321
|
+
const isCssModule = buildMeta.isCssModule;
|
|
319
322
|
|
|
320
323
|
const generateContentCode = () => {
|
|
321
324
|
switch (exportType) {
|
|
@@ -412,8 +415,7 @@ class CssGenerator extends Generator {
|
|
|
412
415
|
/** @type {Source | null} */
|
|
413
416
|
const defaultExport = generateJSDefaultExport();
|
|
414
417
|
|
|
415
|
-
|
|
416
|
-
(module.buildInfo).cssData = cssData;
|
|
418
|
+
buildInfo.cssData = cssData;
|
|
417
419
|
|
|
418
420
|
// Required for HMR
|
|
419
421
|
if (module.hot) {
|
|
@@ -575,7 +577,7 @@ class CssGenerator extends Generator {
|
|
|
575
577
|
// `SourceMapDevToolPlugin` can match the module and apply the
|
|
576
578
|
// devtool filename template instead of leaking this raw name
|
|
577
579
|
const sourceName = contextifySourceUrl(
|
|
578
|
-
|
|
580
|
+
compilation.options.context,
|
|
579
581
|
module.identifier(),
|
|
580
582
|
compilation.compiler.root
|
|
581
583
|
);
|
|
@@ -611,7 +613,7 @@ class CssGenerator extends Generator {
|
|
|
611
613
|
/**
|
|
612
614
|
* Generates fallback output for the provided error condition.
|
|
613
615
|
* @param {Error} error the error
|
|
614
|
-
* @param {
|
|
616
|
+
* @param {TModule} module module for which the code should be generated
|
|
615
617
|
* @param {GenerateContext} generateContext context for generate
|
|
616
618
|
* @returns {Source | null} generated code
|
|
617
619
|
*/
|
|
@@ -641,7 +643,7 @@ class CssGenerator extends Generator {
|
|
|
641
643
|
|
|
642
644
|
/**
|
|
643
645
|
* Returns the source types available for this module.
|
|
644
|
-
* @param {
|
|
646
|
+
* @param {TModule} module fresh module
|
|
645
647
|
* @returns {SourceTypes} available types (do not mutate)
|
|
646
648
|
*/
|
|
647
649
|
getTypes(module) {
|
|
@@ -730,22 +732,20 @@ class CssGenerator extends Generator {
|
|
|
730
732
|
|
|
731
733
|
/**
|
|
732
734
|
* Returns the estimated size for the requested source type.
|
|
733
|
-
* @param {
|
|
735
|
+
* @param {TModule} module the module
|
|
734
736
|
* @param {SourceType=} type source type
|
|
735
737
|
* @returns {number} estimate size of the module
|
|
736
738
|
*/
|
|
737
739
|
getSize(module, type) {
|
|
738
740
|
switch (type) {
|
|
739
741
|
case JAVASCRIPT_TYPE: {
|
|
740
|
-
const
|
|
741
|
-
|
|
742
|
+
const { buildInfo, buildMeta } = /** @type {BuiltCssModule} */ (module);
|
|
743
|
+
const cssData = buildInfo.cssData;
|
|
742
744
|
if (!cssData) {
|
|
743
745
|
return 42;
|
|
744
746
|
}
|
|
745
747
|
if (cssData.exports.size === 0) {
|
|
746
|
-
if (
|
|
747
|
-
/** @type {CssModuleBuildMeta} */ (module.buildMeta).isCssModule
|
|
748
|
-
) {
|
|
748
|
+
if (buildMeta.isCssModule) {
|
|
749
749
|
return 42;
|
|
750
750
|
}
|
|
751
751
|
return 0;
|
|
@@ -778,7 +778,7 @@ class CssGenerator extends Generator {
|
|
|
778
778
|
/**
|
|
779
779
|
* Updates the hash with the data contributed by this instance.
|
|
780
780
|
* @param {Hash} hash hash that will be modified
|
|
781
|
-
* @param {UpdateHashContext} updateHashContext context for updating hash
|
|
781
|
+
* @param {UpdateHashContext<TModule>} updateHashContext context for updating hash
|
|
782
782
|
*/
|
|
783
783
|
updateHash(hash, { module, runtimeTemplate }) {
|
|
784
784
|
hash.update(/** @type {boolean} */ (this._esModule).toString());
|
|
@@ -805,7 +805,7 @@ class CssGenerator extends Generator {
|
|
|
805
805
|
|
|
806
806
|
/**
|
|
807
807
|
* Resolve the effective `@charset` by walking text imports.
|
|
808
|
-
* @param {
|
|
808
|
+
* @param {TModule} module the module
|
|
809
809
|
* @param {ModuleGraph} moduleGraph module graph
|
|
810
810
|
* @param {WeakSet<NormalModule>=} visited cycle guard
|
|
811
811
|
* @returns {string | undefined} the effective charset
|
|
@@ -817,14 +817,12 @@ class CssGenerator extends Generator {
|
|
|
817
817
|
return undefined;
|
|
818
818
|
}
|
|
819
819
|
visited.add(module);
|
|
820
|
-
const own =
|
|
821
|
-
module.buildInfo &&
|
|
822
|
-
/** @type {CssModuleBuildInfo} */ (module.buildInfo).charset;
|
|
820
|
+
const own = module.buildInfo && module.buildInfo.charset;
|
|
823
821
|
if (own !== undefined) return own;
|
|
824
822
|
if (exportType !== "text") return undefined;
|
|
825
823
|
for (const dep of module.dependencies) {
|
|
826
824
|
if (isDependencyKind(dep, "css-import")) {
|
|
827
|
-
const depModule = /** @type {
|
|
825
|
+
const depModule = /** @type {BuiltCssModule} */ (
|
|
828
826
|
moduleGraph.getModule(dep)
|
|
829
827
|
);
|
|
830
828
|
const inherited = this._getEffectiveCharset(
|
|
@@ -840,7 +838,7 @@ class CssGenerator extends Generator {
|
|
|
840
838
|
|
|
841
839
|
/**
|
|
842
840
|
* Generate JS expressions for `@import` side effects (`style` exportType only).
|
|
843
|
-
* @param {
|
|
841
|
+
* @param {TModule} module the module to generate CSS text for
|
|
844
842
|
* @param {GenerateContext} generateContext the generate context
|
|
845
843
|
* @returns {string[]} JS expressions, one per `@import` dependency
|
|
846
844
|
*/
|
|
@@ -850,7 +848,10 @@ class CssGenerator extends Generator {
|
|
|
850
848
|
|
|
851
849
|
for (const dep of module.dependencies) {
|
|
852
850
|
if (!isDependencyKind(dep, "css-import")) continue;
|
|
853
|
-
const depModule = /** @type {CssModule} */ (
|
|
851
|
+
const depModule = /** @type {CssModule & BuiltCssModule} */ (
|
|
852
|
+
moduleGraph.getModule(dep)
|
|
853
|
+
);
|
|
854
|
+
if (!depModule) continue;
|
|
854
855
|
if (concatenationScope && concatenationScope.isModuleInScope(depModule)) {
|
|
855
856
|
continue;
|
|
856
857
|
}
|
|
@@ -870,7 +871,7 @@ class CssGenerator extends Generator {
|
|
|
870
871
|
|
|
871
872
|
/**
|
|
872
873
|
* Recursively merge `@import`'d CSS into a single Source (text/css-style-sheet only).
|
|
873
|
-
* @param {
|
|
874
|
+
* @param {TModule} module the module to render
|
|
874
875
|
* @param {GenerateContext} generateContext the generate context
|
|
875
876
|
* @param {Set<NormalModule>} ancestors modules on the current path (cycle guard)
|
|
876
877
|
* @returns {Source | null} merged CSS source, or null when the module has no content
|
|
@@ -885,7 +886,9 @@ class CssGenerator extends Generator {
|
|
|
885
886
|
|
|
886
887
|
for (const dep of module.dependencies) {
|
|
887
888
|
if (!isDependencyKind(dep, "css-import")) continue;
|
|
888
|
-
const depModule = /** @type {CssModule} */ (
|
|
889
|
+
const depModule = /** @type {CssModule & BuiltCssModule} */ (
|
|
890
|
+
moduleGraph.getModule(dep)
|
|
891
|
+
);
|
|
889
892
|
if (!depModule) continue;
|
|
890
893
|
const depExportType = depModule.exportType;
|
|
891
894
|
if (depExportType !== "text" && depExportType !== "css-style-sheet") {
|
|
@@ -912,7 +915,7 @@ class CssGenerator extends Generator {
|
|
|
912
915
|
|
|
913
916
|
/**
|
|
914
917
|
* Generate CSS source for the current module
|
|
915
|
-
* @param {
|
|
918
|
+
* @param {TModule} module the module to generate CSS source for
|
|
916
919
|
* @param {GenerateContext} generateContext the generate context
|
|
917
920
|
* @returns {Source | null} the CSS source
|
|
918
921
|
*/
|
|
@@ -957,7 +960,7 @@ class CssGenerator extends Generator {
|
|
|
957
960
|
const { compilation } = runtimeTemplate;
|
|
958
961
|
const outputOptions = compilation.outputOptions;
|
|
959
962
|
const absolutify = makePathsAbsolute.bindContextCache(
|
|
960
|
-
|
|
963
|
+
compilation.options.context,
|
|
961
964
|
compilation.compiler.root
|
|
962
965
|
);
|
|
963
966
|
const options = {
|
|
@@ -1013,7 +1016,7 @@ class CssGenerator extends Generator {
|
|
|
1013
1016
|
* Offer CSS bound for a JS string literal to `renderEmbeddedSource`. No `.css`
|
|
1014
1017
|
* asset carries this text, so an asset-level minimizer never sees it.
|
|
1015
1018
|
* @param {Source} cssSource the CSS source
|
|
1016
|
-
* @param {
|
|
1019
|
+
* @param {TModule} module the module
|
|
1017
1020
|
* @param {GenerateContext} generateContext the generate context
|
|
1018
1021
|
* @returns {Source} the source a tap returned, or the original
|
|
1019
1022
|
*/
|
|
@@ -1077,7 +1080,7 @@ class CssGenerator extends Generator {
|
|
|
1077
1080
|
/**
|
|
1078
1081
|
* Generate the merged CSS text for a module, optionally wrapped as a
|
|
1079
1082
|
* JS string literal for embedding in JavaScript output.
|
|
1080
|
-
* @param {
|
|
1083
|
+
* @param {TModule} module the module
|
|
1081
1084
|
* @param {GenerateContext} generateContext the generate context
|
|
1082
1085
|
* @param {boolean} asJsLiteral wrap the result as a JS string literal
|
|
1083
1086
|
* @returns {Source} the CSS text source
|
package/lib/css/CssModule.js
CHANGED
|
@@ -47,6 +47,16 @@ const makeSerializable = require("../util/makeSerializable");
|
|
|
47
47
|
|
|
48
48
|
/** @typedef {BuildMeta & KnownCssModuleBuildMeta} CssModuleBuildMeta */
|
|
49
49
|
|
|
50
|
+
/**
|
|
51
|
+
* A css module before or after its build, typed with its build info and build meta.
|
|
52
|
+
* @typedef {NormalModule & { buildInfo?: CssModuleBuildInfo, buildMeta?: CssModuleBuildMeta }} CssNormalModule
|
|
53
|
+
*/
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* A built css module, typed with its build info and build meta.
|
|
57
|
+
* @typedef {NormalModule & { buildInfo: CssModuleBuildInfo, buildMeta: CssModuleBuildMeta }} BuiltCssModule
|
|
58
|
+
*/
|
|
59
|
+
|
|
50
60
|
class CssModule extends NormalModule {
|
|
51
61
|
/**
|
|
52
62
|
* Creates an instance of CssModule.
|