@@ -25,6 +25,7 @@ import {
2525 FS_PREFIX ,
2626} from './constants'
2727import type {
28+ FalsyPlugin ,
2829 HookHandler ,
2930 Plugin ,
3031 PluginOption ,
@@ -1002,7 +1003,7 @@ export async function resolveConfig(
10021003 mode = inlineConfig . mode || config . mode || mode
10031004 configEnv . mode = mode
10041005
1005- const filterPlugin = ( p : Plugin ) => {
1006+ const filterPlugin = ( p : Plugin | FalsyPlugin ) : p is Plugin => {
10061007 if ( ! p ) {
10071008 return false
10081009 } else if ( ! p . apply ) {
@@ -1015,9 +1016,9 @@ export async function resolveConfig(
10151016 }
10161017
10171018 // resolve plugins
1018- const rawPlugins = (
1019- ( await asyncFlatten ( config . plugins || [ ] ) ) as Plugin [ ]
1020- ) . filter ( filterPlugin )
1019+ const rawPlugins = ( await asyncFlatten ( config . plugins || [ ] ) ) . filter (
1020+ filterPlugin ,
1021+ )
10211022
10221023 const [ prePlugins , normalPlugins , postPlugins ] = sortUserPlugins ( rawPlugins )
10231024
@@ -1068,12 +1069,12 @@ export async function resolveConfig(
10681069 // Backward compatibility: server.warmup.clientFiles/ssrFiles -> environment.dev.warmup
10691070 const warmupOptions = config . server ?. warmup
10701071 if ( warmupOptions ?. clientFiles ) {
1071- configEnvironmentsClient . dev . warmup = warmupOptions ? .clientFiles
1072+ configEnvironmentsClient . dev . warmup = warmupOptions . clientFiles
10721073 }
10731074 if ( warmupOptions ?. ssrFiles ) {
10741075 configEnvironmentsSsr ??= { }
10751076 configEnvironmentsSsr . dev ??= { }
1076- configEnvironmentsSsr . dev . warmup = warmupOptions ? .ssrFiles
1077+ configEnvironmentsSsr . dev . warmup = warmupOptions . ssrFiles
10771078 }
10781079
10791080 // Backward compatibility: merge ssr into environments.ssr.config as defaults
@@ -1102,11 +1103,7 @@ export async function resolveConfig(
11021103 }
11031104
11041105 // The client and ssr environment configs can't be removed by the user in the config hook
1105- if (
1106- ! config . environments ||
1107- ! config . environments . client ||
1108- ( ! config . environments . ssr && ! isBuild )
1109- ) {
1106+ if ( ! config . environments . client || ( ! config . environments . ssr && ! isBuild ) ) {
11101107 throw new Error (
11111108 'Required environments configuration were stripped out in the config hook' ,
11121109 )
@@ -1244,7 +1241,7 @@ export async function resolveConfig(
12441241 ? ! isBuild || config . build ?. ssr
12451242 ? '/'
12461243 : './'
1247- : ( resolveBaseUrl ( config . base , isBuild , logger ) ?? configDefaults . base )
1244+ : resolveBaseUrl ( config . base , isBuild , logger )
12481245
12491246 // resolve cache directory
12501247 const pkgDir = findNearestPackageData ( resolvedRoot , packageCache ) ?. dir
@@ -1301,7 +1298,7 @@ export async function resolveConfig(
13011298 // And Plugins may also have cached that could be corrupted by being used in these extra rollup calls.
13021299 // So we need to separate the worker plugin from the plugin that vite needs to run.
13031300 const rawWorkerUserPlugins = (
1304- ( await asyncFlatten ( createUserWorkerPlugins ?.( ) || [ ] ) ) as Plugin [ ]
1301+ await asyncFlatten ( createUserWorkerPlugins ?.( ) || [ ] )
13051302 ) . filter ( filterPlugin )
13061303
13071304 // resolve worker
@@ -1577,7 +1574,7 @@ assetFileNames isn't equal for every build.rollupOptions.output. A single patter
15771574 * electron or expects to deploy
15781575 */
15791576export function resolveBaseUrl (
1580- base : UserConfig [ 'base' ] = '/' ,
1577+ base : UserConfig [ 'base' ] = configDefaults . base ,
15811578 isBuild : boolean ,
15821579 logger : Logger ,
15831580) : string {
@@ -1846,7 +1843,7 @@ async function bundleConfigFile(
18461843 const { text } = result . outputFiles [ 0 ]
18471844 return {
18481845 code : text ,
1849- dependencies : result . metafile ? Object . keys ( result . metafile . inputs ) : [ ] ,
1846+ dependencies : Object . keys ( result . metafile . inputs ) ,
18501847 }
18511848}
18521849
@@ -1934,11 +1931,9 @@ async function runConfigHook(
19341931 for ( const p of getSortedPluginsByHook ( 'config' , plugins ) ) {
19351932 const hook = p . config
19361933 const handler = getHookHandler ( hook )
1937- if ( handler ) {
1938- const res = await handler ( conf , configEnv )
1939- if ( res && res !== conf ) {
1940- conf = mergeConfig ( conf , res )
1941- }
1934+ const res = await handler ( conf , configEnv )
1935+ if ( res && res !== conf ) {
1936+ conf = mergeConfig ( conf , res )
19421937 }
19431938 }
19441939
@@ -1955,15 +1950,13 @@ async function runConfigEnvironmentHook(
19551950 for ( const p of getSortedPluginsByHook ( 'configEnvironment' , plugins ) ) {
19561951 const hook = p . configEnvironment
19571952 const handler = getHookHandler ( hook )
1958- if ( handler ) {
1959- for ( const name of environmentNames ) {
1960- const res = await handler ( name , environments [ name ] , {
1961- ...configEnv ,
1962- isSsrTargetWebworker : isSsrTargetWebworkerSet && name === 'ssr' ,
1963- } )
1964- if ( res ) {
1965- environments [ name ] = mergeConfig ( environments [ name ] , res )
1966- }
1953+ for ( const name of environmentNames ) {
1954+ const res = await handler ( name , environments [ name ] , {
1955+ ...configEnv ,
1956+ isSsrTargetWebworker : isSsrTargetWebworkerSet && name === 'ssr' ,
1957+ } )
1958+ if ( res ) {
1959+ environments [ name ] = mergeConfig ( environments [ name ] , res )
19671960 }
19681961 }
19691962 }
@@ -1977,7 +1970,7 @@ function optimizeDepsDisabledBackwardCompatibility(
19771970 const optimizeDepsDisabled = optimizeDeps . disabled
19781971 if ( optimizeDepsDisabled !== undefined ) {
19791972 if ( optimizeDepsDisabled === true || optimizeDepsDisabled === 'dev' ) {
1980- const commonjsOptionsInclude = resolved . build ? .commonjsOptions ? .include
1973+ const commonjsOptionsInclude = resolved . build . commonjsOptions . include
19811974 const commonjsPluginDisabled =
19821975 Array . isArray ( commonjsOptionsInclude ) &&
19831976 commonjsOptionsInclude . length === 0
0 commit comments