webpack 5.59.0 → 5.94.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 +48 -38
- package/bin/webpack.js +34 -10
- package/hot/dev-server.js +19 -5
- package/hot/lazy-compilation-node.js +13 -1
- package/hot/lazy-compilation-web.js +9 -0
- package/hot/log-apply-result.js +5 -0
- package/hot/log.js +23 -4
- package/hot/only-dev-server.js +3 -2
- package/hot/poll.js +5 -2
- package/hot/signal.js +6 -2
- package/lib/APIPlugin.js +226 -122
- package/lib/AbstractMethodError.js +10 -5
- package/lib/AsyncDependenciesBlock.js +13 -5
- package/lib/AutomaticPrefetchPlugin.js +2 -1
- package/lib/BannerPlugin.js +33 -12
- package/lib/Cache.js +16 -12
- package/lib/CacheFacade.js +13 -16
- package/lib/CaseSensitiveModulesWarning.js +8 -8
- package/lib/Chunk.js +60 -33
- package/lib/ChunkGraph.js +207 -72
- package/lib/ChunkGroup.js +40 -20
- package/lib/ChunkTemplate.js +43 -0
- package/lib/CleanPlugin.js +117 -32
- package/lib/CodeGenerationResults.js +8 -7
- package/lib/CommentCompilationWarning.js +0 -1
- package/lib/CompatibilityPlugin.js +85 -46
- package/lib/Compilation.js +712 -392
- package/lib/Compiler.js +393 -172
- package/lib/ConcatenationScope.js +10 -13
- package/lib/ConditionalInitFragment.js +22 -14
- package/lib/ConstPlugin.js +104 -64
- package/lib/ContextExclusionPlugin.js +3 -3
- package/lib/ContextModule.js +283 -108
- package/lib/ContextModuleFactory.js +151 -63
- package/lib/ContextReplacementPlugin.js +25 -10
- package/lib/CssModule.js +166 -0
- package/lib/DefinePlugin.js +254 -148
- package/lib/DelegatedModule.js +29 -6
- package/lib/DelegatedModuleFactoryPlugin.js +42 -22
- package/lib/DelegatedPlugin.js +4 -0
- package/lib/DependenciesBlock.js +17 -2
- package/lib/Dependency.js +58 -29
- package/lib/DependencyTemplate.js +24 -3
- package/lib/DependencyTemplates.js +2 -2
- package/lib/DllEntryPlugin.js +18 -1
- package/lib/DllModule.js +21 -4
- package/lib/DllModuleFactory.js +2 -1
- package/lib/DllPlugin.js +9 -7
- package/lib/DllReferencePlugin.js +50 -19
- package/lib/EntryOptionPlugin.js +6 -1
- package/lib/EntryPlugin.js +7 -4
- package/lib/Entrypoint.js +2 -2
- package/lib/EnvironmentNotSupportAsyncWarning.js +52 -0
- package/lib/EnvironmentPlugin.js +5 -2
- package/lib/ErrorHelpers.js +65 -26
- package/lib/EvalDevToolModulePlugin.js +37 -13
- package/lib/EvalSourceMapDevToolPlugin.js +50 -20
- package/lib/ExportsInfo.js +234 -133
- package/lib/ExportsInfoApiPlugin.js +31 -15
- package/lib/ExternalModule.js +391 -129
- package/lib/ExternalModuleFactoryPlugin.js +65 -17
- package/lib/FileSystemInfo.js +1038 -523
- package/lib/FlagAllModulesAsUsedPlugin.js +27 -27
- package/lib/FlagDependencyExportsPlugin.js +352 -349
- package/lib/FlagDependencyUsagePlugin.js +10 -10
- package/lib/FlagEntryExportAsUsedPlugin.js +26 -23
- package/lib/Generator.js +16 -8
- package/lib/GraphHelpers.js +3 -2
- package/lib/HookWebpackError.js +11 -13
- package/lib/HotModuleReplacementPlugin.js +221 -128
- package/lib/IgnoreErrorModuleFactory.js +4 -4
- package/lib/IgnorePlugin.js +5 -4
- package/lib/IgnoreWarningsPlugin.js +6 -9
- package/lib/InitFragment.js +39 -15
- package/lib/JavascriptMetaInfoPlugin.js +27 -15
- package/lib/LibManifestPlugin.js +45 -16
- package/lib/LoaderOptionsPlugin.js +13 -3
- package/lib/MainTemplate.js +74 -21
- package/lib/Module.js +155 -34
- package/lib/ModuleBuildError.js +13 -11
- package/lib/ModuleDependencyError.js +6 -4
- package/lib/ModuleDependencyWarning.js +6 -4
- package/lib/ModuleError.js +10 -5
- package/lib/ModuleFactory.js +4 -4
- package/lib/ModuleFilenameHelpers.js +164 -54
- package/lib/ModuleGraph.js +93 -53
- package/lib/ModuleGraphConnection.js +27 -13
- package/lib/ModuleHashingError.js +29 -0
- package/lib/ModuleInfoHeaderPlugin.js +92 -33
- package/lib/ModuleNotFoundError.js +5 -2
- package/lib/ModuleParseError.js +17 -9
- package/lib/ModuleProfile.js +1 -0
- package/lib/ModuleRestoreError.js +3 -1
- package/lib/ModuleStoreError.js +3 -2
- package/lib/ModuleTemplate.js +33 -1
- package/lib/ModuleTypeConstants.js +168 -0
- package/lib/ModuleWarning.js +10 -5
- package/lib/MultiCompiler.js +115 -38
- package/lib/MultiStats.js +75 -33
- package/lib/MultiWatching.js +6 -2
- package/lib/NodeStuffPlugin.js +136 -37
- package/lib/NormalModule.js +437 -194
- package/lib/NormalModuleFactory.js +313 -116
- package/lib/NormalModuleReplacementPlugin.js +10 -4
- package/lib/NullFactory.js +1 -1
- package/lib/OptimizationStages.js +3 -3
- package/lib/Parser.js +1 -1
- package/lib/PlatformPlugin.js +39 -0
- package/lib/PrefetchPlugin.js +4 -0
- package/lib/ProgressPlugin.js +83 -28
- package/lib/ProvidePlugin.js +37 -19
- package/lib/RawModule.js +18 -5
- package/lib/RecordIdsPlugin.js +8 -8
- package/lib/RequireJsStuffPlugin.js +22 -15
- package/lib/ResolverFactory.js +8 -4
- package/lib/RuntimeGlobals.js +99 -65
- package/lib/RuntimeModule.js +17 -15
- package/lib/RuntimePlugin.js +116 -13
- package/lib/RuntimeTemplate.js +304 -102
- package/lib/SelfModuleFactory.js +12 -0
- package/lib/SizeFormatHelpers.js +2 -4
- package/lib/SourceMapDevToolModuleOptionsPlugin.js +4 -0
- package/lib/SourceMapDevToolPlugin.js +89 -42
- package/lib/Stats.js +12 -7
- package/lib/Template.js +30 -33
- package/lib/TemplatedPathPlugin.js +102 -34
- package/lib/UseStrictPlugin.js +37 -12
- package/lib/WarnCaseSensitiveModulesPlugin.js +12 -0
- package/lib/WarnDeprecatedOptionPlugin.js +6 -0
- package/lib/WatchIgnorePlugin.js +46 -13
- package/lib/Watching.js +139 -76
- package/lib/WebpackError.js +14 -5
- package/lib/WebpackIsIncludedPlugin.js +22 -13
- package/lib/WebpackOptionsApply.js +162 -56
- package/lib/WebpackOptionsDefaulter.js +10 -3
- package/lib/asset/AssetGenerator.js +351 -99
- package/lib/asset/AssetModulesPlugin.js +57 -33
- package/lib/asset/AssetParser.js +15 -6
- package/lib/asset/AssetSourceGenerator.js +30 -10
- package/lib/asset/AssetSourceParser.js +8 -2
- package/lib/asset/RawDataUrlModule.js +162 -0
- package/lib/async-modules/AwaitDependenciesInitFragment.js +16 -13
- package/lib/async-modules/InferAsyncModulesPlugin.js +1 -1
- package/lib/buildChunkGraph.js +376 -420
- package/lib/cache/AddManagedPathsPlugin.js +6 -1
- package/lib/cache/IdleFileCachePlugin.js +26 -13
- package/lib/cache/MemoryCachePlugin.js +1 -1
- package/lib/cache/MemoryWithGcCachePlugin.js +13 -7
- package/lib/cache/PackFileCacheStrategy.js +172 -94
- package/lib/cache/ResolverCachePlugin.js +115 -43
- package/lib/cache/getLazyHashedEtag.js +2 -2
- package/lib/cache/mergeEtags.js +16 -21
- package/lib/cli.js +195 -110
- package/lib/config/browserslistTargetHandler.js +106 -41
- package/lib/config/defaults.js +572 -154
- package/lib/config/normalization.js +361 -322
- package/lib/config/target.js +105 -66
- package/lib/container/ContainerEntryDependency.js +2 -1
- package/lib/container/ContainerEntryModule.js +27 -11
- package/lib/container/ContainerEntryModuleFactory.js +1 -1
- package/lib/container/ContainerExposedDependency.js +9 -0
- package/lib/container/ContainerPlugin.js +18 -12
- package/lib/container/ContainerReferencePlugin.js +1 -1
- package/lib/container/FallbackDependency.js +13 -0
- package/lib/container/FallbackItemDependency.js +3 -0
- package/lib/container/FallbackModule.js +19 -8
- package/lib/container/FallbackModuleFactory.js +1 -1
- package/lib/container/ModuleFederationPlugin.js +2 -0
- package/lib/container/RemoteModule.js +17 -4
- package/lib/container/RemoteRuntimeModule.js +31 -17
- package/lib/container/RemoteToExternalDependency.js +3 -0
- package/lib/container/options.js +18 -4
- package/lib/css/CssExportsGenerator.js +203 -0
- package/lib/css/CssGenerator.js +151 -0
- package/lib/css/CssLoadingRuntimeModule.js +592 -0
- package/lib/css/CssModulesPlugin.js +888 -0
- package/lib/css/CssParser.js +1049 -0
- package/lib/css/walkCssTokens.js +775 -0
- package/lib/debug/ProfilingPlugin.js +102 -54
- package/lib/dependencies/AMDDefineDependency.js +54 -10
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +204 -61
- package/lib/dependencies/AMDPlugin.js +44 -24
- package/lib/dependencies/AMDRequireArrayDependency.js +34 -10
- package/lib/dependencies/AMDRequireContextDependency.js +15 -0
- package/lib/dependencies/AMDRequireDependenciesBlock.js +6 -0
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +185 -54
- package/lib/dependencies/AMDRequireDependency.js +21 -6
- package/lib/dependencies/AMDRequireItemDependency.js +6 -0
- package/lib/dependencies/AMDRuntimeModules.js +4 -4
- package/lib/dependencies/CachedConstDependency.js +22 -1
- package/lib/dependencies/CommonJsDependencyHelpers.js +16 -2
- package/lib/dependencies/CommonJsExportRequireDependency.js +77 -47
- package/lib/dependencies/CommonJsExportsDependency.js +28 -5
- package/lib/dependencies/CommonJsExportsParserPlugin.js +111 -39
- package/lib/dependencies/CommonJsFullRequireDependency.js +42 -8
- package/lib/dependencies/CommonJsImportsParserPlugin.js +530 -130
- package/lib/dependencies/CommonJsPlugin.js +51 -26
- package/lib/dependencies/CommonJsRequireContextDependency.js +23 -2
- package/lib/dependencies/CommonJsRequireDependency.js +9 -1
- package/lib/dependencies/CommonJsSelfReferenceDependency.js +22 -8
- package/lib/dependencies/ConstDependency.js +12 -3
- package/lib/dependencies/ContextDependency.js +32 -5
- package/lib/dependencies/ContextDependencyHelpers.js +92 -62
- package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +4 -1
- package/lib/dependencies/ContextElementDependency.js +41 -4
- package/lib/dependencies/CreateScriptUrlDependency.js +22 -1
- package/lib/dependencies/CriticalDependencyWarning.js +4 -1
- package/lib/dependencies/CssExportDependency.js +156 -0
- package/lib/dependencies/CssImportDependency.js +125 -0
- package/lib/dependencies/CssLocalIdentifierDependency.js +245 -0
- package/lib/dependencies/CssSelfLocalIdentifierDependency.js +111 -0
- package/lib/dependencies/CssUrlDependency.js +164 -0
- package/lib/dependencies/DelegatedSourceDependency.js +3 -0
- package/lib/dependencies/DllEntryDependency.js +14 -0
- package/lib/dependencies/DynamicExports.js +15 -11
- package/lib/dependencies/ExportsInfoDependency.js +26 -5
- package/lib/dependencies/ExternalModuleDependency.js +109 -0
- package/lib/dependencies/ExternalModuleInitFragment.js +133 -0
- package/lib/dependencies/HarmonyAcceptDependency.js +11 -2
- package/lib/dependencies/HarmonyAcceptImportDependency.js +9 -4
- package/lib/dependencies/HarmonyCompatibilityDependency.js +6 -5
- package/lib/dependencies/HarmonyDetectionParserPlugin.js +29 -3
- package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +152 -0
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +96 -51
- package/lib/dependencies/HarmonyExportExpressionDependency.js +21 -4
- package/lib/dependencies/HarmonyExportHeaderDependency.js +13 -0
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +216 -108
- package/lib/dependencies/HarmonyExportInitFragment.js +21 -9
- package/lib/dependencies/HarmonyExportSpecifierDependency.js +12 -0
- package/lib/dependencies/HarmonyExports.js +13 -7
- package/lib/dependencies/HarmonyImportDependency.js +65 -19
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +268 -74
- package/lib/dependencies/HarmonyImportSideEffectDependency.js +11 -5
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +180 -36
- package/lib/dependencies/HarmonyModulesPlugin.js +33 -5
- package/lib/dependencies/HarmonyTopLevelThisParserPlugin.js +15 -3
- package/lib/dependencies/ImportContextDependency.js +15 -2
- package/lib/dependencies/ImportDependency.js +50 -12
- package/lib/dependencies/ImportEagerDependency.js +11 -6
- package/lib/dependencies/ImportMetaContextDependency.js +42 -0
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +301 -0
- package/lib/dependencies/ImportMetaContextPlugin.js +72 -0
- package/lib/dependencies/ImportMetaHotAcceptDependency.js +6 -0
- package/lib/dependencies/ImportMetaHotDeclineDependency.js +6 -0
- package/lib/dependencies/ImportMetaPlugin.js +128 -59
- package/lib/dependencies/ImportParserPlugin.js +153 -83
- package/lib/dependencies/ImportPlugin.js +21 -7
- package/lib/dependencies/ImportWeakDependency.js +11 -6
- package/lib/dependencies/JsonExportsDependency.js +38 -30
- package/lib/dependencies/LoaderDependency.js +14 -0
- package/lib/dependencies/LoaderImportDependency.js +14 -0
- package/lib/dependencies/LoaderPlugin.js +54 -40
- package/lib/dependencies/LocalModule.js +17 -1
- package/lib/dependencies/LocalModuleDependency.js +15 -0
- package/lib/dependencies/LocalModulesHelpers.js +22 -4
- package/lib/dependencies/ModuleDecoratorDependency.js +9 -1
- package/lib/dependencies/ModuleDependency.js +24 -7
- package/lib/dependencies/ModuleDependencyTemplateAsId.js +2 -1
- package/lib/dependencies/ModuleHotAcceptDependency.js +6 -0
- package/lib/dependencies/ModuleHotDeclineDependency.js +6 -0
- package/lib/dependencies/PrefetchDependency.js +3 -0
- package/lib/dependencies/ProvidedDependency.js +43 -8
- package/lib/dependencies/PureExpressionDependency.js +73 -39
- package/lib/dependencies/RequireContextDependency.js +6 -16
- package/lib/dependencies/RequireContextDependencyParserPlugin.js +14 -6
- package/lib/dependencies/RequireContextPlugin.js +20 -7
- package/lib/dependencies/RequireEnsureDependenciesBlock.js +7 -0
- package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +29 -12
- package/lib/dependencies/RequireEnsureDependency.js +16 -2
- package/lib/dependencies/RequireEnsureItemDependency.js +3 -0
- package/lib/dependencies/RequireEnsurePlugin.js +27 -7
- package/lib/dependencies/RequireHeaderDependency.js +14 -1
- package/lib/dependencies/RequireIncludeDependency.js +6 -1
- package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +29 -5
- package/lib/dependencies/RequireIncludePlugin.js +25 -5
- package/lib/dependencies/RequireResolveContextDependency.js +19 -2
- package/lib/dependencies/RequireResolveDependency.js +8 -1
- package/lib/dependencies/RequireResolveHeaderDependency.js +18 -0
- package/lib/dependencies/RuntimeRequirementsDependency.js +9 -1
- package/lib/dependencies/StaticExportsDependency.js +8 -0
- package/lib/dependencies/SystemPlugin.js +49 -22
- package/lib/dependencies/SystemRuntimeModule.js +1 -1
- package/lib/dependencies/URLDependency.js +20 -13
- package/lib/dependencies/URLPlugin.js +115 -27
- package/lib/dependencies/UnsupportedDependency.js +13 -0
- package/lib/dependencies/WebAssemblyExportImportedDependency.js +14 -0
- package/lib/dependencies/WebAssemblyImportDependency.js +9 -1
- package/lib/dependencies/WebpackIsIncludedDependency.js +6 -1
- package/lib/dependencies/WorkerDependency.js +47 -3
- package/lib/dependencies/WorkerPlugin.js +143 -59
- package/lib/dependencies/getFunctionExpression.js +9 -0
- package/lib/dependencies/processExportInfo.js +3 -1
- package/lib/electron/ElectronTargetPlugin.js +1 -0
- package/lib/esm/ExportWebpackRequireRuntimeModule.js +3 -2
- package/lib/esm/ModuleChunkFormatPlugin.js +92 -55
- package/lib/esm/ModuleChunkLoadingPlugin.js +12 -1
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +141 -25
- package/lib/formatLocation.js +1 -2
- package/lib/hmr/HotModuleReplacement.runtime.js +37 -25
- package/lib/hmr/HotModuleReplacementRuntimeModule.js +2 -1
- package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +13 -15
- package/lib/hmr/LazyCompilationPlugin.js +94 -41
- package/lib/hmr/lazyCompilationBackend.js +107 -44
- package/lib/ids/ChunkModuleIdRangePlugin.js +12 -3
- package/lib/ids/DeterministicChunkIdsPlugin.js +13 -6
- package/lib/ids/DeterministicModuleIdsPlugin.js +59 -35
- package/lib/ids/HashedModuleIdsPlugin.js +24 -16
- package/lib/ids/IdHelpers.js +59 -49
- package/lib/ids/NamedChunkIdsPlugin.js +13 -1
- package/lib/ids/NamedModuleIdsPlugin.js +20 -12
- package/lib/ids/NaturalModuleIdsPlugin.js +10 -13
- package/lib/ids/OccurrenceChunkIdsPlugin.js +6 -2
- package/lib/ids/OccurrenceModuleIdsPlugin.js +14 -11
- package/lib/ids/SyncModuleIdsPlugin.js +146 -0
- package/lib/index.js +44 -5
- package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +9 -7
- package/lib/javascript/BasicEvaluatedExpression.js +133 -19
- package/lib/javascript/ChunkHelpers.js +33 -0
- package/lib/javascript/CommonJsChunkFormatPlugin.js +18 -15
- package/lib/javascript/EnableChunkLoadingPlugin.js +11 -6
- package/lib/javascript/JavascriptGenerator.js +37 -6
- package/lib/javascript/JavascriptModulesPlugin.js +523 -295
- package/lib/javascript/JavascriptParser.js +1591 -574
- package/lib/javascript/JavascriptParserHelpers.js +58 -37
- package/lib/javascript/StartupHelpers.js +69 -47
- package/lib/json/JsonData.js +33 -0
- package/lib/json/JsonGenerator.js +29 -21
- package/lib/json/JsonModulesPlugin.js +13 -7
- package/lib/json/JsonParser.js +30 -16
- package/lib/library/AbstractLibraryPlugin.js +6 -2
- package/lib/library/AmdLibraryPlugin.js +34 -18
- package/lib/library/AssignLibraryPlugin.js +68 -32
- package/lib/library/EnableLibraryPlugin.js +39 -14
- package/lib/library/ExportPropertyLibraryPlugin.js +14 -5
- package/lib/library/JsonpLibraryPlugin.js +4 -3
- package/lib/library/ModernModuleLibraryPlugin.js +144 -0
- package/lib/library/ModuleLibraryPlugin.js +12 -7
- package/lib/library/SystemLibraryPlugin.js +6 -4
- package/lib/library/UmdLibraryPlugin.js +119 -100
- package/lib/logging/Logger.js +59 -6
- package/lib/logging/createConsoleLogger.js +25 -40
- package/lib/logging/runtime.js +8 -9
- package/lib/logging/truncateArgs.js +9 -8
- package/lib/node/CommonJsChunkLoadingPlugin.js +18 -2
- package/lib/node/NodeEnvironmentPlugin.js +14 -8
- package/lib/node/NodeTargetPlugin.js +7 -0
- package/lib/node/NodeTemplatePlugin.js +10 -2
- package/lib/node/NodeWatchFileSystem.js +100 -50
- package/lib/node/ReadFileChunkLoadingRuntimeModule.js +51 -26
- package/lib/node/ReadFileCompileAsyncWasmPlugin.js +13 -2
- package/lib/node/ReadFileCompileWasmPlugin.js +21 -3
- package/lib/node/RequireChunkLoadingRuntimeModule.js +49 -26
- package/lib/node/nodeConsole.js +48 -31
- package/lib/optimize/AggressiveMergingPlugin.js +10 -4
- package/lib/optimize/AggressiveSplittingPlugin.js +26 -21
- package/lib/optimize/ConcatenatedModule.js +353 -212
- package/lib/optimize/EnsureChunkConditionsPlugin.js +4 -1
- package/lib/optimize/FlagIncludedChunksPlugin.js +14 -8
- package/lib/optimize/InnerGraph.js +30 -25
- package/lib/optimize/InnerGraphPlugin.js +105 -64
- package/lib/optimize/LimitChunkCountPlugin.js +32 -9
- package/lib/optimize/MangleExportsPlugin.js +7 -2
- package/lib/optimize/MinMaxSizeWarning.js +6 -1
- package/lib/optimize/ModuleConcatenationPlugin.js +150 -83
- package/lib/optimize/RealContentHashPlugin.js +99 -43
- package/lib/optimize/RemoveParentModulesPlugin.js +131 -48
- package/lib/optimize/RuntimeChunkPlugin.js +15 -2
- package/lib/optimize/SideEffectsFlagPlugin.js +119 -63
- package/lib/optimize/SplitChunksPlugin.js +129 -78
- package/lib/performance/SizeLimitsPlugin.js +22 -8
- package/lib/prefetch/ChunkPrefetchFunctionRuntimeModule.js +4 -2
- package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +4 -1
- package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +8 -5
- package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +5 -3
- package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +5 -3
- package/lib/rules/BasicEffectRulePlugin.js +7 -1
- package/lib/rules/BasicMatcherRulePlugin.js +8 -1
- package/lib/rules/ObjectMatcherRulePlugin.js +19 -2
- package/lib/rules/RuleSetCompiler.js +53 -32
- package/lib/rules/UseEffectRulePlugin.js +42 -36
- package/lib/runtime/AsyncModuleRuntimeModule.js +56 -69
- package/lib/runtime/AutoPublicPathRuntimeModule.js +25 -9
- package/lib/runtime/BaseUriRuntimeModule.js +35 -0
- package/lib/runtime/ChunkNameRuntimeModule.js +1 -1
- package/lib/runtime/CompatGetDefaultExportRuntimeModule.js +5 -2
- package/lib/runtime/CompatRuntimeModule.js +7 -2
- package/lib/runtime/CreateFakeNamespaceObjectRuntimeModule.js +7 -4
- package/lib/runtime/CreateScriptRuntimeModule.js +38 -0
- package/lib/runtime/CreateScriptUrlRuntimeModule.js +13 -36
- package/lib/runtime/DefinePropertyGettersRuntimeModule.js +6 -3
- package/lib/runtime/EnsureChunkRuntimeModule.js +29 -15
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +56 -43
- package/lib/runtime/GetFullHashRuntimeModule.js +4 -3
- package/lib/runtime/GetMainFilenameRuntimeModule.js +5 -2
- package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +98 -0
- package/lib/runtime/GlobalRuntimeModule.js +1 -1
- package/lib/runtime/HasOwnPropertyRuntimeModule.js +5 -2
- package/lib/runtime/LoadScriptRuntimeModule.js +61 -45
- package/lib/runtime/MakeNamespaceObjectRuntimeModule.js +5 -2
- package/lib/runtime/NonceRuntimeModule.js +24 -0
- package/lib/runtime/OnChunksLoadedRuntimeModule.js +4 -2
- package/lib/runtime/PublicPathRuntimeModule.js +9 -2
- package/lib/runtime/RelativeUrlRuntimeModule.js +5 -2
- package/lib/runtime/RuntimeIdRuntimeModule.js +6 -2
- package/lib/runtime/StartupChunkDependenciesPlugin.js +15 -0
- package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +36 -28
- package/lib/runtime/StartupEntrypointRuntimeModule.js +13 -9
- package/lib/runtime/SystemContextRuntimeModule.js +1 -1
- package/lib/schemes/DataUriPlugin.js +16 -3
- package/lib/schemes/HttpUriPlugin.js +336 -120
- package/lib/serialization/ArraySerializer.js +22 -6
- package/lib/serialization/BinaryMiddleware.js +212 -33
- package/lib/serialization/DateObjectSerializer.js +16 -4
- package/lib/serialization/ErrorObjectSerializer.js +23 -6
- package/lib/serialization/FileMiddleware.js +187 -86
- package/lib/serialization/MapObjectSerializer.js +25 -8
- package/lib/serialization/NullPrototypeObjectSerializer.js +26 -8
- package/lib/serialization/ObjectMiddleware.js +96 -66
- package/lib/serialization/PlainObjectSerializer.js +51 -14
- package/lib/serialization/RegExpObjectSerializer.js +17 -5
- package/lib/serialization/Serializer.js +23 -5
- package/lib/serialization/SerializerMiddleware.js +8 -8
- package/lib/serialization/SetObjectSerializer.js +22 -6
- package/lib/serialization/SingleItemMiddleware.js +2 -2
- package/lib/serialization/types.js +2 -2
- package/lib/sharing/ConsumeSharedFallbackDependency.js +3 -0
- package/lib/sharing/ConsumeSharedModule.js +40 -17
- package/lib/sharing/ConsumeSharedPlugin.js +139 -102
- package/lib/sharing/ConsumeSharedRuntimeModule.js +144 -130
- package/lib/sharing/ProvideForSharedDependency.js +0 -1
- package/lib/sharing/ProvideSharedDependency.js +17 -0
- package/lib/sharing/ProvideSharedModule.js +19 -6
- package/lib/sharing/ProvideSharedModuleFactory.js +1 -1
- package/lib/sharing/ProvideSharedPlugin.js +37 -30
- package/lib/sharing/SharePlugin.js +2 -2
- package/lib/sharing/ShareRuntimeModule.js +20 -10
- package/lib/sharing/resolveMatchedConfigs.js +6 -5
- package/lib/sharing/utils.js +338 -34
- package/lib/stats/DefaultStatsFactoryPlugin.js +660 -396
- package/lib/stats/DefaultStatsPresetPlugin.js +85 -25
- package/lib/stats/DefaultStatsPrinterPlugin.js +525 -145
- package/lib/stats/StatsFactory.js +128 -57
- package/lib/stats/StatsPrinter.js +77 -46
- package/lib/util/ArrayHelpers.js +35 -1
- package/lib/util/ArrayQueue.js +15 -22
- package/lib/util/AsyncQueue.js +37 -16
- package/lib/util/IterableHelpers.js +3 -4
- package/lib/util/LazyBucketSortedSet.js +60 -44
- package/lib/util/LazySet.js +11 -2
- package/lib/util/MapHelpers.js +17 -5
- package/lib/util/ParallelismFactorCalculator.js +11 -1
- package/lib/util/Queue.js +9 -3
- package/lib/util/Semaphore.js +4 -7
- package/lib/util/SetHelpers.js +5 -5
- package/lib/util/SortableSet.js +19 -6
- package/lib/util/StackedCacheMap.js +33 -3
- package/lib/util/StackedMap.js +1 -3
- package/lib/util/StringXor.js +46 -0
- package/lib/util/TupleQueue.js +9 -3
- package/lib/util/TupleSet.js +15 -5
- package/lib/util/URLAbsoluteSpecifier.js +8 -8
- package/lib/util/WeakTupleMap.js +70 -28
- package/lib/util/binarySearchBounds.js +51 -9
- package/lib/util/chainedImports.js +97 -0
- package/lib/util/cleverMerge.js +51 -36
- package/lib/util/comparators.js +146 -83
- package/lib/util/compileBooleanMatcher.js +35 -7
- package/lib/util/conventions.js +126 -0
- package/lib/util/create-schema-validation.js +9 -2
- package/lib/util/createHash.js +49 -14
- package/lib/util/deprecation.js +48 -15
- package/lib/util/deterministicGrouping.js +71 -39
- package/lib/util/extractUrlAndGlobal.js +3 -0
- package/lib/util/findGraphRoots.js +7 -5
- package/lib/util/fs.js +419 -94
- package/lib/util/hash/BatchedHash.js +10 -4
- package/lib/util/hash/md4.js +20 -0
- package/lib/util/hash/wasm-hash.js +163 -0
- package/lib/util/hash/xxhash64.js +7 -141
- package/lib/util/identifier.js +140 -93
- package/lib/util/internalSerializables.js +22 -0
- package/lib/util/makeSerializable.js +7 -0
- package/lib/util/memoize.js +10 -10
- package/lib/util/mergeScope.js +76 -0
- package/lib/util/nonNumericOnlyHash.js +22 -0
- package/lib/util/numberHash.js +84 -34
- package/lib/util/objectToMap.js +0 -1
- package/lib/util/processAsyncTree.js +7 -1
- package/lib/util/propertyAccess.js +7 -55
- package/lib/util/propertyName.js +77 -0
- package/lib/util/registerExternalSerializer.js +2 -2
- package/lib/util/runtime.js +188 -133
- package/lib/util/semver.js +64 -56
- package/lib/util/serialization.js +26 -1
- package/lib/util/smartGrouping.js +10 -10
- package/lib/util/source.js +1 -1
- package/lib/validateSchema.js +6 -2
- package/lib/wasm/EnableWasmLoadingPlugin.js +9 -4
- package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +70 -30
- package/lib/wasm-async/AsyncWebAssemblyGenerator.js +9 -1
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +34 -16
- package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +32 -12
- package/lib/wasm-async/AsyncWebAssemblyParser.js +17 -4
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +72 -31
- package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +17 -6
- package/lib/wasm-sync/WebAssemblyGenerator.js +72 -52
- package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +5 -4
- package/lib/wasm-sync/WebAssemblyModulesPlugin.js +53 -43
- package/lib/wasm-sync/WebAssemblyParser.js +23 -9
- package/lib/wasm-sync/WebAssemblyUtils.js +5 -4
- package/lib/web/FetchCompileAsyncWasmPlugin.js +11 -1
- package/lib/web/FetchCompileWasmPlugin.js +59 -42
- package/lib/web/JsonpChunkLoadingPlugin.js +9 -0
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +71 -41
- package/lib/webpack.js +43 -12
- package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +15 -12
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +55 -40
- package/module.d.ts +233 -0
- package/package.json +85 -139
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +679 -47
- package/schemas/plugins/BannerPlugin.check.js +1 -1
- package/schemas/plugins/BannerPlugin.json +9 -1
- package/schemas/plugins/DllReferencePlugin.check.js +1 -1
- package/schemas/plugins/HashedModuleIdsPlugin.check.js +1 -1
- package/schemas/plugins/ProgressPlugin.check.js +1 -1
- package/schemas/plugins/SourceMapDevToolPlugin.check.js +1 -1
- package/schemas/plugins/SourceMapDevToolPlugin.json +4 -0
- package/schemas/plugins/asset/AssetGeneratorOptions.check.js +1 -1
- package/schemas/plugins/asset/AssetInlineGeneratorOptions.check.js +1 -1
- package/schemas/plugins/asset/AssetParserOptions.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/ContainerPlugin.json +10 -1
- package/schemas/plugins/container/ContainerReferencePlugin.check.js +1 -1
- package/schemas/plugins/container/ContainerReferencePlugin.json +2 -0
- package/schemas/plugins/container/ExternalsType.check.js +1 -1
- package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
- package/schemas/plugins/container/ModuleFederationPlugin.json +12 -1
- package/schemas/plugins/css/CssAutoGeneratorOptions.check.d.ts +7 -0
- package/schemas/plugins/css/CssAutoGeneratorOptions.check.js +6 -0
- package/schemas/plugins/css/CssAutoGeneratorOptions.json +3 -0
- package/schemas/plugins/css/CssAutoParserOptions.check.d.ts +7 -0
- package/schemas/plugins/css/CssAutoParserOptions.check.js +6 -0
- package/schemas/plugins/css/CssAutoParserOptions.json +3 -0
- package/schemas/plugins/css/CssGeneratorOptions.check.d.ts +7 -0
- package/schemas/plugins/css/CssGeneratorOptions.check.js +6 -0
- package/schemas/plugins/css/CssGeneratorOptions.json +3 -0
- package/schemas/plugins/css/CssGlobalGeneratorOptions.check.d.ts +7 -0
- package/schemas/plugins/css/CssGlobalGeneratorOptions.check.js +6 -0
- package/schemas/plugins/css/CssGlobalGeneratorOptions.json +3 -0
- package/schemas/plugins/css/CssGlobalParserOptions.check.d.ts +7 -0
- package/schemas/plugins/css/CssGlobalParserOptions.check.js +6 -0
- package/schemas/plugins/css/CssGlobalParserOptions.json +3 -0
- package/schemas/plugins/css/CssModuleGeneratorOptions.check.d.ts +7 -0
- package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +6 -0
- package/schemas/plugins/css/CssModuleGeneratorOptions.json +3 -0
- package/schemas/plugins/css/CssModuleParserOptions.check.d.ts +7 -0
- package/schemas/plugins/css/CssModuleParserOptions.check.js +6 -0
- package/schemas/plugins/css/CssModuleParserOptions.json +3 -0
- package/schemas/plugins/css/CssParserOptions.check.d.ts +7 -0
- package/schemas/plugins/css/CssParserOptions.check.js +6 -0
- package/schemas/plugins/css/CssParserOptions.json +3 -0
- package/schemas/plugins/optimize/AggressiveSplittingPlugin.check.js +1 -1
- package/schemas/plugins/optimize/LimitChunkCountPlugin.check.js +1 -1
- package/schemas/plugins/optimize/MinChunkSizePlugin.check.js +1 -1
- package/schemas/plugins/schemes/HttpUriPlugin.check.js +1 -1
- package/schemas/plugins/schemes/HttpUriPlugin.json +4 -0
- package/schemas/plugins/sharing/SharePlugin.check.js +1 -1
- package/types.d.ts +5026 -1756
package/lib/config/defaults.js
CHANGED
@@ -7,6 +7,18 @@
|
|
7
7
|
|
8
8
|
const fs = require("fs");
|
9
9
|
const path = require("path");
|
10
|
+
const {
|
11
|
+
JAVASCRIPT_MODULE_TYPE_AUTO,
|
12
|
+
JSON_MODULE_TYPE,
|
13
|
+
WEBASSEMBLY_MODULE_TYPE_ASYNC,
|
14
|
+
JAVASCRIPT_MODULE_TYPE_ESM,
|
15
|
+
JAVASCRIPT_MODULE_TYPE_DYNAMIC,
|
16
|
+
WEBASSEMBLY_MODULE_TYPE_SYNC,
|
17
|
+
ASSET_MODULE_TYPE,
|
18
|
+
CSS_MODULE_TYPE_AUTO,
|
19
|
+
CSS_MODULE_TYPE,
|
20
|
+
CSS_MODULE_TYPE_MODULE
|
21
|
+
} = require("../ModuleTypeConstants");
|
10
22
|
const Template = require("../Template");
|
11
23
|
const { cleverMerge } = require("../util/cleverMerge");
|
12
24
|
const {
|
@@ -15,33 +27,54 @@ const {
|
|
15
27
|
getDefaultTarget
|
16
28
|
} = require("./target");
|
17
29
|
|
18
|
-
/** @typedef {import("../../declarations/WebpackOptions").
|
30
|
+
/** @typedef {import("../../declarations/WebpackOptions").CacheOptions} CacheOptions */
|
31
|
+
/** @typedef {import("../../declarations/WebpackOptions").CacheOptionsNormalized} CacheOptionsNormalized */
|
32
|
+
/** @typedef {import("../../declarations/WebpackOptions").Context} Context */
|
33
|
+
/** @typedef {import("../../declarations/WebpackOptions").CssGeneratorOptions} CssGeneratorOptions */
|
34
|
+
/** @typedef {import("../../declarations/WebpackOptions").CssParserOptions} CssParserOptions */
|
19
35
|
/** @typedef {import("../../declarations/WebpackOptions").EntryDescription} EntryDescription */
|
20
36
|
/** @typedef {import("../../declarations/WebpackOptions").EntryNormalized} Entry */
|
37
|
+
/** @typedef {import("../../declarations/WebpackOptions").EntryStaticNormalized} EntryStaticNormalized */
|
38
|
+
/** @typedef {import("../../declarations/WebpackOptions").Environment} Environment */
|
21
39
|
/** @typedef {import("../../declarations/WebpackOptions").Experiments} Experiments */
|
22
40
|
/** @typedef {import("../../declarations/WebpackOptions").ExperimentsNormalized} ExperimentsNormalized */
|
23
41
|
/** @typedef {import("../../declarations/WebpackOptions").ExternalsPresets} ExternalsPresets */
|
24
42
|
/** @typedef {import("../../declarations/WebpackOptions").ExternalsType} ExternalsType */
|
43
|
+
/** @typedef {import("../../declarations/WebpackOptions").FileCacheOptions} FileCacheOptions */
|
44
|
+
/** @typedef {import("../../declarations/WebpackOptions").GeneratorOptionsByModuleTypeKnown} GeneratorOptionsByModuleTypeKnown */
|
25
45
|
/** @typedef {import("../../declarations/WebpackOptions").InfrastructureLogging} InfrastructureLogging */
|
26
46
|
/** @typedef {import("../../declarations/WebpackOptions").JavascriptParserOptions} JavascriptParserOptions */
|
27
47
|
/** @typedef {import("../../declarations/WebpackOptions").Library} Library */
|
28
48
|
/** @typedef {import("../../declarations/WebpackOptions").LibraryName} LibraryName */
|
29
49
|
/** @typedef {import("../../declarations/WebpackOptions").LibraryOptions} LibraryOptions */
|
50
|
+
/** @typedef {import("../../declarations/WebpackOptions").LibraryType} LibraryType */
|
30
51
|
/** @typedef {import("../../declarations/WebpackOptions").Loader} Loader */
|
31
52
|
/** @typedef {import("../../declarations/WebpackOptions").Mode} Mode */
|
32
53
|
/** @typedef {import("../../declarations/WebpackOptions").ModuleOptionsNormalized} ModuleOptions */
|
33
54
|
/** @typedef {import("../../declarations/WebpackOptions").Node} WebpackNode */
|
34
55
|
/** @typedef {import("../../declarations/WebpackOptions").Optimization} Optimization */
|
56
|
+
/** @typedef {import("../../declarations/WebpackOptions").OptimizationSplitChunksOptions} OptimizationSplitChunksOptions */
|
35
57
|
/** @typedef {import("../../declarations/WebpackOptions").OutputNormalized} Output */
|
58
|
+
/** @typedef {import("../../declarations/WebpackOptions").ParserOptionsByModuleTypeKnown} ParserOptionsByModuleTypeKnown */
|
36
59
|
/** @typedef {import("../../declarations/WebpackOptions").Performance} Performance */
|
37
60
|
/** @typedef {import("../../declarations/WebpackOptions").ResolveOptions} ResolveOptions */
|
38
61
|
/** @typedef {import("../../declarations/WebpackOptions").RuleSetRules} RuleSetRules */
|
39
62
|
/** @typedef {import("../../declarations/WebpackOptions").SnapshotOptions} SnapshotOptions */
|
40
63
|
/** @typedef {import("../../declarations/WebpackOptions").Target} Target */
|
41
|
-
/** @typedef {import("../../declarations/WebpackOptions").
|
64
|
+
/** @typedef {import("../../declarations/WebpackOptions").WebpackOptions} WebpackOptions */
|
65
|
+
/** @typedef {import("../../declarations/WebpackOptions").WebpackOptionsNormalized} WebpackOptionsNormalized */
|
66
|
+
/** @typedef {import("../Compiler")} Compiler */
|
67
|
+
/** @typedef {import("../Module")} Module */
|
68
|
+
/** @typedef {import("./target").PlatformTargetProperties} PlatformTargetProperties */
|
42
69
|
/** @typedef {import("./target").TargetProperties} TargetProperties */
|
43
70
|
|
71
|
+
/**
|
72
|
+
* @typedef {object} ResolvedOptions
|
73
|
+
* @property {PlatformTargetProperties | false} platform - platform target properties
|
74
|
+
*/
|
75
|
+
|
44
76
|
const NODE_MODULES_REGEXP = /[\\/]node_modules[\\/]/i;
|
77
|
+
const DEFAULT_CACHE_NAME = "default";
|
45
78
|
|
46
79
|
/**
|
47
80
|
* Sets a constant default value when undefined
|
@@ -90,8 +123,8 @@ const A = (obj, prop, factory) => {
|
|
90
123
|
if (value === undefined) {
|
91
124
|
obj[prop] = factory();
|
92
125
|
} else if (Array.isArray(value)) {
|
93
|
-
/** @type {any[]} */
|
94
|
-
let newArray
|
126
|
+
/** @type {any[] | undefined} */
|
127
|
+
let newArray;
|
95
128
|
for (let i = 0; i < value.length; i++) {
|
96
129
|
const item = value[i];
|
97
130
|
if (item === "...") {
|
@@ -113,7 +146,7 @@ const A = (obj, prop, factory) => {
|
|
113
146
|
};
|
114
147
|
|
115
148
|
/**
|
116
|
-
* @param {
|
149
|
+
* @param {WebpackOptionsNormalized} options options to be modified
|
117
150
|
* @returns {void}
|
118
151
|
*/
|
119
152
|
const applyWebpackOptionsBaseDefaults = options => {
|
@@ -122,23 +155,27 @@ const applyWebpackOptionsBaseDefaults = options => {
|
|
122
155
|
};
|
123
156
|
|
124
157
|
/**
|
125
|
-
* @param {
|
126
|
-
* @
|
158
|
+
* @param {WebpackOptionsNormalized} options options to be modified
|
159
|
+
* @param {number} [compilerIndex] index of compiler
|
160
|
+
* @returns {ResolvedOptions} Resolved options after apply defaults
|
127
161
|
*/
|
128
|
-
const applyWebpackOptionsDefaults = options => {
|
162
|
+
const applyWebpackOptionsDefaults = (options, compilerIndex) => {
|
129
163
|
F(options, "context", () => process.cwd());
|
130
|
-
F(options, "target", () =>
|
131
|
-
|
132
|
-
|
164
|
+
F(options, "target", () =>
|
165
|
+
getDefaultTarget(/** @type {string} */ (options.context))
|
166
|
+
);
|
133
167
|
|
134
168
|
const { mode, name, target } = options;
|
135
169
|
|
136
|
-
|
170
|
+
const targetProperties =
|
137
171
|
target === false
|
138
172
|
? /** @type {false} */ (false)
|
139
173
|
: typeof target === "string"
|
140
|
-
|
141
|
-
|
174
|
+
? getTargetProperties(target, /** @type {Context} */ (options.context))
|
175
|
+
: getTargetsProperties(
|
176
|
+
/** @type {string[]} */ (target),
|
177
|
+
/** @type {Context} */ (options.context)
|
178
|
+
);
|
142
179
|
|
143
180
|
const development = mode === "development";
|
144
181
|
const production = mode === "production" || !mode;
|
@@ -160,20 +197,27 @@ const applyWebpackOptionsDefaults = options => {
|
|
160
197
|
D(options, "recordsInputPath", false);
|
161
198
|
D(options, "recordsOutputPath", false);
|
162
199
|
|
163
|
-
applyExperimentsDefaults(options.experiments, {
|
200
|
+
applyExperimentsDefaults(options.experiments, {
|
201
|
+
production,
|
202
|
+
development,
|
203
|
+
targetProperties
|
204
|
+
});
|
164
205
|
|
165
|
-
const futureDefaults =
|
206
|
+
const futureDefaults =
|
207
|
+
/** @type {NonNullable<ExperimentsNormalized["futureDefaults"]>} */
|
208
|
+
(options.experiments.futureDefaults);
|
166
209
|
|
167
210
|
F(options, "cache", () =>
|
168
211
|
development ? { type: /** @type {"memory"} */ ("memory") } : false
|
169
212
|
);
|
170
213
|
applyCacheDefaults(options.cache, {
|
171
|
-
name: name ||
|
214
|
+
name: name || DEFAULT_CACHE_NAME,
|
172
215
|
mode: mode || "production",
|
173
216
|
development,
|
174
|
-
cacheUnaffected: options.experiments.cacheUnaffected
|
217
|
+
cacheUnaffected: options.experiments.cacheUnaffected,
|
218
|
+
compilerIndex
|
175
219
|
});
|
176
|
-
const cache =
|
220
|
+
const cache = Boolean(options.cache);
|
177
221
|
|
178
222
|
applySnapshotDefaults(options.snapshot, {
|
179
223
|
production,
|
@@ -182,31 +226,47 @@ const applyWebpackOptionsDefaults = options => {
|
|
182
226
|
|
183
227
|
applyModuleDefaults(options.module, {
|
184
228
|
cache,
|
185
|
-
syncWebAssembly:
|
186
|
-
|
229
|
+
syncWebAssembly:
|
230
|
+
/** @type {NonNullable<ExperimentsNormalized["syncWebAssembly"]>} */
|
231
|
+
(options.experiments.syncWebAssembly),
|
232
|
+
asyncWebAssembly:
|
233
|
+
/** @type {NonNullable<ExperimentsNormalized["asyncWebAssembly"]>} */
|
234
|
+
(options.experiments.asyncWebAssembly),
|
235
|
+
css:
|
236
|
+
/** @type {NonNullable<ExperimentsNormalized["css"]>} */
|
237
|
+
(options.experiments.css),
|
238
|
+
futureDefaults,
|
239
|
+
isNode: targetProperties && targetProperties.node === true,
|
240
|
+
targetProperties
|
187
241
|
});
|
188
242
|
|
189
243
|
applyOutputDefaults(options.output, {
|
190
|
-
context: options.context,
|
244
|
+
context: /** @type {Context} */ (options.context),
|
191
245
|
targetProperties,
|
192
246
|
isAffectedByBrowserslist:
|
193
247
|
target === undefined ||
|
194
248
|
(typeof target === "string" && target.startsWith("browserslist")) ||
|
195
249
|
(Array.isArray(target) &&
|
196
250
|
target.some(target => target.startsWith("browserslist"))),
|
197
|
-
outputModule:
|
251
|
+
outputModule:
|
252
|
+
/** @type {NonNullable<ExperimentsNormalized["outputModule"]>} */
|
253
|
+
(options.experiments.outputModule),
|
198
254
|
development,
|
199
255
|
entry: options.entry,
|
200
|
-
module: options.module,
|
201
256
|
futureDefaults
|
202
257
|
});
|
203
258
|
|
204
259
|
applyExternalsPresetsDefaults(options.externalsPresets, {
|
205
260
|
targetProperties,
|
206
|
-
buildHttp:
|
261
|
+
buildHttp: Boolean(options.experiments.buildHttp)
|
207
262
|
});
|
208
263
|
|
209
|
-
applyLoaderDefaults(
|
264
|
+
applyLoaderDefaults(
|
265
|
+
/** @type {NonNullable<WebpackOptionsNormalized["loader"]>} */ (
|
266
|
+
options.loader
|
267
|
+
),
|
268
|
+
{ targetProperties, environment: options.output.environment }
|
269
|
+
);
|
210
270
|
|
211
271
|
F(options, "externalsType", () => {
|
212
272
|
const validExternalTypes = require("../../schemas/WebpackOptions.json")
|
@@ -215,12 +275,15 @@ const applyWebpackOptionsDefaults = options => {
|
|
215
275
|
validExternalTypes.includes(options.output.library.type)
|
216
276
|
? /** @type {ExternalsType} */ (options.output.library.type)
|
217
277
|
: options.output.module
|
218
|
-
|
219
|
-
|
278
|
+
? "module-import"
|
279
|
+
: "var";
|
220
280
|
});
|
221
281
|
|
222
282
|
applyNodeDefaults(options.node, {
|
223
|
-
futureDefaults:
|
283
|
+
futureDefaults:
|
284
|
+
/** @type {NonNullable<WebpackOptionsNormalized["experiments"]["futureDefaults"]>} */
|
285
|
+
(options.experiments.futureDefaults),
|
286
|
+
outputModule: options.output.module,
|
224
287
|
targetProperties
|
225
288
|
});
|
226
289
|
|
@@ -231,22 +294,32 @@ const applyWebpackOptionsDefaults = options => {
|
|
231
294
|
? {}
|
232
295
|
: false
|
233
296
|
);
|
234
|
-
applyPerformanceDefaults(
|
235
|
-
|
236
|
-
|
297
|
+
applyPerformanceDefaults(
|
298
|
+
/** @type {NonNullable<WebpackOptionsNormalized["performance"]>} */
|
299
|
+
(options.performance),
|
300
|
+
{
|
301
|
+
production
|
302
|
+
}
|
303
|
+
);
|
237
304
|
|
238
305
|
applyOptimizationDefaults(options.optimization, {
|
239
306
|
development,
|
240
307
|
production,
|
241
|
-
|
308
|
+
css:
|
309
|
+
/** @type {NonNullable<ExperimentsNormalized["css"]>} */
|
310
|
+
(options.experiments.css),
|
311
|
+
records: Boolean(options.recordsInputPath || options.recordsOutputPath)
|
242
312
|
});
|
243
313
|
|
244
314
|
options.resolve = cleverMerge(
|
245
315
|
getResolveDefaults({
|
246
316
|
cache,
|
247
|
-
context: options.context,
|
317
|
+
context: /** @type {Context} */ (options.context),
|
248
318
|
targetProperties,
|
249
|
-
mode: options.mode
|
319
|
+
mode: /** @type {Mode} */ (options.mode),
|
320
|
+
css:
|
321
|
+
/** @type {NonNullable<ExperimentsNormalized["css"]>} */
|
322
|
+
(options.experiments.css)
|
250
323
|
}),
|
251
324
|
options.resolve
|
252
325
|
);
|
@@ -255,26 +328,51 @@ const applyWebpackOptionsDefaults = options => {
|
|
255
328
|
getResolveLoaderDefaults({ cache }),
|
256
329
|
options.resolveLoader
|
257
330
|
);
|
331
|
+
|
332
|
+
return {
|
333
|
+
platform:
|
334
|
+
targetProperties === false
|
335
|
+
? targetProperties
|
336
|
+
: {
|
337
|
+
web: targetProperties.web,
|
338
|
+
browser: targetProperties.browser,
|
339
|
+
webworker: targetProperties.webworker,
|
340
|
+
node: targetProperties.node,
|
341
|
+
nwjs: targetProperties.nwjs,
|
342
|
+
electron: targetProperties.electron
|
343
|
+
}
|
344
|
+
};
|
258
345
|
};
|
259
346
|
|
260
347
|
/**
|
261
348
|
* @param {ExperimentsNormalized} experiments options
|
262
|
-
* @param {
|
349
|
+
* @param {object} options options
|
263
350
|
* @param {boolean} options.production is production
|
264
351
|
* @param {boolean} options.development is development mode
|
352
|
+
* @param {TargetProperties | false} options.targetProperties target properties
|
265
353
|
* @returns {void}
|
266
354
|
*/
|
267
|
-
const applyExperimentsDefaults = (
|
268
|
-
|
355
|
+
const applyExperimentsDefaults = (
|
356
|
+
experiments,
|
357
|
+
{ production, development, targetProperties }
|
358
|
+
) => {
|
359
|
+
D(experiments, "futureDefaults", false);
|
360
|
+
D(experiments, "backCompat", !experiments.futureDefaults);
|
269
361
|
D(experiments, "syncWebAssembly", false);
|
270
|
-
D(experiments, "asyncWebAssembly",
|
362
|
+
D(experiments, "asyncWebAssembly", experiments.futureDefaults);
|
271
363
|
D(experiments, "outputModule", false);
|
272
|
-
D(experiments, "asset", false);
|
273
364
|
D(experiments, "layers", false);
|
274
365
|
D(experiments, "lazyCompilation", undefined);
|
275
366
|
D(experiments, "buildHttp", undefined);
|
276
|
-
D(experiments, "futureDefaults", false);
|
277
367
|
D(experiments, "cacheUnaffected", experiments.futureDefaults);
|
368
|
+
F(experiments, "css", () => (experiments.futureDefaults ? true : undefined));
|
369
|
+
|
370
|
+
// TODO webpack 6: remove this. topLevelAwait should be enabled by default
|
371
|
+
let shouldEnableTopLevelAwait = true;
|
372
|
+
if (typeof experiments.topLevelAwait === "boolean") {
|
373
|
+
shouldEnableTopLevelAwait = experiments.topLevelAwait;
|
374
|
+
}
|
375
|
+
D(experiments, "topLevelAwait", shouldEnableTopLevelAwait);
|
278
376
|
|
279
377
|
if (typeof experiments.buildHttp === "object") {
|
280
378
|
D(experiments.buildHttp, "frozen", production);
|
@@ -283,31 +381,37 @@ const applyExperimentsDefaults = (experiments, { production, development }) => {
|
|
283
381
|
};
|
284
382
|
|
285
383
|
/**
|
286
|
-
* @param {
|
287
|
-
* @param {
|
384
|
+
* @param {CacheOptionsNormalized} cache options
|
385
|
+
* @param {object} options options
|
288
386
|
* @param {string} options.name name
|
289
|
-
* @param {
|
387
|
+
* @param {Mode} options.mode mode
|
290
388
|
* @param {boolean} options.development is development mode
|
291
|
-
* @param {
|
389
|
+
* @param {number} [options.compilerIndex] index of compiler
|
390
|
+
* @param {Experiments["cacheUnaffected"]} options.cacheUnaffected the cacheUnaffected experiment is enabled
|
292
391
|
* @returns {void}
|
293
392
|
*/
|
294
393
|
const applyCacheDefaults = (
|
295
394
|
cache,
|
296
|
-
{ name, mode, development, cacheUnaffected }
|
395
|
+
{ name, mode, development, cacheUnaffected, compilerIndex }
|
297
396
|
) => {
|
298
397
|
if (cache === false) return;
|
299
398
|
switch (cache.type) {
|
300
399
|
case "filesystem":
|
301
|
-
F(cache, "name", () =>
|
400
|
+
F(cache, "name", () =>
|
401
|
+
compilerIndex !== undefined
|
402
|
+
? `${`${name}-${mode}`}__compiler${compilerIndex + 1}__`
|
403
|
+
: `${name}-${mode}`
|
404
|
+
);
|
302
405
|
D(cache, "version", "");
|
303
406
|
F(cache, "cacheDirectory", () => {
|
304
407
|
const cwd = process.cwd();
|
408
|
+
/** @type {string | undefined} */
|
305
409
|
let dir = cwd;
|
306
410
|
for (;;) {
|
307
411
|
try {
|
308
412
|
if (fs.statSync(path.join(dir, "package.json")).isFile()) break;
|
309
413
|
// eslint-disable-next-line no-empty
|
310
|
-
} catch (
|
414
|
+
} catch (_err) {}
|
311
415
|
const parent = path.dirname(dir);
|
312
416
|
if (dir === parent) {
|
313
417
|
dir = undefined;
|
@@ -321,12 +425,15 @@ const applyCacheDefaults = (
|
|
321
425
|
return path.resolve(dir, ".pnp/.cache/webpack");
|
322
426
|
} else if (process.versions.pnp === "3") {
|
323
427
|
return path.resolve(dir, ".yarn/.cache/webpack");
|
324
|
-
} else {
|
325
|
-
return path.resolve(dir, "node_modules/.cache/webpack");
|
326
428
|
}
|
429
|
+
return path.resolve(dir, "node_modules/.cache/webpack");
|
327
430
|
});
|
328
431
|
F(cache, "cacheLocation", () =>
|
329
|
-
path.resolve(
|
432
|
+
path.resolve(
|
433
|
+
/** @type {NonNullable<FileCacheOptions["cacheDirectory"]>} */
|
434
|
+
(cache.cacheDirectory),
|
435
|
+
/** @type {NonNullable<FileCacheOptions["name"]>} */ (cache.name)
|
436
|
+
)
|
330
437
|
);
|
331
438
|
D(cache, "hashAlgorithm", "md4");
|
332
439
|
D(cache, "store", "pack");
|
@@ -339,9 +446,13 @@ const applyCacheDefaults = (
|
|
339
446
|
D(cache, "maxAge", 1000 * 60 * 60 * 24 * 60); // 1 month
|
340
447
|
D(cache, "allowCollectingMemory", development);
|
341
448
|
D(cache, "memoryCacheUnaffected", development && cacheUnaffected);
|
342
|
-
D(cache
|
343
|
-
|
344
|
-
|
449
|
+
D(cache, "readonly", false);
|
450
|
+
D(
|
451
|
+
/** @type {NonNullable<FileCacheOptions["buildDependencies"]>} */
|
452
|
+
(cache.buildDependencies),
|
453
|
+
"defaultWebpack",
|
454
|
+
[path.resolve(__dirname, "..") + path.sep]
|
455
|
+
);
|
345
456
|
break;
|
346
457
|
case "memory":
|
347
458
|
D(cache, "maxGenerations", Infinity);
|
@@ -352,7 +463,7 @@ const applyCacheDefaults = (
|
|
352
463
|
|
353
464
|
/**
|
354
465
|
* @param {SnapshotOptions} snapshot options
|
355
|
-
* @param {
|
466
|
+
* @param {object} options options
|
356
467
|
* @param {boolean} options.production is production
|
357
468
|
* @param {boolean} options.futureDefaults is future defaults enabled
|
358
469
|
* @returns {void}
|
@@ -363,7 +474,7 @@ const applySnapshotDefaults = (snapshot, { production, futureDefaults }) => {
|
|
363
474
|
process.versions.pnp === "3"
|
364
475
|
? [
|
365
476
|
/^(.+?(?:[\\/]\.yarn[\\/]unplugged[\\/][^\\/]+)?[\\/]node_modules[\\/])/
|
366
|
-
|
477
|
+
]
|
367
478
|
: [/^(.+?[\\/]node_modules[\\/])/]
|
368
479
|
);
|
369
480
|
F(snapshot, "immutablePaths", () =>
|
@@ -382,8 +493,7 @@ const applySnapshotDefaults = (snapshot, { production, futureDefaults }) => {
|
|
382
493
|
return [path.resolve(match[1], "unplugged")];
|
383
494
|
}
|
384
495
|
} else {
|
385
|
-
const match = /^(.+?[\\/]node_modules
|
386
|
-
// eslint-disable-next-line node/no-extraneous-require
|
496
|
+
const match = /^(.+?[\\/]node_modules[\\/])/.exec(
|
387
497
|
require.resolve("watchpack")
|
388
498
|
);
|
389
499
|
if (match) {
|
@@ -413,6 +523,7 @@ const applySnapshotDefaults = (snapshot, { production, futureDefaults }) => {
|
|
413
523
|
return [];
|
414
524
|
});
|
415
525
|
}
|
526
|
+
F(snapshot, "unmanagedPaths", () => []);
|
416
527
|
F(snapshot, "resolveBuildDependencies", () => ({
|
417
528
|
timestamp: true,
|
418
529
|
hash: true
|
@@ -428,9 +539,15 @@ const applySnapshotDefaults = (snapshot, { production, futureDefaults }) => {
|
|
428
539
|
|
429
540
|
/**
|
430
541
|
* @param {JavascriptParserOptions} parserOptions parser options
|
542
|
+
* @param {object} options options
|
543
|
+
* @param {boolean} options.futureDefaults is future defaults enabled
|
544
|
+
* @param {boolean} options.isNode is node target platform
|
431
545
|
* @returns {void}
|
432
546
|
*/
|
433
|
-
const applyJavascriptParserOptionsDefaults =
|
547
|
+
const applyJavascriptParserOptionsDefaults = (
|
548
|
+
parserOptions,
|
549
|
+
{ futureDefaults, isNode }
|
550
|
+
) => {
|
434
551
|
D(parserOptions, "unknownContextRequest", ".");
|
435
552
|
D(parserOptions, "unknownContextRegExp", false);
|
436
553
|
D(parserOptions, "unknownContextRecursive", true);
|
@@ -442,44 +559,148 @@ const applyJavascriptParserOptionsDefaults = parserOptions => {
|
|
442
559
|
D(parserOptions, "wrappedContextRegExp", /.*/);
|
443
560
|
D(parserOptions, "wrappedContextRecursive", true);
|
444
561
|
D(parserOptions, "wrappedContextCritical", false);
|
445
|
-
|
446
|
-
D(parserOptions, "strictExportPresence", false);
|
447
562
|
D(parserOptions, "strictThisContextOnImports", false);
|
563
|
+
D(parserOptions, "importMeta", true);
|
564
|
+
D(parserOptions, "dynamicImportMode", "lazy");
|
565
|
+
D(parserOptions, "dynamicImportPrefetch", false);
|
566
|
+
D(parserOptions, "dynamicImportPreload", false);
|
567
|
+
D(parserOptions, "dynamicImportFetchPriority", false);
|
568
|
+
D(parserOptions, "createRequire", isNode);
|
569
|
+
if (futureDefaults) D(parserOptions, "exportsPresence", "error");
|
570
|
+
};
|
571
|
+
|
572
|
+
/**
|
573
|
+
* @param {CssGeneratorOptions} generatorOptions generator options
|
574
|
+
* @param {object} options options
|
575
|
+
* @param {TargetProperties | false} options.targetProperties target properties
|
576
|
+
* @returns {void}
|
577
|
+
*/
|
578
|
+
const applyCssGeneratorOptionsDefaults = (
|
579
|
+
generatorOptions,
|
580
|
+
{ targetProperties }
|
581
|
+
) => {
|
582
|
+
D(
|
583
|
+
generatorOptions,
|
584
|
+
"exportsOnly",
|
585
|
+
!targetProperties || !targetProperties.document
|
586
|
+
);
|
587
|
+
D(generatorOptions, "esModule", true);
|
448
588
|
};
|
449
589
|
|
450
590
|
/**
|
451
591
|
* @param {ModuleOptions} module options
|
452
|
-
* @param {
|
592
|
+
* @param {object} options options
|
453
593
|
* @param {boolean} options.cache is caching enabled
|
454
594
|
* @param {boolean} options.syncWebAssembly is syncWebAssembly enabled
|
455
595
|
* @param {boolean} options.asyncWebAssembly is asyncWebAssembly enabled
|
596
|
+
* @param {boolean} options.css is css enabled
|
597
|
+
* @param {boolean} options.futureDefaults is future defaults enabled
|
598
|
+
* @param {boolean} options.isNode is node target platform
|
599
|
+
* @param {TargetProperties | false} options.targetProperties target properties
|
456
600
|
* @returns {void}
|
457
601
|
*/
|
458
602
|
const applyModuleDefaults = (
|
459
603
|
module,
|
460
|
-
{
|
604
|
+
{
|
605
|
+
cache,
|
606
|
+
syncWebAssembly,
|
607
|
+
asyncWebAssembly,
|
608
|
+
css,
|
609
|
+
futureDefaults,
|
610
|
+
isNode,
|
611
|
+
targetProperties
|
612
|
+
}
|
461
613
|
) => {
|
462
614
|
if (cache) {
|
463
|
-
D(
|
464
|
-
|
465
|
-
|
466
|
-
|
615
|
+
D(
|
616
|
+
module,
|
617
|
+
"unsafeCache",
|
618
|
+
/**
|
619
|
+
* @param {Module} module module
|
620
|
+
* @returns {boolean | null | string} true, if we want to cache the module
|
621
|
+
*/
|
622
|
+
module => {
|
623
|
+
const name = module.nameForCondition();
|
624
|
+
return name && NODE_MODULES_REGEXP.test(name);
|
625
|
+
}
|
626
|
+
);
|
467
627
|
} else {
|
468
628
|
D(module, "unsafeCache", false);
|
469
629
|
}
|
470
630
|
|
471
|
-
F(module.parser,
|
472
|
-
F(
|
473
|
-
|
474
|
-
|
631
|
+
F(module.parser, ASSET_MODULE_TYPE, () => ({}));
|
632
|
+
F(
|
633
|
+
/** @type {NonNullable<ParserOptionsByModuleTypeKnown["asset"]>} */
|
634
|
+
(module.parser.asset),
|
635
|
+
"dataUrlCondition",
|
636
|
+
() => ({})
|
637
|
+
);
|
638
|
+
if (
|
639
|
+
typeof (
|
640
|
+
/** @type {NonNullable<ParserOptionsByModuleTypeKnown["asset"]>} */
|
641
|
+
(module.parser.asset).dataUrlCondition
|
642
|
+
) === "object"
|
643
|
+
) {
|
644
|
+
D(
|
645
|
+
/** @type {NonNullable<ParserOptionsByModuleTypeKnown["asset"]>} */
|
646
|
+
(module.parser.asset).dataUrlCondition,
|
647
|
+
"maxSize",
|
648
|
+
8096
|
649
|
+
);
|
475
650
|
}
|
476
651
|
|
477
652
|
F(module.parser, "javascript", () => ({}));
|
478
|
-
|
653
|
+
|
654
|
+
applyJavascriptParserOptionsDefaults(
|
655
|
+
/** @type {NonNullable<ParserOptionsByModuleTypeKnown["javascript"]>} */
|
656
|
+
(module.parser.javascript),
|
657
|
+
{
|
658
|
+
futureDefaults,
|
659
|
+
isNode
|
660
|
+
}
|
661
|
+
);
|
662
|
+
|
663
|
+
if (css) {
|
664
|
+
F(module.parser, "css", () => ({}));
|
665
|
+
|
666
|
+
D(module.parser.css, "namedExports", true);
|
667
|
+
|
668
|
+
F(module.generator, "css", () => ({}));
|
669
|
+
|
670
|
+
applyCssGeneratorOptionsDefaults(
|
671
|
+
/** @type {NonNullable<GeneratorOptionsByModuleTypeKnown["css"]>} */
|
672
|
+
(module.generator.css),
|
673
|
+
{ targetProperties }
|
674
|
+
);
|
675
|
+
|
676
|
+
F(module.generator, "css/auto", () => ({}));
|
677
|
+
D(
|
678
|
+
module.generator["css/auto"],
|
679
|
+
"localIdentName",
|
680
|
+
"[uniqueName]-[id]-[local]"
|
681
|
+
);
|
682
|
+
D(module.generator["css/auto"], "exportsConvention", "as-is");
|
683
|
+
|
684
|
+
F(module.generator, "css/module", () => ({}));
|
685
|
+
D(
|
686
|
+
module.generator["css/module"],
|
687
|
+
"localIdentName",
|
688
|
+
"[uniqueName]-[id]-[local]"
|
689
|
+
);
|
690
|
+
D(module.generator["css/module"], "exportsConvention", "as-is");
|
691
|
+
|
692
|
+
F(module.generator, "css/global", () => ({}));
|
693
|
+
D(
|
694
|
+
module.generator["css/global"],
|
695
|
+
"localIdentName",
|
696
|
+
"[uniqueName]-[id]-[local]"
|
697
|
+
);
|
698
|
+
D(module.generator["css/global"], "exportsConvention", "as-is");
|
699
|
+
}
|
479
700
|
|
480
701
|
A(module, "defaultRules", () => {
|
481
702
|
const esm = {
|
482
|
-
type:
|
703
|
+
type: JAVASCRIPT_MODULE_TYPE_ESM,
|
483
704
|
resolve: {
|
484
705
|
byDependency: {
|
485
706
|
esm: {
|
@@ -489,21 +710,21 @@ const applyModuleDefaults = (
|
|
489
710
|
}
|
490
711
|
};
|
491
712
|
const commonjs = {
|
492
|
-
type:
|
713
|
+
type: JAVASCRIPT_MODULE_TYPE_DYNAMIC
|
493
714
|
};
|
494
715
|
/** @type {RuleSetRules} */
|
495
716
|
const rules = [
|
496
717
|
{
|
497
718
|
mimetype: "application/node",
|
498
|
-
type:
|
719
|
+
type: JAVASCRIPT_MODULE_TYPE_AUTO
|
499
720
|
},
|
500
721
|
{
|
501
722
|
test: /\.json$/i,
|
502
|
-
type:
|
723
|
+
type: JSON_MODULE_TYPE
|
503
724
|
},
|
504
725
|
{
|
505
726
|
mimetype: "application/json",
|
506
|
-
type:
|
727
|
+
type: JSON_MODULE_TYPE
|
507
728
|
},
|
508
729
|
{
|
509
730
|
test: /\.mjs$/i,
|
@@ -536,7 +757,7 @@ const applyModuleDefaults = (
|
|
536
757
|
];
|
537
758
|
if (asyncWebAssembly) {
|
538
759
|
const wasm = {
|
539
|
-
type:
|
760
|
+
type: WEBASSEMBLY_MODULE_TYPE_ASYNC,
|
540
761
|
rules: [
|
541
762
|
{
|
542
763
|
descriptionData: {
|
@@ -558,7 +779,7 @@ const applyModuleDefaults = (
|
|
558
779
|
});
|
559
780
|
} else if (syncWebAssembly) {
|
560
781
|
const wasm = {
|
561
|
-
type:
|
782
|
+
type: WEBASSEMBLY_MODULE_TYPE_SYNC,
|
562
783
|
rules: [
|
563
784
|
{
|
564
785
|
descriptionData: {
|
@@ -579,6 +800,27 @@ const applyModuleDefaults = (
|
|
579
800
|
...wasm
|
580
801
|
});
|
581
802
|
}
|
803
|
+
if (css) {
|
804
|
+
const resolve = {
|
805
|
+
fullySpecified: true,
|
806
|
+
preferRelative: true
|
807
|
+
};
|
808
|
+
rules.push({
|
809
|
+
test: /\.css$/i,
|
810
|
+
type: CSS_MODULE_TYPE_AUTO,
|
811
|
+
resolve
|
812
|
+
});
|
813
|
+
rules.push({
|
814
|
+
mimetype: "text/css+module",
|
815
|
+
type: CSS_MODULE_TYPE_MODULE,
|
816
|
+
resolve
|
817
|
+
});
|
818
|
+
rules.push({
|
819
|
+
mimetype: "text/css",
|
820
|
+
type: CSS_MODULE_TYPE,
|
821
|
+
resolve
|
822
|
+
});
|
823
|
+
}
|
582
824
|
rules.push(
|
583
825
|
{
|
584
826
|
dependency: "url",
|
@@ -594,7 +836,11 @@ const applyModuleDefaults = (
|
|
594
836
|
},
|
595
837
|
{
|
596
838
|
assert: { type: "json" },
|
597
|
-
type:
|
839
|
+
type: JSON_MODULE_TYPE
|
840
|
+
},
|
841
|
+
{
|
842
|
+
with: { type: "json" },
|
843
|
+
type: JSON_MODULE_TYPE
|
598
844
|
}
|
599
845
|
);
|
600
846
|
return rules;
|
@@ -603,14 +849,13 @@ const applyModuleDefaults = (
|
|
603
849
|
|
604
850
|
/**
|
605
851
|
* @param {Output} output options
|
606
|
-
* @param {
|
852
|
+
* @param {object} options options
|
607
853
|
* @param {string} options.context context
|
608
854
|
* @param {TargetProperties | false} options.targetProperties target properties
|
609
855
|
* @param {boolean} options.isAffectedByBrowserslist is affected by browserslist
|
610
856
|
* @param {boolean} options.outputModule is outputModule experiment enabled
|
611
857
|
* @param {boolean} options.development is development mode
|
612
858
|
* @param {Entry} options.entry entry option
|
613
|
-
* @param {ModuleOptions} options.module module option
|
614
859
|
* @param {boolean} options.futureDefaults is future defaults enabled
|
615
860
|
* @returns {void}
|
616
861
|
*/
|
@@ -623,7 +868,6 @@ const applyOutputDefaults = (
|
|
623
868
|
outputModule,
|
624
869
|
development,
|
625
870
|
entry,
|
626
|
-
module,
|
627
871
|
futureDefaults
|
628
872
|
}
|
629
873
|
) => {
|
@@ -638,7 +882,7 @@ const applyOutputDefaults = (
|
|
638
882
|
!Array.isArray(library) &&
|
639
883
|
"type" in library
|
640
884
|
? library.name
|
641
|
-
: /** @type {LibraryName
|
885
|
+
: /** @type {LibraryName} */ (library);
|
642
886
|
if (Array.isArray(libraryName)) {
|
643
887
|
return libraryName.join(".");
|
644
888
|
} else if (typeof libraryName === "object") {
|
@@ -650,28 +894,40 @@ const applyOutputDefaults = (
|
|
650
894
|
};
|
651
895
|
|
652
896
|
F(output, "uniqueName", () => {
|
653
|
-
const libraryName = getLibraryName(output.library)
|
897
|
+
const libraryName = getLibraryName(output.library).replace(
|
898
|
+
/^\[(\\*[\w:]+\\*)\](\.)|(\.)\[(\\*[\w:]+\\*)\](?=\.|$)|\[(\\*[\w:]+\\*)\]/g,
|
899
|
+
(m, a, d1, d2, b, c) => {
|
900
|
+
const content = a || b || c;
|
901
|
+
return content.startsWith("\\") && content.endsWith("\\")
|
902
|
+
? `${d2 || ""}[${content.slice(1, -1)}]${d1 || ""}`
|
903
|
+
: "";
|
904
|
+
}
|
905
|
+
);
|
654
906
|
if (libraryName) return libraryName;
|
655
907
|
const pkgPath = path.resolve(context, "package.json");
|
656
908
|
try {
|
657
909
|
const packageInfo = JSON.parse(fs.readFileSync(pkgPath, "utf-8"));
|
658
910
|
return packageInfo.name || "";
|
659
|
-
} catch (
|
660
|
-
if (
|
661
|
-
|
662
|
-
|
911
|
+
} catch (err) {
|
912
|
+
if (/** @type {Error & { code: string }} */ (err).code !== "ENOENT") {
|
913
|
+
/** @type {Error & { code: string }} */
|
914
|
+
(err).message +=
|
915
|
+
`\nwhile determining default 'output.uniqueName' from 'name' in ${pkgPath}`;
|
916
|
+
throw err;
|
663
917
|
}
|
664
918
|
return "";
|
665
919
|
}
|
666
920
|
});
|
667
921
|
|
668
|
-
F(output, "module", () =>
|
922
|
+
F(output, "module", () => Boolean(outputModule));
|
669
923
|
D(output, "filename", output.module ? "[name].mjs" : "[name].js");
|
670
924
|
F(output, "iife", () => !output.module);
|
671
925
|
D(output, "importFunctionName", "import");
|
672
926
|
D(output, "importMetaName", "import.meta");
|
673
927
|
F(output, "chunkFilename", () => {
|
674
|
-
const filename =
|
928
|
+
const filename =
|
929
|
+
/** @type {NonNullable<Output["chunkFilename"]>} */
|
930
|
+
(output.filename);
|
675
931
|
if (typeof filename !== "function") {
|
676
932
|
const hasName = filename.includes("[name]");
|
677
933
|
const hasId = filename.includes("[id]");
|
@@ -684,20 +940,34 @@ const applyOutputDefaults = (
|
|
684
940
|
}
|
685
941
|
return output.module ? "[id].mjs" : "[id].js";
|
686
942
|
});
|
943
|
+
F(output, "cssFilename", () => {
|
944
|
+
const filename =
|
945
|
+
/** @type {NonNullable<Output["cssFilename"]>} */
|
946
|
+
(output.filename);
|
947
|
+
if (typeof filename !== "function") {
|
948
|
+
return filename.replace(/\.[mc]?js(\?|$)/, ".css$1");
|
949
|
+
}
|
950
|
+
return "[id].css";
|
951
|
+
});
|
952
|
+
F(output, "cssChunkFilename", () => {
|
953
|
+
const chunkFilename =
|
954
|
+
/** @type {NonNullable<Output["cssChunkFilename"]>} */
|
955
|
+
(output.chunkFilename);
|
956
|
+
if (typeof chunkFilename !== "function") {
|
957
|
+
return chunkFilename.replace(/\.[mc]?js(\?|$)/, ".css$1");
|
958
|
+
}
|
959
|
+
return "[id].css";
|
960
|
+
});
|
961
|
+
D(output, "cssHeadDataCompression", !development);
|
687
962
|
D(output, "assetModuleFilename", "[hash][ext][query]");
|
688
963
|
D(output, "webassemblyModuleFilename", "[hash].module.wasm");
|
689
964
|
D(output, "compareBeforeEmit", true);
|
690
965
|
D(output, "charset", true);
|
691
|
-
|
692
|
-
|
693
|
-
"webpackHotUpdate" + Template.toIdentifier(output.uniqueName)
|
694
|
-
)
|
695
|
-
);
|
696
|
-
F(output, "chunkLoadingGlobal", () =>
|
697
|
-
Template.toIdentifier(
|
698
|
-
"webpackChunk" + Template.toIdentifier(output.uniqueName)
|
699
|
-
)
|
966
|
+
const uniqueNameId = Template.toIdentifier(
|
967
|
+
/** @type {NonNullable<Output["uniqueName"]>} */ (output.uniqueName)
|
700
968
|
);
|
969
|
+
F(output, "hotUpdateGlobal", () => `webpackHotUpdate${uniqueNameId}`);
|
970
|
+
F(output, "chunkLoadingGlobal", () => `webpackChunk${uniqueNameId}`);
|
701
971
|
F(output, "globalObject", () => {
|
702
972
|
if (tp) {
|
703
973
|
if (tp.global) return "global";
|
@@ -716,8 +986,9 @@ const applyOutputDefaults = (
|
|
716
986
|
throw new Error(
|
717
987
|
"For the selected environment is no default ESM chunk format available:\n" +
|
718
988
|
"ESM exports can be chosen when 'import()' is available.\n" +
|
719
|
-
|
720
|
-
|
989
|
+
`JSONP Array push can be chosen when 'document' is available.\n${
|
990
|
+
helpMessage
|
991
|
+
}`
|
721
992
|
);
|
722
993
|
} else {
|
723
994
|
if (tp.document) return "array-push";
|
@@ -727,8 +998,9 @@ const applyOutputDefaults = (
|
|
727
998
|
throw new Error(
|
728
999
|
"For the selected environment is no default script chunk format available:\n" +
|
729
1000
|
"JSONP Array push can be chosen when 'document' or 'importScripts' is available.\n" +
|
730
|
-
|
731
|
-
|
1001
|
+
`CommonJs exports can be chosen when 'require' or node builtins are available.\n${
|
1002
|
+
helpMessage
|
1003
|
+
}`
|
732
1004
|
);
|
733
1005
|
}
|
734
1006
|
}
|
@@ -736,6 +1008,7 @@ const applyOutputDefaults = (
|
|
736
1008
|
"Chunk format can't be selected by default when no target is specified"
|
737
1009
|
);
|
738
1010
|
});
|
1011
|
+
D(output, "asyncChunks", true);
|
739
1012
|
F(output, "chunkLoading", () => {
|
740
1013
|
if (tp) {
|
741
1014
|
switch (output.chunkFormat) {
|
@@ -748,7 +1021,7 @@ const applyOutputDefaults = (
|
|
748
1021
|
if (tp.nodeBuiltins) return "async-node";
|
749
1022
|
break;
|
750
1023
|
case "module":
|
751
|
-
if (tp.dynamicImport) return "import";
|
1024
|
+
if (tp.dynamicImport || output.module) return "import";
|
752
1025
|
break;
|
753
1026
|
}
|
754
1027
|
if (
|
@@ -773,7 +1046,7 @@ const applyOutputDefaults = (
|
|
773
1046
|
if (tp.nodeBuiltins) return "async-node";
|
774
1047
|
break;
|
775
1048
|
case "module":
|
776
|
-
if (tp.dynamicImportInWorker) return "import";
|
1049
|
+
if (tp.dynamicImportInWorker || output.module) return "import";
|
777
1050
|
break;
|
778
1051
|
}
|
779
1052
|
if (
|
@@ -820,28 +1093,110 @@ const applyOutputDefaults = (
|
|
820
1093
|
? "auto"
|
821
1094
|
: ""
|
822
1095
|
);
|
1096
|
+
D(output, "workerPublicPath", "");
|
823
1097
|
D(output, "chunkLoadTimeout", 120000);
|
824
1098
|
D(output, "hashFunction", futureDefaults ? "xxhash64" : "md4");
|
825
1099
|
D(output, "hashDigest", "hex");
|
826
|
-
D(output, "hashDigestLength", 20);
|
1100
|
+
D(output, "hashDigestLength", futureDefaults ? 16 : 20);
|
1101
|
+
D(output, "strictModuleErrorHandling", false);
|
827
1102
|
D(output, "strictModuleExceptionHandling", false);
|
828
1103
|
|
1104
|
+
const environment = /** @type {Environment} */ (output.environment);
|
1105
|
+
/**
|
1106
|
+
* @param {boolean | undefined} v value
|
1107
|
+
* @returns {boolean} true, when v is truthy or undefined
|
1108
|
+
*/
|
829
1109
|
const optimistic = v => v || v === undefined;
|
1110
|
+
/**
|
1111
|
+
* @param {boolean | undefined} v value
|
1112
|
+
* @param {boolean | undefined} c condition
|
1113
|
+
* @returns {boolean | undefined} true, when v is truthy or undefined, or c is truthy
|
1114
|
+
*/
|
1115
|
+
const conditionallyOptimistic = (v, c) => (v === undefined && c) || v;
|
1116
|
+
|
1117
|
+
F(
|
1118
|
+
environment,
|
1119
|
+
"globalThis",
|
1120
|
+
() => /** @type {boolean | undefined} */ (tp && tp.globalThis)
|
1121
|
+
);
|
1122
|
+
F(
|
1123
|
+
environment,
|
1124
|
+
"bigIntLiteral",
|
1125
|
+
() =>
|
1126
|
+
tp && optimistic(/** @type {boolean | undefined} */ (tp.bigIntLiteral))
|
1127
|
+
);
|
830
1128
|
F(
|
831
|
-
|
1129
|
+
environment,
|
1130
|
+
"const",
|
1131
|
+
() => tp && optimistic(/** @type {boolean | undefined} */ (tp.const))
|
1132
|
+
);
|
1133
|
+
F(
|
1134
|
+
environment,
|
832
1135
|
"arrowFunction",
|
833
|
-
() =>
|
1136
|
+
() =>
|
1137
|
+
tp && optimistic(/** @type {boolean | undefined} */ (tp.arrowFunction))
|
834
1138
|
);
|
835
|
-
F(output.environment, "const", () => tp && optimistic(tp.const));
|
836
1139
|
F(
|
837
|
-
|
1140
|
+
environment,
|
1141
|
+
"asyncFunction",
|
1142
|
+
() =>
|
1143
|
+
tp && optimistic(/** @type {boolean | undefined} */ (tp.asyncFunction))
|
1144
|
+
);
|
1145
|
+
F(
|
1146
|
+
environment,
|
1147
|
+
"forOf",
|
1148
|
+
() => tp && optimistic(/** @type {boolean | undefined} */ (tp.forOf))
|
1149
|
+
);
|
1150
|
+
F(
|
1151
|
+
environment,
|
838
1152
|
"destructuring",
|
839
|
-
() =>
|
1153
|
+
() =>
|
1154
|
+
tp && optimistic(/** @type {boolean | undefined} */ (tp.destructuring))
|
1155
|
+
);
|
1156
|
+
F(
|
1157
|
+
environment,
|
1158
|
+
"optionalChaining",
|
1159
|
+
() =>
|
1160
|
+
tp && optimistic(/** @type {boolean | undefined} */ (tp.optionalChaining))
|
1161
|
+
);
|
1162
|
+
F(
|
1163
|
+
environment,
|
1164
|
+
"nodePrefixForCoreModules",
|
1165
|
+
() =>
|
1166
|
+
tp &&
|
1167
|
+
optimistic(
|
1168
|
+
/** @type {boolean | undefined} */ (tp.nodePrefixForCoreModules)
|
1169
|
+
)
|
1170
|
+
);
|
1171
|
+
F(
|
1172
|
+
environment,
|
1173
|
+
"templateLiteral",
|
1174
|
+
() =>
|
1175
|
+
tp && optimistic(/** @type {boolean | undefined} */ (tp.templateLiteral))
|
1176
|
+
);
|
1177
|
+
F(environment, "dynamicImport", () =>
|
1178
|
+
conditionallyOptimistic(
|
1179
|
+
/** @type {boolean | undefined} */ (tp && tp.dynamicImport),
|
1180
|
+
output.module
|
1181
|
+
)
|
1182
|
+
);
|
1183
|
+
F(environment, "dynamicImportInWorker", () =>
|
1184
|
+
conditionallyOptimistic(
|
1185
|
+
/** @type {boolean | undefined} */ (tp && tp.dynamicImportInWorker),
|
1186
|
+
output.module
|
1187
|
+
)
|
1188
|
+
);
|
1189
|
+
F(environment, "module", () =>
|
1190
|
+
conditionallyOptimistic(
|
1191
|
+
/** @type {boolean | undefined} */ (tp && tp.module),
|
1192
|
+
output.module
|
1193
|
+
)
|
1194
|
+
);
|
1195
|
+
F(
|
1196
|
+
environment,
|
1197
|
+
"document",
|
1198
|
+
() => tp && optimistic(/** @type {boolean | undefined} */ (tp.document))
|
840
1199
|
);
|
841
|
-
F(output.environment, "forOf", () => tp && optimistic(tp.forOf));
|
842
|
-
F(output.environment, "bigIntLiteral", () => tp && tp.bigIntLiteral);
|
843
|
-
F(output.environment, "dynamicImport", () => tp && tp.dynamicImport);
|
844
|
-
F(output.environment, "module", () => tp && tp.module);
|
845
1200
|
|
846
1201
|
const { trustedTypes } = output;
|
847
1202
|
if (trustedTypes) {
|
@@ -849,8 +1204,10 @@ const applyOutputDefaults = (
|
|
849
1204
|
trustedTypes,
|
850
1205
|
"policyName",
|
851
1206
|
() =>
|
852
|
-
|
1207
|
+
/** @type {NonNullable<Output["uniqueName"]>} */
|
1208
|
+
(output.uniqueName).replace(/[^a-zA-Z0-9\-#=_/@.%]+/g, "_") || "webpack"
|
853
1209
|
);
|
1210
|
+
D(trustedTypes, "onPolicyCreationFailure", "stop");
|
854
1211
|
}
|
855
1212
|
|
856
1213
|
/**
|
@@ -859,10 +1216,11 @@ const applyOutputDefaults = (
|
|
859
1216
|
*/
|
860
1217
|
const forEachEntry = fn => {
|
861
1218
|
for (const name of Object.keys(entry)) {
|
862
|
-
fn(entry[name]);
|
1219
|
+
fn(/** @type {{[k: string] : EntryDescription}} */ (entry)[name]);
|
863
1220
|
}
|
864
1221
|
};
|
865
1222
|
A(output, "enabledLibraryTypes", () => {
|
1223
|
+
/** @type {LibraryType[]} */
|
866
1224
|
const enabledLibraryTypes = [];
|
867
1225
|
if (output.library) {
|
868
1226
|
enabledLibraryTypes.push(output.library.type);
|
@@ -910,7 +1268,7 @@ const applyOutputDefaults = (
|
|
910
1268
|
|
911
1269
|
/**
|
912
1270
|
* @param {ExternalsPresets} externalsPresets options
|
913
|
-
* @param {
|
1271
|
+
* @param {object} options options
|
914
1272
|
* @param {TargetProperties | false} options.targetProperties target properties
|
915
1273
|
* @param {boolean} options.buildHttp buildHttp experiment enabled
|
916
1274
|
* @returns {void}
|
@@ -922,45 +1280,67 @@ const applyExternalsPresetsDefaults = (
|
|
922
1280
|
D(
|
923
1281
|
externalsPresets,
|
924
1282
|
"web",
|
925
|
-
|
1283
|
+
/** @type {boolean | undefined} */
|
1284
|
+
(!buildHttp && targetProperties && targetProperties.web)
|
1285
|
+
);
|
1286
|
+
D(
|
1287
|
+
externalsPresets,
|
1288
|
+
"node",
|
1289
|
+
/** @type {boolean | undefined} */
|
1290
|
+
(targetProperties && targetProperties.node)
|
1291
|
+
);
|
1292
|
+
D(
|
1293
|
+
externalsPresets,
|
1294
|
+
"nwjs",
|
1295
|
+
/** @type {boolean | undefined} */
|
1296
|
+
(targetProperties && targetProperties.nwjs)
|
926
1297
|
);
|
927
|
-
D(externalsPresets, "node", targetProperties && targetProperties.node);
|
928
|
-
D(externalsPresets, "nwjs", targetProperties && targetProperties.nwjs);
|
929
1298
|
D(
|
930
1299
|
externalsPresets,
|
931
1300
|
"electron",
|
932
|
-
|
1301
|
+
/** @type {boolean | undefined} */
|
1302
|
+
(targetProperties && targetProperties.electron)
|
933
1303
|
);
|
934
1304
|
D(
|
935
1305
|
externalsPresets,
|
936
1306
|
"electronMain",
|
937
|
-
|
938
|
-
|
939
|
-
targetProperties
|
1307
|
+
/** @type {boolean | undefined} */
|
1308
|
+
(
|
1309
|
+
targetProperties &&
|
1310
|
+
targetProperties.electron &&
|
1311
|
+
targetProperties.electronMain
|
1312
|
+
)
|
940
1313
|
);
|
941
1314
|
D(
|
942
1315
|
externalsPresets,
|
943
1316
|
"electronPreload",
|
944
|
-
|
945
|
-
|
946
|
-
targetProperties
|
1317
|
+
/** @type {boolean | undefined} */
|
1318
|
+
(
|
1319
|
+
targetProperties &&
|
1320
|
+
targetProperties.electron &&
|
1321
|
+
targetProperties.electronPreload
|
1322
|
+
)
|
947
1323
|
);
|
948
1324
|
D(
|
949
1325
|
externalsPresets,
|
950
1326
|
"electronRenderer",
|
951
|
-
|
952
|
-
|
953
|
-
targetProperties
|
1327
|
+
/** @type {boolean | undefined} */
|
1328
|
+
(
|
1329
|
+
targetProperties &&
|
1330
|
+
targetProperties.electron &&
|
1331
|
+
targetProperties.electronRenderer
|
1332
|
+
)
|
954
1333
|
);
|
955
1334
|
};
|
956
1335
|
|
957
1336
|
/**
|
958
1337
|
* @param {Loader} loader options
|
959
|
-
* @param {
|
1338
|
+
* @param {object} options options
|
960
1339
|
* @param {TargetProperties | false} options.targetProperties target properties
|
1340
|
+
* @param {Environment} options.environment environment
|
961
1341
|
* @returns {void}
|
962
1342
|
*/
|
963
|
-
const applyLoaderDefaults = (loader, { targetProperties }) => {
|
1343
|
+
const applyLoaderDefaults = (loader, { targetProperties, environment }) => {
|
964
1344
|
F(loader, "target", () => {
|
965
1345
|
if (targetProperties) {
|
966
1346
|
if (targetProperties.electron) {
|
@@ -974,16 +1354,21 @@ const applyLoaderDefaults = (loader, { targetProperties }) => {
|
|
974
1354
|
if (targetProperties.web) return "web";
|
975
1355
|
}
|
976
1356
|
});
|
1357
|
+
D(loader, "environment", environment);
|
977
1358
|
};
|
978
1359
|
|
979
1360
|
/**
|
980
1361
|
* @param {WebpackNode} node options
|
981
|
-
* @param {
|
1362
|
+
* @param {object} options options
|
982
1363
|
* @param {TargetProperties | false} options.targetProperties target properties
|
983
1364
|
* @param {boolean} options.futureDefaults is future defaults enabled
|
1365
|
+
* @param {boolean} options.outputModule is output type is module
|
984
1366
|
* @returns {void}
|
985
1367
|
*/
|
986
|
-
const applyNodeDefaults = (
|
1368
|
+
const applyNodeDefaults = (
|
1369
|
+
node,
|
1370
|
+
{ futureDefaults, outputModule, targetProperties }
|
1371
|
+
) => {
|
987
1372
|
if (node === false) return;
|
988
1373
|
|
989
1374
|
F(node, "global", () => {
|
@@ -991,21 +1376,21 @@ const applyNodeDefaults = (node, { futureDefaults, targetProperties }) => {
|
|
991
1376
|
// TODO webpack 6 should always default to false
|
992
1377
|
return futureDefaults ? "warn" : true;
|
993
1378
|
});
|
994
|
-
|
995
|
-
|
996
|
-
|
997
|
-
|
998
|
-
});
|
999
|
-
F(node, "__dirname", () => {
|
1000
|
-
if (targetProperties && targetProperties.node) return "eval-only";
|
1379
|
+
|
1380
|
+
const handlerForNames = () => {
|
1381
|
+
if (targetProperties && targetProperties.node)
|
1382
|
+
return outputModule ? "node-module" : "eval-only";
|
1001
1383
|
// TODO webpack 6 should always default to false
|
1002
1384
|
return futureDefaults ? "warn-mock" : "mock";
|
1003
|
-
}
|
1385
|
+
};
|
1386
|
+
|
1387
|
+
F(node, "__filename", handlerForNames);
|
1388
|
+
F(node, "__dirname", handlerForNames);
|
1004
1389
|
};
|
1005
1390
|
|
1006
1391
|
/**
|
1007
1392
|
* @param {Performance} performance options
|
1008
|
-
* @param {
|
1393
|
+
* @param {object} options options
|
1009
1394
|
* @param {boolean} options.production is production
|
1010
1395
|
* @returns {void}
|
1011
1396
|
*/
|
@@ -1018,15 +1403,16 @@ const applyPerformanceDefaults = (performance, { production }) => {
|
|
1018
1403
|
|
1019
1404
|
/**
|
1020
1405
|
* @param {Optimization} optimization options
|
1021
|
-
* @param {
|
1406
|
+
* @param {object} options options
|
1022
1407
|
* @param {boolean} options.production is production
|
1023
1408
|
* @param {boolean} options.development is development
|
1409
|
+
* @param {boolean} options.css is css enabled
|
1024
1410
|
* @param {boolean} options.records using records
|
1025
1411
|
* @returns {void}
|
1026
1412
|
*/
|
1027
1413
|
const applyOptimizationDefaults = (
|
1028
1414
|
optimization,
|
1029
|
-
{ production, development, records }
|
1415
|
+
{ production, development, css, records }
|
1030
1416
|
) => {
|
1031
1417
|
D(optimization, "removeAvailableModules", false);
|
1032
1418
|
D(optimization, "removeEmptyChunks", true);
|
@@ -1077,7 +1463,9 @@ const applyOptimizationDefaults = (
|
|
1077
1463
|
});
|
1078
1464
|
const { splitChunks } = optimization;
|
1079
1465
|
if (splitChunks) {
|
1080
|
-
A(splitChunks, "defaultSizeTypes", () =>
|
1466
|
+
A(splitChunks, "defaultSizeTypes", () =>
|
1467
|
+
css ? ["javascript", "css", "unknown"] : ["javascript", "unknown"]
|
1468
|
+
);
|
1081
1469
|
D(splitChunks, "hidePathInfo", production);
|
1082
1470
|
D(splitChunks, "chunks", "async");
|
1083
1471
|
D(splitChunks, "usedExports", optimization.usedExports === true);
|
@@ -1088,7 +1476,9 @@ const applyOptimizationDefaults = (
|
|
1088
1476
|
F(splitChunks, "maxAsyncRequests", () => (production ? 30 : Infinity));
|
1089
1477
|
F(splitChunks, "maxInitialRequests", () => (production ? 30 : Infinity));
|
1090
1478
|
D(splitChunks, "automaticNameDelimiter", "-");
|
1091
|
-
const
|
1479
|
+
const cacheGroups =
|
1480
|
+
/** @type {NonNullable<OptimizationSplitChunksOptions["cacheGroups"]>} */
|
1481
|
+
(splitChunks.cacheGroups);
|
1092
1482
|
F(cacheGroups, "default", () => ({
|
1093
1483
|
idHint: "",
|
1094
1484
|
reuseExistingChunk: true,
|
@@ -1105,14 +1495,21 @@ const applyOptimizationDefaults = (
|
|
1105
1495
|
};
|
1106
1496
|
|
1107
1497
|
/**
|
1108
|
-
* @param {
|
1498
|
+
* @param {object} options options
|
1109
1499
|
* @param {boolean} options.cache is cache enable
|
1110
1500
|
* @param {string} options.context build context
|
1111
1501
|
* @param {TargetProperties | false} options.targetProperties target properties
|
1112
1502
|
* @param {Mode} options.mode mode
|
1503
|
+
* @param {boolean} options.css is css enabled
|
1113
1504
|
* @returns {ResolveOptions} resolve options
|
1114
1505
|
*/
|
1115
|
-
const getResolveDefaults = ({
|
1506
|
+
const getResolveDefaults = ({
|
1507
|
+
cache,
|
1508
|
+
context,
|
1509
|
+
targetProperties,
|
1510
|
+
mode,
|
1511
|
+
css
|
1512
|
+
}) => {
|
1116
1513
|
/** @type {string[]} */
|
1117
1514
|
const conditions = ["webpack"];
|
1118
1515
|
|
@@ -1158,6 +1555,7 @@ const getResolveDefaults = ({ cache, context, targetProperties, mode }) => {
|
|
1158
1555
|
exportsFields: ["exports"],
|
1159
1556
|
roots: [context],
|
1160
1557
|
mainFields: ["main"],
|
1558
|
+
importsFields: ["imports"],
|
1161
1559
|
byDependency: {
|
1162
1560
|
wasm: esmDeps(),
|
1163
1561
|
esm: esmDeps(),
|
@@ -1180,11 +1578,30 @@ const getResolveDefaults = ({ cache, context, targetProperties, mode }) => {
|
|
1180
1578
|
}
|
1181
1579
|
};
|
1182
1580
|
|
1581
|
+
if (css) {
|
1582
|
+
const styleConditions = [];
|
1583
|
+
|
1584
|
+
styleConditions.push("webpack");
|
1585
|
+
styleConditions.push(mode === "development" ? "development" : "production");
|
1586
|
+
styleConditions.push("style");
|
1587
|
+
|
1588
|
+
resolveOptions.byDependency["css-import"] = {
|
1589
|
+
// We avoid using any main files because we have to be consistent with CSS `@import`
|
1590
|
+
// and CSS `@import` does not handle `main` files in directories,
|
1591
|
+
// you should always specify the full URL for styles
|
1592
|
+
mainFiles: [],
|
1593
|
+
mainFields: ["style", "..."],
|
1594
|
+
conditionNames: styleConditions,
|
1595
|
+
extensions: [".css"],
|
1596
|
+
preferRelative: true
|
1597
|
+
};
|
1598
|
+
}
|
1599
|
+
|
1183
1600
|
return resolveOptions;
|
1184
1601
|
};
|
1185
1602
|
|
1186
1603
|
/**
|
1187
|
-
* @param {
|
1604
|
+
* @param {object} options options
|
1188
1605
|
* @param {boolean} options.cache is cache enable
|
1189
1606
|
* @returns {ResolveOptions} resolve options
|
1190
1607
|
*/
|
@@ -1217,5 +1634,6 @@ const applyInfrastructureLoggingDefaults = infrastructureLogging => {
|
|
1217
1634
|
D(infrastructureLogging, "appendOnly", !tty);
|
1218
1635
|
};
|
1219
1636
|
|
1220
|
-
exports.applyWebpackOptionsBaseDefaults =
|
1221
|
-
|
1637
|
+
module.exports.applyWebpackOptionsBaseDefaults =
|
1638
|
+
applyWebpackOptionsBaseDefaults;
|
1639
|
+
module.exports.applyWebpackOptionsDefaults = applyWebpackOptionsDefaults;
|