vite-plugin-vercel 10.0.0-beta.4 → 10.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +168 -31
- package/dist/index.cjs +829 -0
- package/dist/index.d.cts +694 -0
- package/dist/index.d.ts +691 -8
- package/dist/index.js +684 -702
- package/index.d.ts +10 -0
- package/package.json +32 -31
- package/dist/api.d.ts +0 -55
- package/dist/api.js +0 -9
- package/dist/chunk-6F4PWJZI.js +0 -0
- package/dist/chunk-CR7Q2T4Q.js +0 -75
- package/dist/chunk-OCCU6UM5.js +0 -33
- package/dist/chunk-UTQ72LMT.js +0 -13
- package/dist/chunk-YN5MUEL2.js +0 -34
- package/dist/types.d.ts +0 -121
- package/dist/types.js +0 -1
- package/dist/universal-middleware-dev.d.ts +0 -17
- package/dist/universal-middleware-dev.js +0 -26
- package/dist/universal-middleware-prod.d.ts +0 -12
- package/dist/universal-middleware-prod.js +0 -21
- package/dist/utils.d.ts +0 -23
- package/dist/utils.js +0 -82
package/README.md
CHANGED
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
# vite-plugin-vercel
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
> :construction: Work In Progress
|
|
5
|
-
>
|
|
6
|
-
> You are on the [Vite Environment API](https://vite.dev/guide/api-environment.html#environment-configuration) development branch. Check out [v9 branch](https://github.com/magne4000/vite-plugin-vercel/tree/v9) current stable version.
|
|
7
|
-
|
|
8
|
-
Vercel adapter for [Vite 6](https://vitejs.dev/).
|
|
3
|
+
Vercel adapter for [Vite](https://vitejs.dev/).
|
|
9
4
|
|
|
10
5
|
Bundle your Vite application as supported by [Vercel Output API (v3)](https://vercel.com/docs/build-output-api/v3).
|
|
11
6
|
|
|
@@ -50,32 +45,27 @@ Install this package as a dev dependency and add it to your Vite config:
|
|
|
50
45
|
// vite.config.ts
|
|
51
46
|
import { defineConfig } from 'vite';
|
|
52
47
|
import vercel from 'vite-plugin-vercel';
|
|
53
|
-
import { getEntriesFromFs } from "vite-plugin-vercel/utils";
|
|
54
48
|
|
|
55
49
|
export default defineConfig({
|
|
56
|
-
plugins: [vercel(
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
// endpoints/api/page.ts -> /api/page
|
|
61
|
-
// endpoints/api/name/[name].ts -> /api/name/*
|
|
62
|
-
destination: "api",
|
|
63
|
-
}))
|
|
64
|
-
]
|
|
65
|
-
})],
|
|
50
|
+
plugins: [vercel()],
|
|
51
|
+
vercel: {
|
|
52
|
+
// optional configuration options, see "Advanced usage" below for details
|
|
53
|
+
},
|
|
66
54
|
});
|
|
67
55
|
```
|
|
68
56
|
|
|
69
57
|
> [!NOTE]
|
|
70
|
-
>
|
|
71
|
-
>
|
|
58
|
+
> Files under `/api` or `/_api` directory will automatically be added under `/api/*` route
|
|
59
|
+
> Prefer using `/_api` directory, as `@vercel/build` is currently force building `/api` files,
|
|
60
|
+
> with no way to disable it, thus avoiding double compilation and unexpected behaviour.
|
|
72
61
|
|
|
73
62
|
### Configure endpoints
|
|
74
63
|
|
|
75
|
-
Endpoints added
|
|
64
|
+
Endpoints under `/api`, `/_api` or added through `additionalEndpoints` can be configured
|
|
65
|
+
by exporting values from the endpoint file:
|
|
76
66
|
|
|
77
67
|
```ts
|
|
78
|
-
// file:
|
|
68
|
+
// file: _api/endpoint.ts
|
|
79
69
|
|
|
80
70
|
// Should run on edge runtime
|
|
81
71
|
export const edge = true;
|
|
@@ -100,23 +90,170 @@ export default async function handler() {
|
|
|
100
90
|
}
|
|
101
91
|
```
|
|
102
92
|
|
|
93
|
+
> [!NOTE]
|
|
94
|
+
> Please create an issue if you need other per-endpoints configurations
|
|
95
|
+
|
|
103
96
|
### Edge middleware
|
|
104
97
|
|
|
105
98
|
You can use [Edge middleware as describe in the official documentation](https://vercel.com/docs/functions/edge-middleware/middleware-api) (i.e. with a `middleware.ts` file at the root of your project).
|
|
106
99
|
|
|
107
|
-
##
|
|
100
|
+
## Usage with Vike
|
|
108
101
|
|
|
109
|
-
|
|
110
|
-
Nothing. It's a production-only feature
|
|
102
|
+
[Vike](https://vike.dev/) is supported through [@vite-plugin-vercel/vike](/packages/vike-integration/README.md) plugin.
|
|
111
103
|
|
|
112
|
-
|
|
113
|
-
Nothing (yet?). If you have a use-case where an actual Edge runtime would be necessary in dev, please open a discussion
|
|
104
|
+
You only need to install `@vite-plugin-vercel/vike`, the Vite config stays the same as above.
|
|
114
105
|
|
|
115
|
-
|
|
116
|
-
|
|
106
|
+
You can then leverage [config files](https://vike.dev/config) to customize your endpoints:
|
|
107
|
+
|
|
108
|
+
```ts
|
|
109
|
+
// /pages/product/+config.ts
|
|
110
|
+
|
|
111
|
+
import Page from './Page';
|
|
112
|
+
import type { Config } from 'vike/types';
|
|
113
|
+
|
|
114
|
+
export default {
|
|
115
|
+
// Customize ISR config for this page
|
|
116
|
+
isr: { expiration: 15 },
|
|
117
|
+
// Target Edge instead of Serverless
|
|
118
|
+
edge: true,
|
|
119
|
+
// append headers to all responses
|
|
120
|
+
headers: {
|
|
121
|
+
'X-Header': 'value'
|
|
122
|
+
}
|
|
123
|
+
} satisfies Config;
|
|
124
|
+
```
|
|
117
125
|
|
|
118
|
-
|
|
126
|
+
You will also need to extend the [renderer config](https://vike.dev/config#renderer) so that `vike` is aware of the new parameter:
|
|
127
|
+
|
|
128
|
+
```ts
|
|
129
|
+
// /renderer/+config.ts
|
|
130
|
+
|
|
131
|
+
import config from '@vite-plugin-vercel/vike/config';
|
|
132
|
+
import type { Config } from 'vike/types';
|
|
133
|
+
|
|
134
|
+
export default {
|
|
135
|
+
extends: config,
|
|
136
|
+
} satisfies Config;
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
## Advanced usage
|
|
140
|
+
|
|
141
|
+
```ts
|
|
142
|
+
// vite.config.ts
|
|
143
|
+
import { defineConfig } from 'vite';
|
|
144
|
+
import vercel from 'vite-plugin-vercel';
|
|
145
|
+
|
|
146
|
+
export default defineConfig({
|
|
147
|
+
plugins: [vercel()],
|
|
148
|
+
vercel: {
|
|
149
|
+
// All the followings optional
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* How long Functions should be allowed to run for every request, in seconds.
|
|
153
|
+
* If left empty, default value for your plan will be used.
|
|
154
|
+
*/
|
|
155
|
+
defaultMaxDuration: 30,
|
|
156
|
+
/**
|
|
157
|
+
* Enable streaming responses by default for all Serverless Functions
|
|
158
|
+
*/
|
|
159
|
+
defaultSupportsResponseStreaming: true,
|
|
160
|
+
/**
|
|
161
|
+
* Default expiration time (in seconds) for prerender functions.
|
|
162
|
+
* Defaults to 86400 seconds (24h).
|
|
163
|
+
*/
|
|
164
|
+
expiration: 86400,
|
|
165
|
+
/**
|
|
166
|
+
* Also known as Server Side Generation, or SSG.
|
|
167
|
+
* If present, this function is responsible to create static files in `.vercel/output/static`.
|
|
168
|
+
* Defaults to `false`, which disables prerendering.
|
|
169
|
+
*/
|
|
170
|
+
prerender(resolvedConfig) {
|
|
171
|
+
// Check `/packages/vike/vike.ts` `prerender` for an example
|
|
172
|
+
},
|
|
173
|
+
/**
|
|
174
|
+
* See https://vercel.com/docs/projects/project-configuration#rewrites
|
|
175
|
+
*/
|
|
176
|
+
rewrites: [{ source: '/about', destination: '/about-our-company.html' }],
|
|
177
|
+
/**
|
|
178
|
+
* @see {@link https://vercel.com/docs/projects/project-configuration#headers}
|
|
179
|
+
*/
|
|
180
|
+
headers: [
|
|
181
|
+
{
|
|
182
|
+
"source": "/service-worker.js",
|
|
183
|
+
"headers": [
|
|
184
|
+
{
|
|
185
|
+
"key": "Cache-Control",
|
|
186
|
+
"value": "public, max-age=0, must-revalidate"
|
|
187
|
+
}
|
|
188
|
+
]
|
|
189
|
+
}
|
|
190
|
+
],
|
|
191
|
+
/**
|
|
192
|
+
* See https://vercel.com/docs/projects/project-configuration#redirects
|
|
193
|
+
*/
|
|
194
|
+
redirects: [
|
|
195
|
+
{ source: '/me', destination: '/profile.html', permanent: false },
|
|
196
|
+
],
|
|
197
|
+
/**
|
|
198
|
+
* See https://vercel.com/docs/projects/project-configuration#cleanurls
|
|
199
|
+
*/
|
|
200
|
+
cleanUrls: true,
|
|
201
|
+
/**
|
|
202
|
+
* See https://vercel.com/docs/projects/project-configuration#trailingslash
|
|
203
|
+
*/
|
|
204
|
+
trailingSlash: true,
|
|
205
|
+
/**
|
|
206
|
+
* By default, all `api/*` and `_api/*` endpoints are compiled under `.vercel/output/functions/api/*.func`.
|
|
207
|
+
* If others serverless functions need to be compiled under `.vercel/output/functions`, they should be added here.
|
|
208
|
+
* For instance, a framework can leverage this to have a generic ssr endpoint
|
|
209
|
+
* without requiring the user to write any code.
|
|
210
|
+
*/
|
|
211
|
+
additionalEndpoints: [
|
|
212
|
+
{
|
|
213
|
+
// can also be an Object representing an esbuild StdinOptions
|
|
214
|
+
source: '/path/to/file.ts',
|
|
215
|
+
// URL path of the handler, will be generated to `.vercel/output/functions/api/file.func/index.js`
|
|
216
|
+
destination: '/api/file',
|
|
217
|
+
},
|
|
218
|
+
],
|
|
219
|
+
/**
|
|
220
|
+
* Advanced configuration to override .vercel/output/config.json
|
|
221
|
+
* See https://vercel.com/docs/build-output-api/v3/configuration#configuration
|
|
222
|
+
*/
|
|
223
|
+
config: {
|
|
224
|
+
// routes?: Route[];
|
|
225
|
+
// images?: ImagesConfig;
|
|
226
|
+
// wildcard?: WildcardConfig;
|
|
227
|
+
// overrides?: OverrideConfig;
|
|
228
|
+
// cache?: string[];
|
|
229
|
+
// crons?: CronsConfig;
|
|
230
|
+
},
|
|
231
|
+
/**
|
|
232
|
+
* ISR and SSG pages are mutually exclusive. If a page is found in both, ISR prevails.
|
|
233
|
+
* Keys are path relative to .vercel/output/functions directory, either without extension,
|
|
234
|
+
* or with `.prerender-config.json` extension.
|
|
235
|
+
* If you have multiple isr configurations pointing to the same underlying function, you can leverage the `symlink`
|
|
236
|
+
* property.
|
|
237
|
+
*
|
|
238
|
+
* Can be an object or a function returning an object (or a Promise of an object).
|
|
239
|
+
*
|
|
240
|
+
* Check `/packages/vike/vike.ts` `vitePluginVercelVpsIsrPlugin` for advanced usage.
|
|
241
|
+
*/
|
|
242
|
+
isr: {
|
|
243
|
+
// `symlink: 'ssr_'` means that a function is available under `.vercel/output/functions/ssr_.func`
|
|
244
|
+
'/pages/a': { expiration: 15, symlink: 'ssr_', route: '^/a/.*$' },
|
|
245
|
+
'/pages/b/c': { expiration: 15, symlink: 'ssr_', route: '^/b/c/.*$' },
|
|
246
|
+
'/pages/d': { expiration: 15, symlink: 'ssr_', route: '^/d$' },
|
|
247
|
+
'/pages/e': { expiration: 25 },
|
|
248
|
+
},
|
|
249
|
+
/**
|
|
250
|
+
* Defaults to `.vercel/output`. Mostly useful for testing purpose
|
|
251
|
+
*/
|
|
252
|
+
outDir: '.vercel/output',
|
|
253
|
+
},
|
|
254
|
+
});
|
|
255
|
+
```
|
|
119
256
|
|
|
120
|
-
##
|
|
257
|
+
## Demo
|
|
121
258
|
|
|
122
|
-
|
|
259
|
+
https://vike-photon-demo.vercel.app/
|