2023-09-19 21:26:15 +00:00
import { consola } from 'consola'
2022-02-25 19:11:01 +00:00
import { resolve } from 'pathe'
2023-04-27 10:31:52 +00:00
import { isTest } from 'std-env'
2022-07-21 10:44:33 +00:00
import { withoutLeadingSlash } from 'ufo'
2022-08-26 15:47:29 +00:00
import { defineUntypedSchema } from 'untyped'
2022-02-25 19:11:01 +00:00
2022-08-26 15:47:29 +00:00
export default defineUntypedSchema ( {
2022-02-25 19:11:01 +00:00
/ * *
* Configuration that will be passed directly to Vite .
*
* See https : //vitejs.dev/config for more information.
* Please note that not all vite options are supported in Nuxt .
2023-07-24 17:32:12 +00:00
* @type { typeof import ( '../src/types/config' ) . ViteConfig & { $client? : typeof import ( '../src/types/config' ) . ViteConfig , $server? : typeof import ( '../src/types/config' ) . ViteConfig } }
2022-02-25 19:11:01 +00:00
* /
vite : {
root : {
2022-09-12 18:22:41 +00:00
$resolve : async ( val , get ) = > val ? ? ( await get ( 'srcDir' ) )
2022-02-25 19:11:01 +00:00
} ,
mode : {
2022-09-12 18:22:41 +00:00
$resolve : async ( val , get ) = > val ? ? ( await get ( 'dev' ) ? 'development' : 'production' )
2022-02-25 19:11:01 +00:00
} ,
define : {
2024-01-29 16:53:25 +00:00
$resolve : async ( val : Record < string , any > | undefined , get ) = > {
const [ isDev , isDebug ] = await Promise . all ( [ get ( 'dev' ) , get ( 'debug' ) ] ) as [ boolean , boolean ]
2023-12-15 09:38:19 +00:00
return {
2023-12-20 10:30:33 +00:00
__VUE_PROD_HYDRATION_MISMATCH_DETAILS__ : isDebug ,
'process.dev' : isDev ,
'import.meta.dev' : isDev ,
2023-12-15 09:38:19 +00:00
'process.test' : isTest ,
'import.meta.test' : isTest ,
. . . val
}
}
2022-02-25 19:11:01 +00:00
} ,
resolve : {
2022-08-11 21:25:35 +00:00
extensions : [ '.mjs' , '.js' , '.ts' , '.jsx' , '.tsx' , '.json' , '.vue' ]
2022-02-25 19:11:01 +00:00
} ,
publicDir : {
2023-07-05 09:59:23 +00:00
$resolve : async ( val , get ) = > {
if ( val ) {
2023-10-18 10:59:43 +00:00
consola . warn ( 'Directly configuring the `vite.publicDir` option is not supported. Instead, set `dir.public`. You can read more in `https://nuxt.com/docs/api/nuxt-config#public`.' )
2023-07-05 09:59:23 +00:00
}
2024-01-29 16:53:25 +00:00
return val ? ? await Promise . all ( [ get ( 'srcDir' ) as Promise < string > , get ( 'dir' ) as Promise < Record < string , string > > ] ) . then ( ( [ srcDir , dir ] ) = > resolve ( srcDir , dir . public ) )
2023-07-05 09:59:23 +00:00
}
2022-02-25 19:11:01 +00:00
} ,
vue : {
isProduction : {
2022-09-12 18:22:41 +00:00
$resolve : async ( val , get ) = > val ? ? ! ( await get ( 'dev' ) )
2022-02-25 19:11:01 +00:00
} ,
2022-08-11 21:25:35 +00:00
template : {
compilerOptions : {
2024-01-29 16:53:25 +00:00
$resolve : async ( val , get ) = > val ? ? ( await get ( 'vue' ) as Record < string , any > ) . compilerOptions
2022-08-11 21:25:35 +00:00
}
2023-06-04 23:06:01 +00:00
} ,
script : {
propsDestructure : {
2024-01-29 16:53:25 +00:00
$resolve : async ( val , get ) = > val ? ? Boolean ( ( await get ( 'vue' ) as Record < string , any > ) . propsDestructure )
2023-08-08 20:55:29 +00:00
}
2022-08-11 21:25:35 +00:00
}
2022-02-25 19:11:01 +00:00
} ,
2023-02-16 12:45:08 +00:00
vueJsx : {
2024-01-29 16:53:25 +00:00
$resolve : async ( val : Record < string , any > , get ) = > {
2023-02-16 12:45:08 +00:00
return {
2024-01-29 16:53:25 +00:00
isCustomElement : ( await get ( 'vue' ) as Record < string , any > ) . compilerOptions ? . isCustomElement ,
2023-11-09 17:01:13 +00:00
. . . val
2023-02-16 12:45:08 +00:00
}
}
} ,
2022-02-25 19:11:01 +00:00
optimizeDeps : {
exclude : {
2024-01-29 16:53:25 +00:00
$resolve : async ( val : string [ ] | undefined , get ) = > [
2022-02-25 19:11:01 +00:00
. . . val || [ ] ,
2024-01-29 16:53:25 +00:00
. . . ( await get ( 'build.transpile' ) as Array < string | RegExp | ( ( ctx : { isClient ? : boolean ; isServer ? : boolean ; isDev : boolean } ) = > string | RegExp | false ) > ) . filter ( ( i ) = > typeof i === 'string' ) ,
2022-08-11 21:25:35 +00:00
'vue-demi'
]
}
2022-02-25 19:11:01 +00:00
} ,
esbuild : {
jsxFactory : 'h' ,
jsxFragment : 'Fragment' ,
tsconfigRaw : '{}'
} ,
2023-03-09 09:19:02 +00:00
clearScreen : true ,
2022-02-25 19:11:01 +00:00
build : {
assetsDir : {
2024-01-29 16:53:25 +00:00
$resolve : async ( val , get ) = > val ? ? withoutLeadingSlash ( ( await get ( 'app' ) as Record < string , string > ) . buildAssetsDir )
2022-02-25 19:11:01 +00:00
} ,
2022-08-11 21:25:35 +00:00
emptyOutDir : false
2022-02-25 19:11:01 +00:00
} ,
server : {
fs : {
allow : {
2024-01-29 16:53:25 +00:00
$resolve : async ( val : string [ ] | undefined , get ) = > {
const [ buildDir , srcDir , rootDir , workspaceDir , module sDir ] = await Promise . all ( [ get ( 'buildDir' ) , get ( 'srcDir' ) , get ( 'rootDir' ) , get ( 'workspaceDir' ) , get ( 'modulesDir' ) ] ) as [ string , string , string , string , string ]
2024-02-13 11:19:25 +00:00
return [ . . . new Set ( [
2023-12-15 14:16:35 +00:00
buildDir ,
srcDir ,
rootDir ,
workspaceDir ,
. . . ( module sDir ) ,
. . . val ? ? [ ]
2024-02-13 11:19:25 +00:00
] ) ]
2023-12-15 14:16:35 +00:00
}
2022-02-25 19:11:01 +00:00
}
}
}
}
2022-08-26 15:47:29 +00:00
} )