2023-09-19 21:26:15 +00:00
import { consola } from 'consola'
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 : {
2024-04-05 18:08:32 +00:00
$resolve : async ( val , get ) = > val ? ? ( await get ( 'srcDir' ) ) ,
2022-02-25 19:11:01 +00:00
} ,
mode : {
2024-04-05 18:08:32 +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 {
2024-04-05 18:08:32 +00:00
'__VUE_PROD_HYDRATION_MISMATCH_DETAILS__' : isDebug ,
2023-12-20 10:30:33 +00:00
'process.dev' : isDev ,
'import.meta.dev' : isDev ,
2023-12-15 09:38:19 +00:00
'process.test' : isTest ,
'import.meta.test' : isTest ,
2024-04-05 18:08:32 +00:00
. . . val ,
2023-12-15 09:38:19 +00:00
}
2024-04-05 18:08:32 +00:00
} ,
2022-02-25 19:11:01 +00:00
} ,
resolve : {
2024-04-05 18:08:32 +00:00
extensions : [ '.mjs' , '.js' , '.ts' , '.jsx' , '.tsx' , '.json' , '.vue' ] ,
2022-02-25 19:11:01 +00:00
} ,
publicDir : {
2024-03-14 00:18:44 +00:00
$resolve : ( val ) = > {
2023-07-05 09:59:23 +00:00
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-03-14 00:18:44 +00:00
return false
2024-04-05 18:08:32 +00:00
} ,
2022-02-25 19:11:01 +00:00
} ,
vue : {
isProduction : {
2024-04-05 18:08:32 +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-04-05 18:08:32 +00:00
$resolve : async ( val , get ) = > val ? ? ( await get ( 'vue' ) as Record < string , any > ) . compilerOptions ,
2024-04-03 09:16:15 +00:00
} ,
transformAssetUrls : {
2024-04-05 18:08:32 +00:00
$resolve : async ( val , get ) = > val ? ? ( await get ( 'vue' ) as Record < string , any > ) . transformAssetUrls ,
} ,
2023-06-04 23:06:01 +00:00
} ,
script : {
propsDestructure : {
2024-04-05 18:08:32 +00:00
$resolve : async ( val , get ) = > val ? ? Boolean ( ( await get ( 'vue' ) as Record < string , any > ) . propsDestructure ) ,
2024-04-03 09:16:15 +00:00
} ,
hoistStatic : {
2024-04-05 18:08:32 +00:00
$resolve : async ( val , get ) = > val ? ? ( await get ( 'vue' ) as Record < string , any > ) . compilerOptions ? . hoistStatic ,
} ,
} ,
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 ,
2024-04-05 18:08:32 +00:00
. . . val ,
2023-02-16 12:45:08 +00:00
}
2024-04-05 18:08:32 +00:00
} ,
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-04-05 18:08:32 +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' ) ,
'vue-demi' ,
] ,
} ,
2022-02-25 19:11:01 +00:00
} ,
esbuild : {
jsxFactory : 'h' ,
jsxFragment : 'Fragment' ,
2024-04-05 18:08:32 +00:00
tsconfigRaw : '{}' ,
2022-02-25 19:11:01 +00:00
} ,
2023-03-09 09:19:02 +00:00
clearScreen : true ,
2022-02-25 19:11:01 +00:00
build : {
assetsDir : {
2024-04-05 18:08:32 +00:00
$resolve : async ( val , get ) = > val ? ? withoutLeadingSlash ( ( await get ( 'app' ) as Record < string , string > ) . buildAssetsDir ) ,
2022-02-25 19:11:01 +00:00
} ,
2024-04-05 18:08:32 +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 ) ,
2024-04-05 18:08:32 +00:00
. . . val ? ? [ ] ,
2024-02-13 11:19:25 +00:00
] ) ]
2024-04-05 18:08:32 +00:00
} ,
} ,
} ,
} ,
} ,
2022-08-26 15:47:29 +00:00
} )