-
Notifications
You must be signed in to change notification settings - Fork 14
/
types.ts
178 lines (170 loc) · 6.08 KB
/
types.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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
import type { Header, Redirect, Rewrite } from "@vercel/routing-utils";
import type { BuildOptions, StdinOptions } from "esbuild";
import type { ResolvedConfig } from "vite";
import type { VercelOutputConfig } from "./schemas/config/config";
import type { VercelOutputPrerenderConfig } from "./schemas/config/prerender-config";
import type { VercelOutputVcConfig } from "./schemas/config/vc-config";
export type { VercelOutputConfig, VercelOutputVcConfig, VercelOutputPrerenderConfig };
export type ViteVercelRewrite = Rewrite & { enforce?: "pre" | "post" };
export type ViteVercelRedirect = Redirect & { enforce?: "pre" | "post" };
export type Awaitable<T> = T | Promise<T>;
// Vite config for Vercel
export interface ViteVercelConfig {
/**
* How long Functions should be allowed to run for every request, in seconds.
* If left empty, default value for your plan will be used.
*/
defaultMaxDuration?: number;
/**
* Default expiration time (in seconds) for prerender functions.
* Defaults to 86400 seconds (24h).
* @see {@link https://vercel.com/docs/concepts/next.js/incremental-static-regeneration}
* @see {@link https://vercel.com/docs/build-output-api/v3#vercel-primitives/prerender-functions/configuration}
*/
expiration?: number;
/**
* Also known as Server Side Generation, or SSG.
* If present, this function is responsible to create static files in `.vercel/output/static`.
* Defaults to `false`, which disables prerendering.
*/
prerender?: ViteVercelPrerenderFn | false;
/**
* @see {@link https://vercel.com/docs/projects/project-configuration#rewrites}
*/
rewrites?: ViteVercelRewrite[];
/**
* @see {@link https://vercel.com/docs/projects/project-configuration#headers}
* @beta
*/
headers?: Header[] | (() => Awaitable<Header[]>);
/**
* @see {@link https://vercel.com/docs/projects/project-configuration#redirects}
*/
redirects?: ViteVercelRedirect[];
/**
* @see {@link https://vercel.com/docs/projects/project-configuration#cleanurls}
*/
cleanUrls?: boolean;
/**
* @see {@link https://vercel.com/docs/projects/project-configuration#trailingslash}
*/
trailingSlash?: boolean;
/**
* When true, the Serverless Function will stream the response to the client.
* @see {@link https://vercel.com/docs/build-output-api/v3/primitives#serverless-function-configuration}
*/
defaultSupportsResponseStreaming?: boolean;
/**
* By default, all `api/*` endpoints are compiled under `.vercel/output/functions/api/*.func`.
* If others serverless functions need to be compiled under `.vercel/output/functions`, they should be added here.
* For instance, a framework can leverage this to have a generic ssr endpoint
* without requiring the user to write any code.
*
* @example
* ```
* {
* additionalEndpoints: [
* {
* // can also be an Object representing an esbuild StdinOptions
* source: '/path/to/file.ts',
* // URL path of the handler, will be generated to `.vercel/output/functions/api/file.func/index.js`
* destination: '/api/file',
* }
* ]
* }
* ```
*/
additionalEndpoints?: (
| ViteVercelApiEntry
| (() => Awaitable<ViteVercelApiEntry>)
| (() => Awaitable<ViteVercelApiEntry[]>)
)[];
/**
* Advanced configuration to override .vercel/output/config.json
* @see {@link https://vercel.com/docs/build-output-api/v3/configuration#configuration}
* @protected
*/
config?: Partial<Omit<VercelOutputConfig, "version">>;
/**
* ISR and SSG pages are mutually exclusive. If a page is found in both, ISR prevails.
* Keys are path relative to .vercel/output/functions directory, either without extension,
* or with `.prerender-config.json` extension.
* If you have multiple isr configurations pointing to the same underlying function, you can leverage the `symlink`
* property. See example below.
*
* @example
* ```
* // Here `ssr_` means that a function is available under `.vercel/output/functions/ssr_.func`
* isr: {
* '/pages/a': { expiration: 15, symlink: 'ssr_', route: '^/a/.*$' },
* '/pages/b/c': { expiration: 15, symlink: 'ssr_', route: '^/b/c/.*$' },
* '/pages/d': { expiration: 15, symlink: 'ssr_', route: '^/d$' },
* '/pages/e': { expiration: 25 }
* }
* ```
*
* @protected
*/
isr?: Record<string, VercelOutputIsr> | (() => Awaitable<Record<string, VercelOutputIsr>>);
/**
* Defaults to `.vercel/output`. Mostly useful for testing purpose
* @protected
*/
outDir?: string;
/**
* By default, Vite generates static files under `dist` folder.
* But usually, when used through a Framework, such as Vike,
* this folder can contain anything, requiring custom integration.
* Set this to false if you create a plugin for a Framework.
*/
distContainsOnlyStatic?: boolean;
}
export interface VercelOutputIsr extends VercelOutputPrerenderConfig {
symlink?: string;
route?: string;
}
/**
* Keys are path relative to .vercel/output/static directory
*/
export type ViteVercelPrerenderRoute = VercelOutputConfig["overrides"];
export type ViteVercelPrerenderFn = (resolvedConfig: ResolvedConfig) => Awaitable<ViteVercelPrerenderRoute>;
export interface ViteVercelApiEntry {
/**
* Path to entry file, or stdin config
*/
source: string | StdinOptions;
/**
* Relative to `.vercel/output/functions`, without extension
*/
destination: string;
/**
* Override esbuild options
*/
buildOptions?: BuildOptions;
/**
* @deprecated use `route` instead
*/
addRoute?: boolean;
/**
* If `true`, guesses route for the function, and adds it to config.json (mimics defaults Vercel behavior).
* If a string is provided, it will be equivalent to a `rewrites` rule.
* Set to `false` to disable
*/
route?: string | boolean;
/**
* Set to `true` to mark this function as an Edge Function
*/
edge?: boolean;
/**
* Additional headers
*/
headers?: Record<string, string> | null;
/**
* ISR config
*/
isr?: VercelOutputIsr;
/**
* When true, the Serverless Function will stream the response to the client
*/
streaming?: boolean;
}