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 : {
2022-09-12 18:22:41 +00:00
$resolve : async ( val , get ) = > ( {
'process.dev' : await get ( 'dev' ) ,
2023-08-10 08:51:58 +00:00
'import.meta.dev' : await get ( 'dev' ) ,
2023-04-27 10:31:52 +00:00
'process.test' : isTest ,
2023-08-10 08:51:58 +00:00
'import.meta.test' : isTest ,
2022-02-25 19:11:01 +00:00
. . . val || { }
} )
} ,
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 ) {
console . warn ( 'Directly configuring the `vite.publicDir` option is not supported. Instead, set `dir.public`. You can read more in `https://nuxt.com/docs/api/configuration/nuxt-config#public`.' )
}
return val ? ? resolve ( ( await get ( 'srcDir' ) ) , ( await get ( 'dir' ) ) . public )
}
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 : {
2022-09-12 18:22:41 +00:00
$resolve : async ( val , get ) = > val ? ? ( await get ( 'vue' ) ) . compilerOptions
2022-08-11 21:25:35 +00:00
}
2023-06-04 23:06:01 +00:00
} ,
script : {
propsDestructure : {
2023-08-08 20:55:29 +00:00
$resolve : async ( val , get ) = > val ? ? Boolean ( ( await get ( 'vue' ) ) . propsDestructure )
2023-06-04 23:06:01 +00:00
} ,
defineModel : {
2023-08-08 20:55:29 +00:00
$resolve : async ( val , get ) = > val ? ? Boolean ( ( await get ( 'vue' ) ) . defineModel )
}
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 : {
$resolve : async ( val , get ) = > {
return {
isCustomElement : ( await get ( 'vue' ) ) . compilerOptions ? . isCustomElement ,
. . . ( val || { } )
}
}
} ,
2022-02-25 19:11:01 +00:00
optimizeDeps : {
exclude : {
2022-09-12 18:22:41 +00:00
$resolve : async ( val , get ) = > [
2022-02-25 19:11:01 +00:00
. . . val || [ ] ,
2022-09-12 18:22:41 +00:00
. . . ( await get ( 'build.transpile' ) ) . filter ( ( i : string ) = > 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 : {
2022-09-12 18:22:41 +00:00
$resolve : async ( val , get ) = > val ? ? withoutLeadingSlash ( ( await get ( 'app' ) ) . 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 : {
2022-09-12 18:22:41 +00:00
$resolve : async ( val , get ) = > [
await get ( 'buildDir' ) ,
await get ( 'srcDir' ) ,
await get ( 'rootDir' ) ,
2022-11-03 22:03:15 +00:00
await get ( 'workspaceDir' ) ,
2022-09-12 18:22:41 +00:00
. . . ( await get ( 'modulesDir' ) ) ,
2022-02-25 19:11:01 +00:00
. . . val ? ? [ ]
]
}
}
}
}
2022-08-26 15:47:29 +00:00
} )