forked from nuxt/nuxt
/
config.ts
153 lines (132 loc) · 4.85 KB
/
config.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
import type { KeepAliveProps, TransitionProps } from 'vue'
import type { ServerOptions as ViteServerOptions, UserConfig as ViteUserConfig } from 'vite'
import type { Options as VuePluginOptions } from '@vitejs/plugin-vue'
import type { Options as VueJsxPluginOptions } from '@vitejs/plugin-vue-jsx'
import type { SchemaDefinition } from 'untyped'
import type { NitroRuntimeConfig, NitroRuntimeConfigApp } from 'nitropack'
import type { SnakeCase } from 'scule'
import type { ConfigSchema } from '../../schema/config'
import type { Nuxt } from './nuxt'
import type { AppHeadMetaObject } from './head'
export type { SchemaDefinition } from 'untyped'
type DeepPartial<T> = T extends Function ? T : T extends Record<string, any> ? { [P in keyof T]?: DeepPartial<T[P]> } : T
export type UpperSnakeCase<S extends string> = Uppercase<SnakeCase<S>>
const message = Symbol('message')
export type RuntimeValue<T, B extends string> = T & { [message]?: B }
type Overrideable<T extends Record<string, any>, Path extends string = ''> = {
[K in keyof T]?: K extends string
? unknown extends T[K]
? unknown
: T[K] extends Record<string, unknown>
? RuntimeValue<Overrideable<T[K], `${Path}_${UpperSnakeCase<K>}`>, `You can override this value at runtime with NUXT${Path}_${UpperSnakeCase<K>}`>
: RuntimeValue<T[K], `You can override this value at runtime with NUXT${Path}_${UpperSnakeCase<K>}`>
: K extends number
? T[K]
: never
}
// Runtime Config
type RuntimeConfigNamespace = Record<string, unknown>
export interface PublicRuntimeConfig extends RuntimeConfigNamespace { }
export interface RuntimeConfig extends RuntimeConfigNamespace {
app: NitroRuntimeConfigApp
/** Only available on the server. */
nitro?: NitroRuntimeConfig['nitro']
public: PublicRuntimeConfig
}
// User configuration in `nuxt.config` file
export interface NuxtConfig extends DeepPartial<Omit<ConfigSchema, 'vite' | 'runtimeConfig'>> {
// Avoid DeepPartial for vite config interface (#4772)
vite?: ConfigSchema['vite']
runtimeConfig?: Overrideable<RuntimeConfig>
webpack?: DeepPartial<ConfigSchema['webpack']> & {
$client?: DeepPartial<ConfigSchema['webpack']>
$server?: DeepPartial<ConfigSchema['webpack']>
}
/**
* Experimental custom config schema
* @see [Nuxt Issue #15592](https://github.com/nuxt/nuxt/issues/15592)
*/
$schema?: SchemaDefinition
}
// TODO: Expose ConfigLayer<T> from c12
interface ConfigLayer<T> {
config: T
cwd: string
configFile: string
}
export type NuxtConfigLayer = ConfigLayer<NuxtConfig & {
srcDir: ConfigSchema['srcDir'],
rootDir: ConfigSchema['rootDir']
}>
export interface NuxtBuilder {
bundle: (nuxt: Nuxt) => Promise<void>
}
// Normalized Nuxt options available as `nuxt.options.*`
export interface NuxtOptions extends Omit<ConfigSchema, 'builder' | 'webpack'> {
sourcemap: Required<Exclude<ConfigSchema['sourcemap'], boolean>>
builder: '@nuxt/vite-builder' | '@nuxt/webpack-builder' | NuxtBuilder
webpack: ConfigSchema['webpack'] & {
$client: ConfigSchema['webpack']
$server: ConfigSchema['webpack']
}
_layers: NuxtConfigLayer[]
$schema: SchemaDefinition
}
export interface ViteConfig extends Omit<ViteUserConfig, 'publicDir'> {
/** The path to the entrypoint for the Vite build. */
entry?: string
/**
* Options passed to @vitejs/plugin-vue.
* @see [@vitejs/plugin-vue](https://github.com/vitejs/vite-plugin-vue/tree/main/packages/plugin-vue)
*/
vue?: VuePluginOptions
/**
* Options passed to @vitejs/plugin-vue-jsx.
* @see [@vitejs/plugin-vue-jsx.](https://github.com/vitejs/vite-plugin-vue/tree/main/packages/plugin-vue-jsx)
*/
vueJsx?: VueJsxPluginOptions
/**
* Bundler for dev time server-side rendering.
* @default 'vite-node'
*/
devBundler?: 'vite-node' | 'legacy'
/**
* Warmup vite entrypoint caches on dev startup.
*/
warmupEntry?: boolean
/**
* Use environment variables or top level `server` options to configure Nuxt server.
*/
server?: Omit<ViteServerOptions, 'port' | 'host'>
/**
* 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>.
* @deprecated
*/
publicDir?: never
}
// App Config
export interface CustomAppConfig {
[key: string]: unknown
}
export interface AppConfigInput extends CustomAppConfig {
/** @deprecated reserved */
private?: never
/** @deprecated reserved */
nuxt?: never
/** @deprecated reserved */
nitro?: never
/** @deprecated reserved */
server?: never
}
export interface NuxtAppConfig {
head: AppHeadMetaObject
layoutTransition: boolean | TransitionProps
pageTransition: boolean | TransitionProps
viewTransition?: boolean | 'always'
keepalive: boolean | KeepAliveProps
}
export interface AppConfig {
[key: string]: unknown
}