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'
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 .
2021-04-15 18:49:29 +00:00
*
2022-02-25 19:11:01 +00:00
* @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 : {
2022-09-12 18:22:41 +00:00
$resolve : async ( val , 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' ,
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 )
2022-08-11 21:25:35 +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 .
*
2022-09-07 11:32:10 +00:00
* @type { boolean | { server? : boolean , client? : boolean } }
2022-04-22 15:35:42 +00:00
* /
2022-09-07 11:32:10 +00:00
sourcemap : {
2022-09-12 18:22:41 +00:00
$resolve : async ( val , get ) = > {
2022-09-07 11:32:10 +00:00
if ( typeof val === 'boolean' ) {
return { server : val , client : val }
}
return defu ( val , {
server : true ,
2022-09-12 18:22:41 +00:00
client : await get ( 'dev' )
2022-09-07 11:32:10 +00:00
} )
} ,
} ,
2022-10-27 10:36:37 +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 : {
$resolve : val = > [ ] . concat ( val ) . filter ( Boolean )
} ,
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
*
2022-02-25 19:11:01 +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
* ` ` `
* /
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
/ * *
2022-10-27 10:36:37 +00:00
* Nuxt uses ` webpack-bundle-analyzer ` to visualize 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
* ` ` `
2022-10-27 10:36:37 +00:00
* @type { boolean | 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 : {
2022-10-27 10:36:37 +00:00
$resolve : async ( val , get ) = > {
if ( val !== true ) {
return val ? ? false
}
const rootDir = await get ( 'rootDir' )
return {
template : 'treemap' ,
projectRoot : rootDir ,
filename : join ( rootDir , '.nuxt/stats' , '{name}.html' )
}
2022-02-25 19:11:01 +00:00
}
} ,
2023-03-07 09:30:05 +00:00
} ,
/ * *
* Build time optimization configuration .
* /
optimization : {
/ * *
* 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 || { } ,
await get ( 'dev' ) ? { } : {
vue : [ 'onBeforeMount' , 'onMounted' , 'onBeforeUpdate' , 'onRenderTracked' , 'onRenderTriggered' , 'onActivated' , 'onDeactivated' , 'onBeforeUnmount' ] ,
}
)
} ,
client : {
$resolve : async ( val , get ) = > defu ( val || { } ,
await get ( 'dev' ) ? { } : {
vue : [ 'onServerPrefetch' , 'onRenderTracked' , 'onRenderTriggered' ] ,
}
)
}
}
} ,
2022-02-25 19:11:01 +00:00
}
2022-08-26 15:47:29 +00:00
} )