@depup/webpack 5.110.1-depup.0 → 5.111.1-depup.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -8
- package/changes.json +7 -11
- package/lib/APIPlugin.js +26 -11
- package/lib/AutomaticPrefetchPlugin.js +1 -1
- package/lib/Cache.js +8 -3
- package/lib/CacheFacade.js +1 -1
- package/lib/ChunkGraph.js +20 -18
- package/lib/CircularModulesPlugin.js +157 -55
- package/lib/CleanPlugin.js +2 -2
- package/lib/CompatibilityPlugin.js +3 -4
- package/lib/Compilation.js +337 -338
- package/lib/Compiler.js +213 -51
- package/lib/ConcatenationScope.js +25 -35
- package/lib/ConstPlugin.js +16 -132
- package/lib/CopyPlugin.js +1054 -0
- package/lib/DefinePlugin.js +24 -8
- package/lib/DependencyTemplate.js +2 -1
- package/lib/DotenvPlugin.js +64 -40
- package/lib/ErrorHelpers.js +113 -0
- package/lib/ExportsInfo.js +30 -16
- package/lib/ExternalModule.js +47 -22
- package/lib/FileSystemInfo.js +17 -14
- package/lib/FlagDependencyExportsPlugin.js +53 -34
- package/lib/FlagDependencyUsagePlugin.js +17 -15
- package/lib/Generator.js +24 -2
- package/lib/HotModuleReplacementPlugin.js +55 -7
- package/lib/IgnorePlugin.js +1 -1
- package/lib/JavascriptMetaInfoPlugin.js +5 -3
- package/lib/LoaderOptionsPlugin.js +1 -1
- package/lib/MainTemplate.js +5 -1
- package/lib/Module.js +19 -10
- package/lib/ModuleGraph.js +6 -9
- package/lib/MultiCompiler.js +7 -17
- package/lib/MultiWatching.js +1 -1
- package/lib/NormalModule.js +148 -70
- package/lib/NormalModuleFactory.js +1 -1
- package/lib/RuntimeGlobals.js +21 -7
- package/lib/RuntimeModule.js +28 -12
- package/lib/RuntimePlugin.js +33 -3
- package/lib/RuntimeTemplate.js +1147 -847
- package/lib/SourceMapDevToolPlugin.js +54 -104
- package/lib/TemplatedPathPlugin.js +16 -59
- package/lib/Watching.js +9 -0
- package/lib/WebpackOptionsApply.js +84 -91
- package/lib/asset/AssetBytesGenerator.js +7 -1
- package/lib/asset/AssetGenerator.js +50 -24
- package/lib/asset/AssetModule.js +3 -0
- package/lib/asset/AssetSourceGenerator.js +7 -1
- package/lib/asset/WebManifestParser.js +7 -5
- package/lib/async-modules/AsyncModuleHelpers.js +10 -4
- package/lib/buildChunkGraph.js +11 -15
- package/lib/cache/AddBuildDependenciesPlugin.js +33 -4
- package/lib/cache/IdleFileCachePlugin.js +2 -2
- package/lib/cache/MemoryCachePlugin.js +4 -4
- package/lib/cache/MemoryWithGcCachePlugin.js +7 -8
- package/lib/cache/PackFileCacheStrategy.js +17 -19
- package/lib/cache/getLazyHashedEtag.js +3 -5
- package/lib/config/browserslistTargetHandler.js +17 -4
- package/lib/config/defaults.js +162 -142
- package/lib/config/getClaimedAssetTypes.js +10 -11
- package/lib/config/normalization.js +100 -20
- package/lib/config/target.js +13 -4
- package/lib/container/ContainerReferencePlugin.js +6 -0
- package/lib/container/RemoteRuntimeModule.js +9 -0
- package/lib/container/declaredRemotes.js +39 -0
- package/lib/{ContextExclusionPlugin.js → context/ContextExclusionPlugin.js} +1 -1
- package/lib/{ContextModule.js → context/ContextModule.js} +54 -115
- package/lib/{ContextModuleFactory.js → context/ContextModuleFactory.js} +19 -21
- package/lib/{ContextReplacementPlugin.js → context/ContextReplacementPlugin.js} +4 -4
- package/lib/css/CssGenerator.js +27 -11
- package/lib/css/CssInjectStyleRuntimeModule.js +9 -0
- package/lib/css/CssLoadingRuntimeModule.js +92 -15
- package/lib/css/CssModule.js +1 -1
- package/lib/css/CssModulesPlugin.js +3 -10
- package/lib/css/CssParser.js +162 -31
- package/lib/css/CssServerStylesRuntimeModule.js +9 -0
- package/lib/css/cssMinify.js +43 -32
- package/lib/css/data.js +3526 -871
- package/lib/css/syntax.js +6455 -1237
- package/lib/debug/ProfilingPlugin.js +7 -4
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +6 -3
- package/lib/dependencies/AMDRuntimeModules.js +18 -0
- package/lib/dependencies/CommonJsExportRequireDependency.js +13 -12
- package/lib/dependencies/CommonJsExportsParserPlugin.js +12 -13
- package/lib/dependencies/CommonJsImportsParserPlugin.js +5 -5
- package/lib/dependencies/CommonJsPlugin.js +19 -3
- package/lib/dependencies/CommonJsRequireDependency.js +32 -9
- package/lib/dependencies/CommonJsSelfReferenceDependency.js +2 -4
- package/lib/dependencies/ContextDependency.js +1 -1
- package/lib/dependencies/ContextDependencyHelpers.js +3 -9
- package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +20 -7
- package/lib/dependencies/ContextElementDependency.js +1 -1
- package/lib/dependencies/CssIcssExportDependency.js +13 -9
- package/lib/dependencies/CssIcssImportDependency.js +3 -6
- package/lib/dependencies/CssUrlDependency.js +3 -5
- package/lib/dependencies/HarmonyCompatibilityDependency.js +67 -22
- package/lib/dependencies/HarmonyDetectionParserPlugin.js +3 -4
- package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +10 -4
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +12 -7
- package/lib/dependencies/HarmonyExportExpressionDependency.js +47 -33
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +217 -34
- package/lib/dependencies/HarmonyExportInitFragment.js +110 -23
- package/lib/dependencies/HarmonyExportSpecifierDependency.js +25 -58
- package/lib/dependencies/HarmonyImportBareSideEffectDependency.js +59 -0
- package/lib/dependencies/HarmonyImportDependency.js +99 -41
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +198 -25
- package/lib/dependencies/HarmonyImportSideEffectDependency.js +117 -4
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +40 -3
- package/lib/dependencies/HarmonyModulesPlugin.js +20 -0
- package/lib/dependencies/HtmlEntryDependency.js +136 -104
- package/lib/dependencies/HtmlInlineScriptDependency.js +3 -4
- package/lib/dependencies/HtmlInlineStyleDependency.js +3 -4
- package/lib/dependencies/ImportContextDependency.js +43 -3
- package/lib/dependencies/ImportDependency.js +8 -29
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +1 -1
- package/lib/dependencies/ImportMetaGlobHelpers.js +1 -1
- package/lib/dependencies/ImportMetaMainDependency.js +104 -0
- package/lib/dependencies/ImportMetaPlugin.js +67 -25
- package/lib/dependencies/ImportParserPlugin.js +25 -15
- package/lib/dependencies/LoaderPlugin.js +26 -1
- package/lib/dependencies/RequireContextDependencyParserPlugin.js +1 -1
- package/lib/dependencies/RequireHeaderDependency.js +20 -21
- package/lib/dependencies/SystemRuntimeModule.js +9 -0
- package/lib/dependencies/URLContextDependency.js +1 -1
- package/lib/dependencies/URLDependency.js +6 -5
- package/lib/dependencies/WorkerAndWorkletPlugin.js +16 -21
- package/lib/dependencies/WorkerDependency.js +12 -18
- package/lib/dependencies/WorkletDependency.js +12 -20
- package/lib/dependencies/importOptionsCheck.js +47 -0
- package/lib/dll/DelegatedModule.js +18 -1
- package/lib/dll/DllReferencePlugin.js +11 -8
- package/lib/dll/LibManifestPlugin.js +1 -1
- package/lib/errors/AnalyzableBailoutsWarning.js +41 -0
- package/lib/errors/DotenvFileError.js +29 -0
- package/lib/errors/DuplicateModulesWarning.js +12 -7
- package/lib/errors/EmptyCopyPatternWarning.js +26 -0
- package/lib/errors/ExternalStarReexportError.js +44 -0
- package/lib/errors/HookWebpackError.js +3 -2
- package/lib/errors/ImportedBindingAssignmentError.js +30 -0
- package/lib/errors/MissingSourceMapsWarning.js +36 -0
- package/lib/errors/ModuleParseError.js +2 -1
- package/lib/errors/UnusedAssetsWarning.js +36 -0
- package/lib/errors/UnusedFederationWarning.js +35 -0
- package/lib/errors/UnusedModulesWarning.js +38 -0
- package/lib/esm/ExportWebpackRequireRuntimeModule.js +9 -0
- package/lib/esm/ModuleChunkFormatPlugin.js +28 -3
- package/lib/esm/ModuleChunkLoadingPlugin.js +21 -5
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +91 -53
- package/lib/hmr/HotModuleReplacement.runtime.js +8 -2
- package/lib/hmr/HotModuleReplacementRuntimeModule.js +9 -0
- package/lib/hmr/LazyCompilationPlugin.js +3 -5
- package/lib/html/HtmlGenerator.js +72 -87
- package/lib/html/HtmlModulesPlugin.js +479 -215
- package/lib/html/HtmlParser.js +110 -147
- package/lib/html/builtinEmbeddedRenderer.js +107 -0
- package/lib/html/data.js +142 -7
- package/lib/html/htmlMinify.js +92 -122
- package/lib/html/syntax.js +2031 -1556
- package/lib/ids/HashedModuleIdsPlugin.js +2 -1
- package/lib/index.js +49 -3
- package/lib/javascript/ChunkFormatHelpers.js +4 -3
- package/lib/javascript/JavascriptGenerator.js +8 -1
- package/lib/javascript/JavascriptModule.js +1 -0
- package/lib/javascript/JavascriptModulesPlugin.js +76 -80
- package/lib/javascript/JavascriptParser.js +1970 -900
- package/lib/javascript/StartupHelpers.js +27 -3
- package/lib/javascript/data.js +172 -0
- package/lib/javascript/grammar.js +5546 -0
- package/lib/javascript/parser.js +1500 -0
- package/lib/javascript/regexp.js +1762 -0
- package/lib/javascript/regexpData.js +51 -0
- package/lib/javascript/syntax.js +9061 -5262
- package/lib/json/JsonGenerator.js +7 -1
- package/lib/library/ModuleLibraryPlugin.js +171 -132
- package/lib/loaders/LoaderRunner.js +170 -14
- package/lib/node/NodeWatchFileSystem.js +3 -9
- package/lib/node/ReadFileChunkLoadingRuntimeModule.js +22 -0
- package/lib/node/ReadFileCompileAsyncWasmPlugin.js +8 -15
- package/lib/node/RequireChunkLoadingRuntimeModule.js +22 -0
- package/lib/optimize/AggressiveMergingPlugin.js +3 -5
- package/lib/optimize/ConcatenatedModule.js +222 -125
- package/lib/optimize/ConstExportsPlugin.js +50 -34
- package/lib/optimize/FlagIncludedChunksPlugin.js +3 -11
- package/lib/optimize/InlineExports.js +20 -2
- package/lib/optimize/InnerGraphPlugin.js +7 -13
- package/lib/optimize/LimitChunkCountPlugin.js +5 -8
- package/lib/optimize/MangleExportsPlugin.js +13 -4
- package/lib/optimize/ModuleConcatenationPlugin.js +27 -5
- package/lib/optimize/RealContentHashPlugin.js +179 -44
- package/lib/optimize/SideEffectsFlagPlugin.js +24 -28
- package/lib/optimize/SplitChunksPlugin.js +2 -4
- package/lib/performance/AnalyzableBailoutsPlugin.js +115 -0
- package/lib/performance/BroadContextsPlugin.js +1 -1
- package/lib/performance/CacheEffectivenessPlugin.js +7 -7
- package/lib/performance/DuplicateModulesPlugin.js +57 -13
- package/lib/performance/EvalUsagePlugin.js +5 -2
- package/lib/performance/MissingSourceMapsPlugin.js +115 -0
- package/lib/performance/PureAnnotationsPlugin.js +6 -3
- package/lib/performance/SizeLimitsPlugin.js +2 -4
- package/lib/performance/TopLevelThisPlugin.js +5 -4
- package/lib/performance/UnusedAssetsPlugin.js +109 -0
- package/lib/performance/UnusedFederationPlugin.js +147 -0
- package/lib/performance/UnusedModulesPlugin.js +141 -0
- package/lib/performance/UnusedReexportsPlugin.js +1 -55
- package/lib/performance/isOnlyReexported.js +65 -0
- package/lib/prefetch/ChunkPrefetchFunctionRuntimeModule.js +25 -5
- package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +8 -8
- package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +9 -0
- package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +9 -0
- package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +9 -0
- package/lib/prefetch/ResourceHintPlugin.js +29 -35
- package/lib/prefetch/ResourceHintRuntimeModule.js +9 -0
- package/lib/prefetch/StartupAssetHintRuntimeModule.js +16 -10
- package/lib/rules/RuleSetCompiler.js +211 -4
- package/lib/runtime/AsyncModuleRuntimeModule.js +103 -67
- package/lib/runtime/AutoPublicPathRuntimeModule.js +9 -0
- package/lib/runtime/BaseUriRuntimeModule.js +9 -0
- package/lib/runtime/ChunkNameRuntimeModule.js +9 -0
- package/lib/runtime/EnsureChunkRuntimeModule.js +35 -16
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +12 -4
- package/lib/runtime/GetFullHashRuntimeModule.js +9 -0
- package/lib/runtime/GetMainFilenameRuntimeModule.js +9 -0
- package/lib/runtime/GetWorkletBootstrapRuntimeModule.js +9 -0
- package/lib/runtime/GlobalRuntimeModule.js +11 -4
- package/lib/runtime/HasOwnPropertyRuntimeModule.js +9 -0
- package/lib/runtime/HelperRuntimeModule.js +10 -0
- package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +313 -222
- package/lib/runtime/NonceRuntimeModule.js +9 -0
- package/lib/runtime/OnChunksLoadedRuntimeModule.js +67 -20
- package/lib/runtime/PublicPathRuntimeModule.js +9 -0
- package/lib/runtime/RuntimeIdRuntimeModule.js +9 -0
- package/lib/runtime/SpecNamespaceObjectRuntimeModule.js +90 -0
- package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +9 -0
- package/lib/runtime/StartupEntrypointRuntimeModule.js +9 -0
- package/lib/runtime/SystemContextRuntimeModule.js +9 -0
- package/lib/runtime/ToBinaryRuntimeModule.js +9 -0
- package/lib/schemes/DataUriPlugin.js +3 -6
- package/lib/schemes/HttpUriPlugin.js +22 -5
- package/lib/schemes/VirtualUrlPlugin.js +1 -1
- package/lib/serialization/BinaryMiddleware.js +9 -9
- package/lib/serialization/FileMiddleware.js +31 -18
- package/lib/serialization/ObjectMiddleware.js +168 -139
- package/lib/sharing/ConsumeSharedPlugin.js +12 -0
- package/lib/sharing/ConsumeSharedRuntimeModule.js +11 -0
- package/lib/sharing/ShareRuntimeModule.js +9 -0
- package/lib/sharing/declaredShared.js +47 -0
- package/lib/stats/DefaultStatsFactoryPlugin.js +6 -5
- package/lib/stats/DefaultStatsPrinterPlugin.js +3 -0
- package/lib/typescript/TypeScriptPlugin.js +10 -13
- package/lib/url/URLParserPlugin.js +6 -8
- package/lib/util/ArrayQueue.js +3 -3
- package/lib/util/LocConverter.js +4 -7
- package/lib/util/SourceProcessor.js +115 -99
- package/lib/util/URLAbsoluteSpecifier.js +3 -1
- package/lib/util/async.js +292 -0
- package/lib/util/buildDiagnostics.js +69 -0
- package/lib/util/chainedImports.js +3 -4
- package/lib/util/concatenate.js +4 -4
- package/lib/util/conventions.js +5 -1
- package/lib/util/createHooksRegistry.js +1 -2
- package/lib/util/createMappings.js +25 -3
- package/lib/util/dataURL.js +2 -3
- package/lib/util/deterministicGrouping.js +8 -13
- package/lib/util/findGraphRoots.js +6 -13
- package/lib/util/fs.js +27 -1
- package/lib/util/globUtils.js +1 -1
- package/lib/util/handlerKeys.js +40 -0
- package/lib/util/hash/wasm-hash.js +3 -4
- package/lib/util/identifier.js +20 -0
- package/lib/util/internalSerializables.js +7 -1
- package/lib/util/registerExternalSerializer.js +6 -45
- package/lib/util/removeBOM.js +82 -1
- package/lib/util/semver.js +5 -3
- package/lib/wasm-async/AsyncWasmCompileRuntimeModule.js +14 -3
- package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +14 -3
- package/lib/wasm-async/AsyncWebAssemblyGenerator.js +6 -1
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +5 -1
- package/lib/wasm-async/UniversalCompileAsyncWasmPlugin.js +7 -12
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +12 -4
- package/lib/wasm-sync/WebAssemblyGenerator.js +6 -1
- package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +5 -1
- package/lib/wasm-sync/WebAssemblyUtils.js +2 -4
- package/lib/web/FetchCompileAsyncWasmPlugin.js +10 -6
- package/lib/web/FetchCompileWasmPlugin.js +4 -2
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +36 -0
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +19 -0
- package/package.json +55 -46
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +388 -76
- package/schemas/plugins/LoaderOptionsPlugin.check.js +1 -1
- package/schemas/plugins/ManifestPlugin.check.js +1 -1
- package/schemas/plugins/SourceMapDevToolPlugin.check.js +1 -1
- package/schemas/plugins/asset/AssetGeneratorOptions.check.js +1 -1
- package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.js +1 -1
- package/schemas/plugins/container/ContainerPlugin.check.js +1 -1
- package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
- package/schemas/plugins/debug/ProfilingPlugin.check.js +1 -1
- package/schemas/plugins/dll/DllReferencePlugin.check.js +1 -1
- package/schemas/plugins/ids/HashedModuleIdsPlugin.check.js +1 -1
- package/schemas/plugins/schemes/HttpUriPlugin.check.js +1 -1
- package/types.d.ts +1795 -608
- package/lib/dependencies/ExportBindingInitFragment.js +0 -191
- package/lib/errors/EntrypointOverlapWarning.js +0 -45
- package/lib/performance/EntrypointOverlapPlugin.js +0 -122
package/lib/config/defaults.js
CHANGED
|
@@ -179,6 +179,7 @@ const {
|
|
|
179
179
|
* portableRecords: NonNullable<Optimization["portableRecords"]>,
|
|
180
180
|
* realContentHash: NonNullable<Optimization["realContentHash"]>,
|
|
181
181
|
* minimize: NonNullable<Optimization["minimize"]>,
|
|
182
|
+
* minimizeOptions: NonNullable<Optimization["minimizeOptions"]>,
|
|
182
183
|
* minimizer: NonNullable<Exclude<Optimization["minimizer"], "...">>,
|
|
183
184
|
* nodeEnv: NonNullable<Optimization["nodeEnv"]>,
|
|
184
185
|
* }} OptimizationNormalizedWithDefaults
|
|
@@ -302,6 +303,15 @@ const A = (obj, prop, factory) => {
|
|
|
302
303
|
}
|
|
303
304
|
};
|
|
304
305
|
|
|
306
|
+
/**
|
|
307
|
+
* Whether the library type emits an ECMAScript module, which only `output.module`
|
|
308
|
+
* output can carry — every other type is written into a script.
|
|
309
|
+
* @param {LibraryType | undefined} type library type
|
|
310
|
+
* @returns {boolean} true, when the type is only emitted as an ECMAScript module
|
|
311
|
+
*/
|
|
312
|
+
const isModuleLibraryType = (type) =>
|
|
313
|
+
type === "module" || type === "modern-module";
|
|
314
|
+
|
|
305
315
|
/**
|
|
306
316
|
* Apply webpack options base defaults.
|
|
307
317
|
* @param {WebpackOptionsNormalized} options options to be modified
|
|
@@ -363,7 +373,6 @@ const applyWebpackOptionsDefaults = (options, compilerIndex) => {
|
|
|
363
373
|
applyExperimentsDefaults(options.experiments, {
|
|
364
374
|
production,
|
|
365
375
|
development,
|
|
366
|
-
targetProperties,
|
|
367
376
|
rules: options.module.rules
|
|
368
377
|
});
|
|
369
378
|
|
|
@@ -407,9 +416,6 @@ const applyWebpackOptionsDefaults = (options, compilerIndex) => {
|
|
|
407
416
|
(typeof target === "string" && target.startsWith("browserslist")) ||
|
|
408
417
|
(Array.isArray(target) &&
|
|
409
418
|
target.some((target) => target.startsWith("browserslist"))),
|
|
410
|
-
outputModule:
|
|
411
|
-
/** @type {NonNullable<ExperimentsNormalized["outputModule"]>} */
|
|
412
|
-
(options.experiments.outputModule),
|
|
413
419
|
development,
|
|
414
420
|
entry: options.entry,
|
|
415
421
|
futureDefaults,
|
|
@@ -422,9 +428,7 @@ const applyWebpackOptionsDefaults = (options, compilerIndex) => {
|
|
|
422
428
|
// is read by another bundler, where an eval wrapper hides `import.meta` from it.
|
|
423
429
|
const noDevSourceMap = /** @type {LibraryType[]} */ (
|
|
424
430
|
options.output.enabledLibraryTypes
|
|
425
|
-
).some(
|
|
426
|
-
(type) => futureDefaults || type === "module" || type === "modern-module"
|
|
427
|
-
);
|
|
431
|
+
).some((type) => futureDefaults || isModuleLibraryType(type));
|
|
428
432
|
|
|
429
433
|
F(
|
|
430
434
|
options,
|
|
@@ -488,10 +492,9 @@ const applyWebpackOptionsDefaults = (options, compilerIndex) => {
|
|
|
488
492
|
library: options.output.library
|
|
489
493
|
});
|
|
490
494
|
|
|
491
|
-
// `output.resourceHints.urlHints`
|
|
492
|
-
//
|
|
493
|
-
//
|
|
494
|
-
// `parser.<type>.urlHints` rules — matched later, last-match-wins — override.
|
|
495
|
+
// `output.resourceHints.urlHints` fans the project-wide rules out as the base
|
|
496
|
+
// `urlHints` of every URL-emitting parser. They go first, so a parser-scoped
|
|
497
|
+
// rule matches later and wins.
|
|
495
498
|
const outputUrlHints =
|
|
496
499
|
options.output.resourceHints && options.output.resourceHints.urlHints;
|
|
497
500
|
if (outputUrlHints && outputUrlHints.length > 0) {
|
|
@@ -629,13 +632,12 @@ const applyWebpackOptionsDefaults = (options, compilerIndex) => {
|
|
|
629
632
|
* @param {object} options options
|
|
630
633
|
* @param {boolean} options.production is production
|
|
631
634
|
* @param {boolean} options.development is development mode
|
|
632
|
-
* @param {TargetProperties | false} options.targetProperties target properties
|
|
633
635
|
* @param {RuleSetRules} options.rules user `module.rules`, used to resolve the css/html/asyncWebAssembly/typescript "auto" defaults
|
|
634
636
|
* @returns {void}
|
|
635
637
|
*/
|
|
636
638
|
const applyExperimentsDefaults = (
|
|
637
639
|
experiments,
|
|
638
|
-
{ production, development,
|
|
640
|
+
{ production, development, rules }
|
|
639
641
|
) => {
|
|
640
642
|
D(experiments, "futureDefaults", false);
|
|
641
643
|
D(experiments, "backCompat", !experiments.futureDefaults);
|
|
@@ -646,23 +648,6 @@ const applyExperimentsDefaults = (
|
|
|
646
648
|
"asyncWebAssembly",
|
|
647
649
|
experiments.futureDefaults ? true : "auto"
|
|
648
650
|
);
|
|
649
|
-
// the universal target (web + node, neither specific) only works as ESM —
|
|
650
|
-
// unless the target cannot read one, which no output format can repair, so
|
|
651
|
-
// leave `output.chunkFormat` to say so rather than emitting a module the
|
|
652
|
-
// target has already reported it will not load
|
|
653
|
-
const universal =
|
|
654
|
-
Boolean(targetProperties) &&
|
|
655
|
-
/** @type {TargetProperties} */ (targetProperties).node === null &&
|
|
656
|
-
/** @type {TargetProperties} */ (targetProperties).web === null &&
|
|
657
|
-
/** @type {TargetProperties} */ (targetProperties).module !== false;
|
|
658
|
-
// the deno and bun targets only emit ECMAScript modules
|
|
659
|
-
const deno =
|
|
660
|
-
Boolean(targetProperties) &&
|
|
661
|
-
/** @type {TargetProperties} */ (targetProperties).deno === true;
|
|
662
|
-
const bun =
|
|
663
|
-
Boolean(targetProperties) &&
|
|
664
|
-
/** @type {TargetProperties} */ (targetProperties).bun === true;
|
|
665
|
-
D(experiments, "outputModule", universal || deno || bun);
|
|
666
651
|
D(experiments, "lazyCompilation", undefined);
|
|
667
652
|
D(experiments, "buildHttp", undefined);
|
|
668
653
|
D(experiments, "cacheUnaffected", experiments.futureDefaults);
|
|
@@ -674,14 +659,12 @@ const applyExperimentsDefaults = (
|
|
|
674
659
|
experiments.futureDefaults ? true : "auto"
|
|
675
660
|
);
|
|
676
661
|
|
|
677
|
-
// Resolve
|
|
678
|
-
//
|
|
679
|
-
//
|
|
680
|
-
|
|
681
|
-
//
|
|
682
|
-
//
|
|
683
|
-
// then step aside per-module for requests that loaders were applied to
|
|
684
|
-
// (inline requests or loaders injected via hooks, e.g. html-webpack-plugin).
|
|
662
|
+
// Resolve `"auto"`: enable the built-in type unless a loader is already
|
|
663
|
+
// registered for these files, so the default breaks no existing setup. Both
|
|
664
|
+
// extensions are sampled, since `/\.css$/i` also covers `.module.css`.
|
|
665
|
+
|
|
666
|
+
// Enabled implicitly the value stays `"auto"`, and the plugins then step
|
|
667
|
+
// aside per module for requests loaders were applied to.
|
|
685
668
|
// TODO webpack 6: css/html default to `true`, drop the `"auto"` marker.
|
|
686
669
|
if (experiments.css === "auto") {
|
|
687
670
|
experiments.css =
|
|
@@ -918,6 +901,7 @@ const applyJavascriptParserOptionsDefaults = (
|
|
|
918
901
|
D(parserOptions, "wrappedContextRecursive", true);
|
|
919
902
|
D(parserOptions, "wrappedContextCritical", false);
|
|
920
903
|
D(parserOptions, "strictThisContextOnImports", false);
|
|
904
|
+
D(parserOptions, "specNamespaceObject", false);
|
|
921
905
|
D(parserOptions, "importMeta", outputModule ? "preserve-unknown" : true);
|
|
922
906
|
D(parserOptions, "dynamicImportMode", "lazy");
|
|
923
907
|
D(parserOptions, "dynamicImportPrefetch", false);
|
|
@@ -1240,18 +1224,13 @@ const applyModuleDefaults = (
|
|
|
1240
1224
|
}
|
|
1241
1225
|
|
|
1242
1226
|
if (html) {
|
|
1243
|
-
// `
|
|
1244
|
-
//
|
|
1245
|
-
//
|
|
1246
|
-
// behaviour. Setting `extract: true` forces extraction for all HTML
|
|
1247
|
-
// modules (including imported ones); `extract: false` disables it
|
|
1248
|
-
// everywhere.
|
|
1227
|
+
// `extract` is deliberately left undefined, which HtmlGenerator reads as
|
|
1228
|
+
// "extract only a module that is a compilation entry". `true` forces it for
|
|
1229
|
+
// imported modules too, `false` disables it everywhere.
|
|
1249
1230
|
F(module.generator, HTML_MODULE_TYPE, () => ({}));
|
|
1250
|
-
// `
|
|
1251
|
-
//
|
|
1252
|
-
//
|
|
1253
|
-
// Users may pass `false` to disable extraction entirely or an array
|
|
1254
|
-
// (with `"..."` to include the defaults) to customize it.
|
|
1231
|
+
// `sources` defaults to `true`, so HtmlParser extracts URL-like attributes
|
|
1232
|
+
// as dependencies from its built-in list. `false` disables extraction, and
|
|
1233
|
+
// an array customizes it, with `"..."` keeping the defaults.
|
|
1255
1234
|
F(module.parser, HTML_MODULE_TYPE, () => ({}));
|
|
1256
1235
|
D(
|
|
1257
1236
|
/** @type {NonNullable<ParserOptionsByModuleTypeKnown[HTML_MODULE_TYPE]>} */
|
|
@@ -1385,11 +1364,9 @@ const applyModuleDefaults = (
|
|
|
1385
1364
|
type: CSS_MODULE_TYPE,
|
|
1386
1365
|
resolve
|
|
1387
1366
|
});
|
|
1388
|
-
// For
|
|
1389
|
-
//
|
|
1390
|
-
//
|
|
1391
|
-
// the same modules-mode behavior from the auto rule, and forcing a
|
|
1392
|
-
// different type stamp here would create a duplicate module instance.
|
|
1367
|
+
// For `composes: className from "./style.css"`. A file already detected as
|
|
1368
|
+
// a CSS module by extension is skipped: it gets modules mode from the auto
|
|
1369
|
+
// rule anyway, and a second type stamp would duplicate the module.
|
|
1393
1370
|
const moduleExtension = /\.module\.\w+$/i;
|
|
1394
1371
|
rules.push({
|
|
1395
1372
|
dependency: /css-import-local-module/,
|
|
@@ -1432,16 +1409,16 @@ const applyModuleDefaults = (
|
|
|
1432
1409
|
type: HTML_MODULE_TYPE,
|
|
1433
1410
|
resolve
|
|
1434
1411
|
});
|
|
1412
|
+
// Exactly `text/html` — a string condition matches by prefix, which
|
|
1413
|
+
// would make a `data:text/htmlx,` module (JavaScript) a page.
|
|
1435
1414
|
rules.push({
|
|
1436
|
-
mimetype:
|
|
1415
|
+
mimetype: /^text\/html$/i,
|
|
1437
1416
|
type: HTML_MODULE_TYPE,
|
|
1438
1417
|
resolve
|
|
1439
1418
|
});
|
|
1440
|
-
// `<iframe srcdoc>` content
|
|
1441
|
-
// `data:text/html` module. `extract: "inline"` exposes the
|
|
1442
|
-
//
|
|
1443
|
-
// Template` reads back into the attribute, without emitting a standalone
|
|
1444
|
-
// `.html` file (the module is never a page on its own).
|
|
1419
|
+
// `<iframe srcdoc>` content goes back through the HTML pipeline as a
|
|
1420
|
+
// `data:text/html` module. `extract: "inline"` exposes it on the `html`
|
|
1421
|
+
// channel without emitting a file: it is never a page on its own.
|
|
1445
1422
|
rules.push({
|
|
1446
1423
|
dependency: "html-srcdoc",
|
|
1447
1424
|
generator: {
|
|
@@ -1450,12 +1427,9 @@ const applyModuleDefaults = (
|
|
|
1450
1427
|
resolve
|
|
1451
1428
|
});
|
|
1452
1429
|
if (css) {
|
|
1453
|
-
// Inline `<style>` content
|
|
1454
|
-
//
|
|
1455
|
-
//
|
|
1456
|
-
// processed CSS text on the `css-text` codegen channel that
|
|
1457
|
-
// `HtmlInlineStyleDependency.Template` reads back into the
|
|
1458
|
-
// `<style>` tag.
|
|
1430
|
+
// Inline `<style>` content goes into the CSS pipeline as a
|
|
1431
|
+
// `data:text/css` module. `exportType: "text"` is forced, so the
|
|
1432
|
+
// processed text reaches the `css-text` channel the template reads.
|
|
1459
1433
|
rules.push({
|
|
1460
1434
|
dependency: "html-style",
|
|
1461
1435
|
parser: {
|
|
@@ -1592,7 +1566,6 @@ const applyModuleDefaults = (
|
|
|
1592
1566
|
* @param {string} options.context context
|
|
1593
1567
|
* @param {TargetProperties | false} options.targetProperties target properties
|
|
1594
1568
|
* @param {boolean} options.isAffectedByBrowserslist is affected by browserslist
|
|
1595
|
-
* @param {boolean} options.outputModule is outputModule experiment enabled
|
|
1596
1569
|
* @param {boolean} options.development is development mode
|
|
1597
1570
|
* @param {Entry} options.entry entry option
|
|
1598
1571
|
* @param {boolean} options.futureDefaults is future defaults enabled
|
|
@@ -1605,7 +1578,6 @@ const applyOutputDefaults = (
|
|
|
1605
1578
|
context,
|
|
1606
1579
|
targetProperties: tp,
|
|
1607
1580
|
isAffectedByBrowserslist,
|
|
1608
|
-
outputModule,
|
|
1609
1581
|
development,
|
|
1610
1582
|
entry,
|
|
1611
1583
|
futureDefaults,
|
|
@@ -1661,7 +1633,65 @@ const applyOutputDefaults = (
|
|
|
1661
1633
|
}
|
|
1662
1634
|
});
|
|
1663
1635
|
|
|
1664
|
-
|
|
1636
|
+
/**
|
|
1637
|
+
* Processes the provided fn.
|
|
1638
|
+
* @param {(entryDescription: EntryDescription) => void} fn iterator
|
|
1639
|
+
* @returns {void}
|
|
1640
|
+
*/
|
|
1641
|
+
const forEachEntry = (fn) => {
|
|
1642
|
+
for (const name of Object.keys(entry)) {
|
|
1643
|
+
fn(/** @type {{ [k: string]: EntryDescription }} */ (entry)[name]);
|
|
1644
|
+
}
|
|
1645
|
+
};
|
|
1646
|
+
|
|
1647
|
+
/**
|
|
1648
|
+
* Every library type the configuration states, wherever it was declared.
|
|
1649
|
+
* @returns {LibraryType[]} the declared library types
|
|
1650
|
+
*/
|
|
1651
|
+
const declaredLibraryTypes = () => {
|
|
1652
|
+
/** @type {LibraryType[]} */
|
|
1653
|
+
const types = [];
|
|
1654
|
+
if (output.library && output.library.type) types.push(output.library.type);
|
|
1655
|
+
// A plugin (`ModuleFederationPlugin`) pushed its type here before the defaults;
|
|
1656
|
+
// `"..."` is the extend placeholder `A` resolves, never a type of its own.
|
|
1657
|
+
if (output.enabledLibraryTypes) {
|
|
1658
|
+
for (const type of output.enabledLibraryTypes) {
|
|
1659
|
+
if (type !== "...") types.push(type);
|
|
1660
|
+
}
|
|
1661
|
+
}
|
|
1662
|
+
forEachEntry((desc) => {
|
|
1663
|
+
if (desc.library && desc.library.type) types.push(desc.library.type);
|
|
1664
|
+
});
|
|
1665
|
+
return types;
|
|
1666
|
+
};
|
|
1667
|
+
|
|
1668
|
+
const libraryTypes = declaredLibraryTypes();
|
|
1669
|
+
|
|
1670
|
+
// A library type that is an ECMAScript module is another spelling of
|
|
1671
|
+
// `output.module`, so it turns it on rather than disagreeing with it.
|
|
1672
|
+
if (libraryTypes.some(isModuleLibraryType)) {
|
|
1673
|
+
output.module = true;
|
|
1674
|
+
}
|
|
1675
|
+
|
|
1676
|
+
// Every other library type is read out of a script, which is a statement that
|
|
1677
|
+
// the output is not an ECMAScript module — so it holds the default below back.
|
|
1678
|
+
const hasScriptLibrary = libraryTypes.some(
|
|
1679
|
+
(type) => !isModuleLibraryType(type)
|
|
1680
|
+
);
|
|
1681
|
+
|
|
1682
|
+
// the universal target (web + node, neither specific), deno and bun only work
|
|
1683
|
+
// as ESM, unless `module: false` says the target cannot read one
|
|
1684
|
+
F(output, "module", () =>
|
|
1685
|
+
Boolean(
|
|
1686
|
+
tp &&
|
|
1687
|
+
((tp.node === null && tp.web === null && tp.module !== false) ||
|
|
1688
|
+
tp.deno === true ||
|
|
1689
|
+
tp.bun === true ||
|
|
1690
|
+
// webpack@6 emits ESM wherever the target reads one — a browserslist
|
|
1691
|
+
// query (or `esX`/`nodeX`) without ESM support keeps script output
|
|
1692
|
+
(futureDefaults && tp.module !== false && !hasScriptLibrary))
|
|
1693
|
+
)
|
|
1694
|
+
);
|
|
1665
1695
|
|
|
1666
1696
|
const environment = /** @type {Environment} */ (output.environment);
|
|
1667
1697
|
/**
|
|
@@ -1705,12 +1735,11 @@ const applyOutputDefaults = (
|
|
|
1705
1735
|
"const",
|
|
1706
1736
|
() => tp && optimistic(/** @type {boolean | undefined} */ (tp.const))
|
|
1707
1737
|
);
|
|
1708
|
-
// Only the browserslist target reports these;
|
|
1709
|
-
//
|
|
1710
|
-
|
|
1711
|
-
// `let` was added after `const
|
|
1712
|
-
//
|
|
1713
|
-
// do report `let` (browserslist, built-ins) keep their own accurate value.
|
|
1738
|
+
// Only the browserslist target reports these; unset elsewhere, which
|
|
1739
|
+
// `optimistic` reads as the modern spelling being available.
|
|
1740
|
+
|
|
1741
|
+
// `let` was added after `const`, so a target predating it reports only
|
|
1742
|
+
// `const` and falls back to it. One reporting `let` keeps its own value.
|
|
1714
1743
|
F(environment, "let", () =>
|
|
1715
1744
|
conditionallyOptimistic(
|
|
1716
1745
|
/** @type {boolean | undefined} */ (tp && tp.let),
|
|
@@ -1747,6 +1776,12 @@ const applyOutputDefaults = (
|
|
|
1747
1776
|
"generator",
|
|
1748
1777
|
() => tp && optimistic(/** @type {boolean | undefined} */ (tp.generator))
|
|
1749
1778
|
);
|
|
1779
|
+
F(
|
|
1780
|
+
environment,
|
|
1781
|
+
"topLevelAwait",
|
|
1782
|
+
() =>
|
|
1783
|
+
tp && optimistic(/** @type {boolean | undefined} */ (tp.topLevelAwait))
|
|
1784
|
+
);
|
|
1750
1785
|
F(
|
|
1751
1786
|
environment,
|
|
1752
1787
|
"forOf",
|
|
@@ -1836,10 +1871,9 @@ const applyOutputDefaults = (
|
|
|
1836
1871
|
tp && optimistic(/** @type {boolean | undefined} */ (tp.modulePreload))
|
|
1837
1872
|
);
|
|
1838
1873
|
|
|
1839
|
-
//
|
|
1840
|
-
//
|
|
1841
|
-
//
|
|
1842
|
-
// tags (no waterfall), so it stays opt-in.
|
|
1874
|
+
// For ESM output, preload the entry's initial dependency graph, which native
|
|
1875
|
+
// `import()` would otherwise fetch in a waterfall. Classic output loads its
|
|
1876
|
+
// initial chunks in parallel already, so it stays opt-in.
|
|
1843
1877
|
if (output.module && output.resourceHints === undefined) {
|
|
1844
1878
|
output.resourceHints = {};
|
|
1845
1879
|
}
|
|
@@ -1893,13 +1927,9 @@ const applyOutputDefaults = (
|
|
|
1893
1927
|
}
|
|
1894
1928
|
return "[id].css";
|
|
1895
1929
|
});
|
|
1896
|
-
// Derive html
|
|
1897
|
-
//
|
|
1898
|
-
//
|
|
1899
|
-
// extracted HTML modules in one compilation don't collide on the same
|
|
1900
|
-
// emitted file. For example: `output.filename: "bundle.js"` would derive
|
|
1901
|
-
// `bundle.html` — two `.html` modules extracted in the same build would
|
|
1902
|
-
// both want that name and conflict at emit time.
|
|
1930
|
+
// Derive the html filenames from `output.filename`, as the CSS pipeline does.
|
|
1931
|
+
// A derived template with no per-module placeholder falls back to
|
|
1932
|
+
// `[name].html`, or two extracted modules would want the same file.
|
|
1903
1933
|
const HAS_PATH_PLACEHOLDER_REGEXP =
|
|
1904
1934
|
/\[(name|id|chunkhash|contenthash|fullhash|hash)/;
|
|
1905
1935
|
/**
|
|
@@ -1946,11 +1976,9 @@ const applyOutputDefaults = (
|
|
|
1946
1976
|
if (tp) {
|
|
1947
1977
|
if (tp.global) return "global";
|
|
1948
1978
|
if (tp.globalThis) return "globalThis";
|
|
1949
|
-
//
|
|
1950
|
-
//
|
|
1951
|
-
//
|
|
1952
|
-
// scopes, `global` covers Node.js. Naming either alone leaves the other
|
|
1953
|
-
// platform reading an undeclared binding.
|
|
1979
|
+
// A universal target has no identifier defined on both sides, so this is
|
|
1980
|
+
// `globalThis` where nothing argues against it and a guarded pair where
|
|
1981
|
+
// something does: naming one alone leaves the other undeclared.
|
|
1954
1982
|
if (tp.web === null && tp.node === null) {
|
|
1955
1983
|
return tp.globalThis === undefined
|
|
1956
1984
|
? "globalThis"
|
|
@@ -1981,7 +2009,7 @@ const applyOutputDefaults = (
|
|
|
1981
2009
|
"For the selected environment is no default script chunk format available:\n" +
|
|
1982
2010
|
`${
|
|
1983
2011
|
tp.module
|
|
1984
|
-
? "Module ('module') can be chosen when ES modules are available (please set '
|
|
2012
|
+
? "Module ('module') can be chosen when ES modules are available (please set 'output.module' to `true`)"
|
|
1985
2013
|
: ""
|
|
1986
2014
|
}\n` +
|
|
1987
2015
|
"JSONP Array push ('array-push') can be chosen when 'document' or 'importScripts' is available.\n" +
|
|
@@ -2128,16 +2156,6 @@ const applyOutputDefaults = (
|
|
|
2128
2156
|
D(trustedTypes, "onPolicyCreationFailure", "stop");
|
|
2129
2157
|
}
|
|
2130
2158
|
|
|
2131
|
-
/**
|
|
2132
|
-
* Processes the provided fn.
|
|
2133
|
-
* @param {(entryDescription: EntryDescription) => void} fn iterator
|
|
2134
|
-
* @returns {void}
|
|
2135
|
-
*/
|
|
2136
|
-
const forEachEntry = (fn) => {
|
|
2137
|
-
for (const name of Object.keys(entry)) {
|
|
2138
|
-
fn(/** @type {{ [k: string]: EntryDescription }} */ (entry)[name]);
|
|
2139
|
-
}
|
|
2140
|
-
};
|
|
2141
2159
|
A(output, "enabledLibraryTypes", () => {
|
|
2142
2160
|
/** @type {LibraryType[]} */
|
|
2143
2161
|
const enabledLibraryTypes = [];
|
|
@@ -2388,6 +2406,7 @@ const applyPerformanceDefaults = (performance, { production }) => {
|
|
|
2388
2406
|
// Stands in for every check left unset, so an explicit one still wins.
|
|
2389
2407
|
const all = performance.all !== undefined ? performance.all : false;
|
|
2390
2408
|
|
|
2409
|
+
D(performance, "analyzableBailouts", all);
|
|
2391
2410
|
D(performance, "asyncChunkWaterfalls", all);
|
|
2392
2411
|
D(performance, "broadContexts", all);
|
|
2393
2412
|
D(performance, "cacheEffectiveness", all);
|
|
@@ -2396,8 +2415,6 @@ const applyPerformanceDefaults = (performance, { production }) => {
|
|
|
2396
2415
|
D(performance, "duplicateModules", all);
|
|
2397
2416
|
D(performance, "duplicatePackages", all);
|
|
2398
2417
|
D(performance, "dynamicExports", all);
|
|
2399
|
-
D(performance, "entrypointOverlap", all);
|
|
2400
|
-
D(performance, "embeddedSourceMaps", all);
|
|
2401
2418
|
D(performance, "evalUsage", all);
|
|
2402
2419
|
D(performance, "hotspots", all);
|
|
2403
2420
|
D(performance, "legacyJavascript", all);
|
|
@@ -2410,14 +2427,13 @@ const applyPerformanceDefaults = (performance, { production }) => {
|
|
|
2410
2427
|
D(performance, "redundantDynamicImports", all);
|
|
2411
2428
|
D(performance, "scopeHoistingBailouts", all);
|
|
2412
2429
|
D(performance, "splitChunksCapped", all);
|
|
2430
|
+
D(performance, "sourceMaps", all);
|
|
2413
2431
|
D(performance, "tinyChunks", all);
|
|
2414
2432
|
D(performance, "topLevelThis", all);
|
|
2415
2433
|
D(performance, "unsplitVendors", all);
|
|
2416
|
-
D(performance, "
|
|
2417
|
-
D(performance, "
|
|
2418
|
-
D(performance, "
|
|
2419
|
-
D(performance, "unusedReexports", all);
|
|
2420
|
-
D(performance, "unusedRules", all);
|
|
2434
|
+
D(performance, "unusedAssets", all);
|
|
2435
|
+
D(performance, "unusedConfig", all);
|
|
2436
|
+
D(performance, "unusedModules", all);
|
|
2421
2437
|
F(performance, "hints", () => (production ? "warning" : false));
|
|
2422
2438
|
};
|
|
2423
2439
|
|
|
@@ -2463,20 +2479,28 @@ const applyOptimizationDefaults = (
|
|
|
2463
2479
|
D(optimization, "mangleWasmImports", false);
|
|
2464
2480
|
D(optimization, "portableRecords", records);
|
|
2465
2481
|
D(optimization, "realContentHash", production);
|
|
2466
|
-
|
|
2467
|
-
//
|
|
2468
|
-
|
|
2469
|
-
|
|
2470
|
-
|
|
2471
|
-
|
|
2482
|
+
// A plugin assigning the object shorthand in `apply()` runs after
|
|
2483
|
+
// normalization: it replaces `minimizeOptions`, keeping `minimize` boolean.
|
|
2484
|
+
const minimizeAssignedInApply = /** @type {unknown} */ (
|
|
2485
|
+
optimization.minimize
|
|
2486
|
+
);
|
|
2487
|
+
if (typeof minimizeAssignedInApply === "object") {
|
|
2488
|
+
optimization.minimizeOptions = /** @type {OptimizationMinimizeOptions} */ (
|
|
2489
|
+
minimizeAssignedInApply
|
|
2490
|
+
);
|
|
2491
|
+
optimization.minimize = true;
|
|
2472
2492
|
}
|
|
2473
|
-
|
|
2474
|
-
|
|
2475
|
-
|
|
2476
|
-
|
|
2477
|
-
|
|
2478
|
-
|
|
2479
|
-
|
|
2493
|
+
D(optimization, "minimize", production);
|
|
2494
|
+
F(optimization, "minimizeOptions", () => ({}));
|
|
2495
|
+
const minimizeOptions =
|
|
2496
|
+
/** @type {NonNullable<Optimization["minimizeOptions"]>} */
|
|
2497
|
+
(optimization.minimizeOptions);
|
|
2498
|
+
if (optimization.minimize) {
|
|
2499
|
+
// Canonicalize the per-asset-type options: the JS minimizer's defaults
|
|
2500
|
+
// become visible in the resolved config rather than hidden in the wiring.
|
|
2501
|
+
F(minimizeOptions, "javascript", () => ({ compress: { passes: 2 } }));
|
|
2502
|
+
F(minimizeOptions, "css", () => ({}));
|
|
2503
|
+
F(minimizeOptions, "html", () => ({}));
|
|
2480
2504
|
}
|
|
2481
2505
|
A(optimization, "minimizer", () => [
|
|
2482
2506
|
{
|
|
@@ -2484,27 +2508,24 @@ const applyOptimizationDefaults = (
|
|
|
2484
2508
|
// Lazy load the minimizer plugin
|
|
2485
2509
|
const TerserPlugin = require("minimizer-webpack-plugin");
|
|
2486
2510
|
|
|
2487
|
-
//
|
|
2488
|
-
// native CSS
|
|
2489
|
-
// functions each dispatched by its own `filter
|
|
2490
|
-
// cssMinify
|
|
2491
|
-
// worker-safe by resolving their parser with `require("webpack/…")`
|
|
2492
|
-
// the worker, so all three share the
|
|
2493
|
-
//
|
|
2494
|
-
|
|
2495
|
-
//
|
|
2496
|
-
//
|
|
2497
|
-
//
|
|
2498
|
-
// than resolved per asset — a coarse check, but it keeps the outcome
|
|
2499
|
-
// independent of tap order and of the plugin version in use.
|
|
2511
|
+
// WHY: one minimizer instance, so one worker-thread pool, handles JS and
|
|
2512
|
+
// — where native CSS and HTML are enabled — those assets too, as an array
|
|
2513
|
+
// of minify functions each dispatched by its own `filter`: terser to JS,
|
|
2514
|
+
// `cssMinify` to CSS, `htmlMinify` to HTML. The CSS and HTML serializers
|
|
2515
|
+
// stay worker-safe by resolving their parser with `require("webpack/…")`
|
|
2516
|
+
// in the worker, so all three share the pool, and `test` is widened to let
|
|
2517
|
+
// those assets reach the dispatcher.
|
|
2518
|
+
|
|
2519
|
+
// Step aside for a minimizer the user configured for these types:
|
|
2520
|
+
// whichever ran first would mark the asset `minimized` and silently
|
|
2521
|
+
// disable the other. Matchers are read directly, coarse but stable.
|
|
2500
2522
|
const claimedByOtherMinimizer = require("./getClaimedAssetTypes")(
|
|
2501
2523
|
compiler
|
|
2502
2524
|
);
|
|
2503
2525
|
|
|
2504
|
-
//
|
|
2505
|
-
// object here: `false` disables a type, an object is its options.
|
|
2526
|
+
// Per asset type: `false` disables that type, an object is its options.
|
|
2506
2527
|
const minimizeByType = /** @type {OptimizationMinimizeOptions} */ (
|
|
2507
|
-
compiler.options.optimization.
|
|
2528
|
+
compiler.options.optimization.minimizeOptions
|
|
2508
2529
|
);
|
|
2509
2530
|
const terserOptions = minimizeByType.javascript || {
|
|
2510
2531
|
compress: { passes: 2 }
|
|
@@ -2573,10 +2594,9 @@ const applyOptimizationDefaults = (
|
|
|
2573
2594
|
}
|
|
2574
2595
|
if (minifyHtml) {
|
|
2575
2596
|
minify.push(require("../html/htmlMinify"));
|
|
2576
|
-
// `minimize.css` rides
|
|
2577
|
-
//
|
|
2578
|
-
//
|
|
2579
|
-
// each language the other's answer.
|
|
2597
|
+
// `minimize.css` rides under its own key rather than spread beside the
|
|
2598
|
+
// HTML options: the two name some of the same switches, so one flat
|
|
2599
|
+
// object would hand each language the other's answer.
|
|
2580
2600
|
minimizerOptions.push({
|
|
2581
2601
|
environment: cssEnvironment,
|
|
2582
2602
|
css: cssOptions,
|
|
@@ -17,19 +17,18 @@ const { matchObject } = require("../ModuleFilenameHelpers");
|
|
|
17
17
|
* @returns {boolean} whether the candidate minimizes that file
|
|
18
18
|
*/
|
|
19
19
|
const claims = (candidate, file) => {
|
|
20
|
-
//
|
|
21
|
-
// `css-minimizer-webpack-plugin`, `html-minimizer-webpack-plugin`, …
|
|
22
|
-
//
|
|
23
|
-
//
|
|
24
|
-
//
|
|
25
|
-
//
|
|
26
|
-
//
|
|
20
|
+
// WHY: every minimizer in the `minimizer-webpack-plugin` family — itself,
|
|
21
|
+
// `css-minimizer-webpack-plugin`, `html-minimizer-webpack-plugin`, … — keeps
|
|
22
|
+
// its implementation on `options.minimizer` and its asset matcher alongside
|
|
23
|
+
// it, in the shape `matchObject` reads. The matcher alone is not enough to
|
|
24
|
+
// recognize one: `BannerPlugin` and `SourceMapDevToolPlugin` carry the same
|
|
25
|
+
// three keys, and `LoaderOptionsPlugin` defaults `test` to match every file,
|
|
26
|
+
// so reading those as minimizers would disable minification.
|
|
27
27
|
const { options } = /** @type {{ options?: MinimizerOptions }} */ (candidate);
|
|
28
28
|
if (!options || !options.minimizer) return false;
|
|
29
|
-
// `test
|
|
30
|
-
// files within them
|
|
31
|
-
// to a subdirectory claim nothing, and webpack would then race it
|
|
32
|
-
// files it was configured for.
|
|
29
|
+
// `test` and `include` say which types it handles, while `exclude` only
|
|
30
|
+
// narrows the files within them: honoring that narrowing would let a minimizer
|
|
31
|
+
// scoped to a subdirectory claim nothing, and webpack would then race it.
|
|
33
32
|
const { test, include } = options;
|
|
34
33
|
return (
|
|
35
34
|
(test !== undefined && matchObject({ test }, file)) ||
|