2022-10-27 10:36:37 +00:00
import { defineUntypedSchema } from 'untyped'
2023-01-30 12:09:48 +00:00
import { defu } from 'defu'
2022-02-21 11:25:31 +00:00
import { join } from 'pathe'
2023-03-07 12:18:47 +00:00
import { isTest } from 'std-env'
2023-09-19 21:26:15 +00:00
import { consola } from 'consola'
2021-03-28 20:14:04 +00:00
2022-08-26 15:47:29 +00:00
export default defineUntypedSchema ( {
2021-04-15 18:49:29 +00:00
/ * *
2022-02-25 19:11:01 +00:00
* The builder to use for bundling the Vue part of your application .
* @type { 'vite' | 'webpack' | { bundle : ( nuxt : typeof import ( '../src/types/nuxt' ) . Nuxt ) = > Promise < void > } }
2021-04-15 18:49:29 +00:00
* /
2022-02-25 19:11:01 +00:00
builder : {
2024-01-29 16:53:25 +00:00
$resolve : async ( val : 'vite' | 'webpack' | { bundle : ( nuxt : unknown ) = > Promise < void > } | undefined = 'vite' , get ) = > {
2022-02-25 19:11:01 +00:00
if ( typeof val === 'object' ) {
return val
2022-02-21 11:25:31 +00:00
}
2022-08-26 15:47:29 +00:00
const map : Record < string , string > = {
2022-02-25 19:11:01 +00:00
vite : '@nuxt/vite-builder' ,
2024-04-05 18:08:32 +00:00
webpack : '@nuxt/webpack-builder' ,
2022-02-21 11:25:31 +00:00
}
2022-09-13 10:57:14 +00:00
return map [ val ] || val || ( await get ( 'vite' ) === false ? map.webpack : map.vite )
2024-04-05 18:08:32 +00:00
} ,
2022-02-21 11:25:31 +00:00
} ,
2022-10-27 10:36:37 +00:00
2022-04-22 15:35:42 +00:00
/ * *
* Whether to generate sourcemaps .
2023-08-24 12:06:44 +00:00
* @type { boolean | { server? : boolean | 'hidden' , client? : boolean | 'hidden' } }
2022-04-22 15:35:42 +00:00
* /
2022-09-07 11:32:10 +00:00
sourcemap : {
2024-01-29 16:53:25 +00:00
$resolve : async ( val : boolean | { server? : boolean | 'hidden' , client? : boolean | 'hidden' } | undefined , get ) = > {
2022-09-07 11:32:10 +00:00
if ( typeof val === 'boolean' ) {
return { server : val , client : val }
}
return defu ( val , {
server : true ,
2024-04-05 18:08:32 +00:00
client : await get ( 'dev' ) ,
2022-09-07 11:32:10 +00:00
} )
2024-04-05 18:08:32 +00:00
} ,
2022-09-07 11:32:10 +00:00
} ,
2022-10-27 10:36:37 +00:00
2023-03-07 12:18:47 +00:00
/ * *
* Log level when building logs .
*
* Defaults to 'silent' when running in CI or when a TTY is not available .
* This option is then used as 'silent' in Vite and 'none' in Webpack
* @type { 'silent' | 'info' | 'verbose' }
* /
logLevel : {
2024-01-29 16:53:25 +00:00
$resolve : ( val : string | undefined ) = > {
2023-03-07 12:18:47 +00:00
if ( val && ! [ 'silent' , 'info' , 'verbose' ] . includes ( val ) ) {
2023-09-19 21:26:15 +00:00
consola . warn ( ` Invalid \` logLevel \` option: \` ${ val } \` . Must be one of: \` silent \` , \` info \` , \` verbose \` . ` )
2023-03-07 12:18:47 +00:00
}
return val ? ? ( isTest ? 'silent' : 'info' )
2024-04-05 18:08:32 +00:00
} ,
2023-03-07 12:18:47 +00:00
} ,
2022-04-01 13:02:26 +00:00
/ * *
* Shared build configuration .
2021-04-15 18:49:29 +00:00
* /
2022-04-01 13:02:26 +00:00
build : {
2022-02-25 19:11:01 +00:00
/ * *
* If you want to transpile specific dependencies with Babel , you can add them here .
* Each item in transpile can be a package name , a function , a string or regex object matching the
* dependency ' s file name .
2021-04-15 18:49:29 +00:00
*
2022-02-25 19:11:01 +00:00
* You can also use a function to conditionally transpile . The function will receive an object ( { isDev , isServer , isClient , isModern , isLegacy } ) .
2021-04-15 18:49:29 +00:00
* @example
* ` ` ` js
2023-03-07 09:30:05 +00:00
transpile : [ ( { isLegacy } ) = > isLegacy && 'ky' ]
2021-04-15 18:49:29 +00:00
* ` ` `
2023-01-19 10:56:34 +00:00
* @type { Array < string | RegExp | ( ( ctx : { isClient ? : boolean ; isServer ? : boolean ; isDev : boolean } ) = > string | RegExp | false ) > }
2021-04-15 18:49:29 +00:00
* /
2022-02-25 19:11:01 +00:00
transpile : {
2024-04-05 18:08:32 +00:00
$resolve : ( val : Array < string | RegExp | ( ( ctx : { isClient ? : boolean , isServer ? : boolean , isDev : boolean } ) = > string | RegExp | false ) > | undefined ) = > ( val || [ ] ) . filter ( Boolean ) ,
2022-02-25 19:11:01 +00:00
} ,
2021-04-15 18:49:29 +00:00
2022-02-25 19:11:01 +00:00
/ * *
* You can provide your own templates which will be rendered based
* on Nuxt configuration . This feature is specially useful for using with module s.
2021-04-15 18:49:29 +00:00
*
2023-06-05 21:52:43 +00:00
* Templates are rendered using [ ` lodash/template ` ] ( https : //lodash.com/docs/4.17.15#template).
2021-04-15 18:49:29 +00:00
* @example
* ` ` ` js
2022-02-25 19:11:01 +00:00
* templates : [
* {
* src : '~/modules/support/plugin.js' , // `src` can be absolute or relative
* dst : 'support.js' , // `dst` is relative to project `.nuxt` dir
* options : {
* // Options are provided to template as `options` key
* live_chat : false
2021-08-11 21:48:33 +00:00
* }
* }
2022-02-25 19:11:01 +00:00
* ]
2021-04-15 18:49:29 +00:00
* ` ` `
2023-06-08 21:50:29 +00:00
* @type { typeof import ( '../src/types/nuxt' ) . NuxtTemplate < any > [ ] }
2021-04-15 18:49:29 +00:00
* /
2022-02-25 19:11:01 +00:00
templates : [ ] ,
2021-03-28 20:14:04 +00:00
2023-03-07 09:30:05 +00:00
/ * *
2023-10-23 11:19:16 +00:00
* Nuxt allows visualizing your bundles and how to optimize them .
2022-02-25 19:11:01 +00:00
*
2022-10-27 10:36:37 +00:00
* Set to ` true ` to enable bundle analysis , or pass an object with options : [ for webpack ] ( https : //github.com/webpack-contrib/webpack-bundle-analyzer#options-for-plugin) or [for vite](https://github.com/btd/rollup-plugin-visualizer#options).
2022-02-25 19:11:01 +00:00
* @example
* ` ` ` js
2022-10-27 10:36:37 +00:00
* analyze : {
* analyzerMode : 'static'
* }
2022-02-25 19:11:01 +00:00
* ` ` `
2023-10-23 11:19:16 +00:00
* @type { boolean | { enabled? : boolean } & ( ( 0 extends 1 & typeof import ( 'webpack-bundle-analyzer' ) . BundleAnalyzerPlugin . Options ? { } : typeof import ( 'webpack-bundle-analyzer' ) . BundleAnalyzerPlugin . Options ) | typeof import ( 'rollup-plugin-visualizer' ) . PluginVisualizerOptions ) }
2022-02-25 19:11:01 +00:00
* /
2023-03-07 09:30:05 +00:00
analyze : {
2024-01-29 16:53:25 +00:00
$resolve : async ( val : boolean | { enabled? : boolean } | Record < string , unknown > , get ) = > {
const [ rootDir , analyzeDir ] = await Promise . all ( [ get ( 'rootDir' ) , get ( 'analyzeDir' ) ] ) as [ string , string ]
2023-10-23 11:19:16 +00:00
return defu ( typeof val === 'boolean' ? { enabled : val } : val , {
2022-10-27 10:36:37 +00:00
template : 'treemap' ,
projectRoot : rootDir ,
2024-04-05 18:08:32 +00:00
filename : join ( analyzeDir , '{name}.html' ) ,
2023-10-23 11:19:16 +00:00
} )
2024-04-05 18:08:32 +00:00
} ,
} ,
2023-03-07 09:30:05 +00:00
} ,
/ * *
* Build time optimization configuration .
* /
optimization : {
2023-03-07 21:06:15 +00:00
/ * *
* Functions to inject a key for .
*
* As long as the number of arguments passed to the function is less than ` argumentLength ` , an
* additional magic string will be injected that can be used to deduplicate requests between server
* and client . You will need to take steps to handle this additional key .
*
* The key will be unique based on the location of the function being invoked within the file .
2023-06-05 19:15:12 +00:00
* @type { Array < { name : string , source? : string | RegExp , argumentLength : number } > }
2023-03-07 21:06:15 +00:00
* /
keyedComposables : {
2024-01-29 16:53:25 +00:00
$resolve : ( val : Array < { name : string , argumentLength : string } > | undefined ) = > [
2024-01-30 09:10:13 +00:00
{ name : 'useId' , argumentLength : 1 } ,
2023-12-19 11:00:11 +00:00
{ name : 'callOnce' , argumentLength : 2 } ,
2023-06-05 18:36:26 +00:00
{ name : 'defineNuxtComponent' , argumentLength : 2 } ,
2023-03-07 21:06:15 +00:00
{ name : 'useState' , argumentLength : 2 } ,
{ name : 'useFetch' , argumentLength : 3 } ,
{ name : 'useAsyncData' , argumentLength : 3 } ,
{ name : 'useLazyAsyncData' , argumentLength : 3 } ,
2024-01-29 16:53:25 +00:00
{ name : 'useLazyFetch' , argumentLength : 3 } ,
2024-04-05 18:08:32 +00:00
. . . val || [ ] ,
] . filter ( Boolean ) ,
2023-03-07 21:06:15 +00:00
} ,
2023-03-07 09:30:05 +00:00
/ * *
* Tree shake code from specific builds .
* /
treeShake : {
/ * *
* Tree shake composables from the server or client builds .
* @example
* ` ` ` js
* treeShake : { client : { myPackage : [ 'useServerOnlyComposable' ] } }
* ` ` `
* /
composables : {
server : {
$resolve : async ( val , get ) = > defu ( val || { } ,
2023-08-08 20:55:29 +00:00
await get ( 'dev' )
? { }
: {
2024-05-03 09:13:54 +00:00
'vue' : [ 'onMounted' , 'onUpdated' , 'onUnmounted' , 'onBeforeMount' , 'onBeforeUpdate' , 'onBeforeUnmount' , 'onRenderTracked' , 'onRenderTriggered' , 'onActivated' , 'onDeactivated' ] ,
2024-04-05 18:08:32 +00:00
'#app' : [ 'definePayloadReviver' , 'definePageMeta' ] ,
} ,
) ,
2023-03-07 09:30:05 +00:00
} ,
client : {
$resolve : async ( val , get ) = > defu ( val || { } ,
2023-08-08 20:55:29 +00:00
await get ( 'dev' )
? { }
: {
2024-05-03 09:13:54 +00:00
'vue' : [ 'onRenderTracked' , 'onRenderTriggered' , 'onServerPrefetch' ] ,
2024-05-07 14:04:21 +00:00
'#app' : [ 'definePayloadReducer' , 'definePageMeta' , 'onPrehydrate' ] ,
2024-04-05 18:08:32 +00:00
} ,
) ,
} ,
} ,
2023-03-07 09:30:05 +00:00
} ,
2023-04-10 21:57:13 +00:00
/ * *
* Options passed directly to the transformer from ` unctx ` that preserves async context
* after ` await ` .
2023-07-05 17:32:37 +00:00
* @type { typeof import ( 'unctx/transform' ) . TransformerOptions }
2023-04-10 21:57:13 +00:00
* /
asyncTransforms : {
asyncFunctions : [ 'defineNuxtPlugin' , 'defineNuxtRouteMiddleware' ] ,
objectDefinitions : {
defineNuxtComponent : [ 'asyncData' , 'setup' ] ,
2023-04-11 11:58:43 +00:00
defineNuxtPlugin : [ 'setup' ] ,
2024-04-05 18:08:32 +00:00
definePageMeta : [ 'middleware' , 'validate' ] ,
} ,
} ,
} ,
2022-08-26 15:47:29 +00:00
} )