vite-plugin-vercel 0.2.0 → 0.2.2
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 +118 -21
- package/dist/index.cjs +14 -9
- package/dist/index.d.ts +21 -9
- package/dist/index.js +14 -9
- package/package.json +9 -9
package/README.md
CHANGED
|
@@ -1,42 +1,43 @@
|
|
|
1
1
|
# vite-plugin-vercel
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Vercel adapter for [`vite`](https://vitejs.dev/).
|
|
4
4
|
|
|
5
5
|
Its purpose is to help you bundle your application in `.vercel` folder as supported by
|
|
6
6
|
[Vercel API v3](https://vercel.com/docs/build-output-api/v3).
|
|
7
7
|
|
|
8
8
|
## Features
|
|
9
9
|
|
|
10
|
-
- [x] [SSG/Static files support](https://vercel.com/docs/build-output-api/v3#
|
|
11
|
-
- see [`prerender` config](/packages/vercel/src/types.ts#
|
|
12
|
-
- [x] [SSR/Serverless functions support](https://vercel.com/docs/build-output-api/v3#
|
|
10
|
+
- [x] [SSG/Static files support](https://vercel.com/docs/build-output-api/v3/primitives#static-files)
|
|
11
|
+
- see [`prerender` config](/packages/vercel/src/types.ts#L37)
|
|
12
|
+
- [x] [SSR/Serverless functions support](https://vercel.com/docs/build-output-api/v3/primitives#serverless-functions)
|
|
13
13
|
- `.[jt]s` files under the `<root>/api` folder of your project are automatically bundled as Serverless functions under `.vercel/output/functions/api/*.func`
|
|
14
|
-
- see [`additionalEndpoints` config](/packages/vercel/src/types.ts#
|
|
15
|
-
- [x] [ISR/Prerender functions support](https://vercel.com/docs/build-output-api/v3#
|
|
16
|
-
- see [`isr` config](/packages/vercel/src/types.ts#
|
|
17
|
-
- [x] [Edge functions support](https://vercel.com/docs/build-output-api/v3#
|
|
18
|
-
- [ ] [Images optimization support](https://vercel.com/docs/build-output-api/v3#
|
|
19
|
-
- [ ] [Preview mode support](https://vercel.com/docs/build-output-api/v3#
|
|
20
|
-
- [x] [Advanced config override](/packages/vercel/src/types.ts#
|
|
14
|
+
- see [`additionalEndpoints` config](/packages/vercel/src/types.ts#L62)
|
|
15
|
+
- [x] [ISR/Prerender functions support](https://vercel.com/docs/build-output-api/v3/primitives#prerender-functions)
|
|
16
|
+
- see [`isr` config](/packages/vercel/src/types.ts#L89). Also see implementation of [vite-plugin-ssr](/packages/vite-plugin-ssr/vite-plugin-ssr.ts) for example
|
|
17
|
+
- [x] [Edge functions support](https://vercel.com/docs/build-output-api/v3/primitives#edge-functions)
|
|
18
|
+
- [ ] [Images optimization support](https://vercel.com/docs/build-output-api/v3/configuration#images)
|
|
19
|
+
- [ ] [Preview mode support](https://vercel.com/docs/build-output-api/v3/features#preview-mode)
|
|
20
|
+
- [x] [Advanced config override](/packages/vercel/src/types.ts#L19)
|
|
21
21
|
- [ ] Complete config override
|
|
22
22
|
|
|
23
|
-
##
|
|
23
|
+
## Simple usage
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
Then, install this package as a dev dependency and add it to your Vite config like this:
|
|
25
|
+
Then, install this package as a dev dependency and add it to your Vite config:
|
|
28
26
|
|
|
29
27
|
```ts
|
|
28
|
+
// vite.config.ts
|
|
30
29
|
import { defineConfig } from 'vite';
|
|
31
30
|
import vercel from 'vite-plugin-vercel';
|
|
32
|
-
import ssr from 'vite-plugin-ssr/plugin';
|
|
33
31
|
|
|
34
32
|
export default defineConfig({
|
|
35
|
-
plugins: [
|
|
33
|
+
plugins: [vercel()],
|
|
34
|
+
vercel: {
|
|
35
|
+
// optional configuration options, see below for details
|
|
36
|
+
},
|
|
36
37
|
});
|
|
37
38
|
```
|
|
38
39
|
|
|
39
|
-
|
|
40
|
+
## Usage with vite-plugin-ssr
|
|
40
41
|
|
|
41
42
|
[vite-plugin-ssr](https://vite-plugin-ssr.com/) is supported through [@magne4000/vite-plugin-vercel-ssr](/packages/vite-plugin-ssr/README.md) plugin.
|
|
42
43
|
|
|
@@ -53,15 +54,111 @@ export default defineConfig(async ({ command, mode }) => {
|
|
|
53
54
|
return {
|
|
54
55
|
plugins: [ssr(), vercel(), vercelSsr()],
|
|
55
56
|
vercel: {
|
|
56
|
-
//
|
|
57
|
+
// optional configuration options, see below for details
|
|
57
58
|
},
|
|
58
59
|
};
|
|
59
60
|
});
|
|
60
61
|
```
|
|
61
62
|
|
|
62
|
-
|
|
63
|
+
## Advanced usage
|
|
64
|
+
|
|
65
|
+
```ts
|
|
66
|
+
// vite.config.ts
|
|
67
|
+
import { defineConfig } from 'vite';
|
|
68
|
+
import vercel from 'vite-plugin-vercel';
|
|
63
69
|
|
|
64
|
-
|
|
70
|
+
export default defineConfig({
|
|
71
|
+
plugins: [vercel()],
|
|
72
|
+
vercel: {
|
|
73
|
+
// All the followings optional
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* How long Functions should be allowed to run for every request, in seconds.
|
|
77
|
+
* If left empty, default value for your plan will be used.
|
|
78
|
+
*/
|
|
79
|
+
defaultMaxDuration: 30,
|
|
80
|
+
/**
|
|
81
|
+
* Default expiration time (in seconds) for prerender functions.
|
|
82
|
+
* Defaults to 86400 seconds (24h).
|
|
83
|
+
*/
|
|
84
|
+
expiration: 86400,
|
|
85
|
+
/**
|
|
86
|
+
* Also known as Server Side Generation, or SSG.
|
|
87
|
+
* If present, this function is responsible to create static files in `.vercel/output/static`.
|
|
88
|
+
* Defaults to `false`, which disables prerendering.
|
|
89
|
+
*/
|
|
90
|
+
prerender(resolvedConfig) {
|
|
91
|
+
// Check `/packages/vite-plugin-ssr/vite-plugin-ssr.ts` `prerender` for an example
|
|
92
|
+
},
|
|
93
|
+
/**
|
|
94
|
+
* See https://vercel.com/docs/projects/project-configuration#rewrites
|
|
95
|
+
*/
|
|
96
|
+
rewrites: [{ source: '/about', destination: '/about-our-company.html' }],
|
|
97
|
+
/**
|
|
98
|
+
* See https://vercel.com/docs/projects/project-configuration#redirects
|
|
99
|
+
*/
|
|
100
|
+
redirects: [
|
|
101
|
+
{ source: '/me', destination: '/profile.html', permanent: false },
|
|
102
|
+
],
|
|
103
|
+
/**
|
|
104
|
+
* See https://vercel.com/docs/projects/project-configuration#cleanurls
|
|
105
|
+
*/
|
|
106
|
+
cleanUrls: true,
|
|
107
|
+
/**
|
|
108
|
+
* See https://vercel.com/docs/projects/project-configuration#trailingslash
|
|
109
|
+
*/
|
|
110
|
+
trailingSlash: true,
|
|
111
|
+
/**
|
|
112
|
+
* By default, all `api/*` endpoints are compiled under `.vercel/output/functions/api/*.func`.
|
|
113
|
+
* If others serverless functions need to be compiled under `.vercel/output/functions`, they should be added here.
|
|
114
|
+
* For instance, a framework can leverage this to have a generic ssr endpoint
|
|
115
|
+
* without requiring the user to write any code.
|
|
116
|
+
*/
|
|
117
|
+
additionalEndpoints: [
|
|
118
|
+
{
|
|
119
|
+
// can also be an Object representing an esbuild StdinOptions
|
|
120
|
+
source: '/path/to/file.ts',
|
|
121
|
+
// URL path of the handler, will be generated to `.vercel/output/functions/api/file.func/index.js`
|
|
122
|
+
destination: '/api/file',
|
|
123
|
+
},
|
|
124
|
+
],
|
|
125
|
+
/**
|
|
126
|
+
* Advanced configuration to override .vercel/output/config.json
|
|
127
|
+
* See https://vercel.com/docs/build-output-api/v3/configuration#configuration
|
|
128
|
+
*/
|
|
129
|
+
config: {
|
|
130
|
+
// routes?: Route[];
|
|
131
|
+
// images?: ImagesConfig;
|
|
132
|
+
// wildcard?: WildcardConfig;
|
|
133
|
+
// overrides?: OverrideConfig;
|
|
134
|
+
// cache?: string[];
|
|
135
|
+
// crons?: CronsConfig;
|
|
136
|
+
},
|
|
137
|
+
/**
|
|
138
|
+
* ISR and SSG pages are mutually exclusive. If a page is found in both, ISR prevails.
|
|
139
|
+
* Keys are path relative to .vercel/output/functions directory, either without extension,
|
|
140
|
+
* or with `.prerender-config.json` extension.
|
|
141
|
+
* If you have multiple isr configurations pointing to the same underlying function, you can leverage the `symlink`
|
|
142
|
+
* property.
|
|
143
|
+
*
|
|
144
|
+
* Can be an object or a function returning an object (or a Promise of an object).
|
|
145
|
+
*
|
|
146
|
+
* Check `/packages/vite-plugin-ssr/vite-plugin-ssr.ts` `vitePluginVercelVpsIsrPlugin` for advanced usage.
|
|
147
|
+
*/
|
|
148
|
+
isr: {
|
|
149
|
+
// `symlink: 'ssr_'` means that a function is available under `.vercel/output/functions/ssr_.func`
|
|
150
|
+
'/pages/a': { expiration: 15, symlink: 'ssr_', route: '^/a/.*$' },
|
|
151
|
+
'/pages/b/c': { expiration: 15, symlink: 'ssr_', route: '^/b/c/.*$' },
|
|
152
|
+
'/pages/d': { expiration: 15, symlink: 'ssr_', route: '^/d$' },
|
|
153
|
+
'/pages/e': { expiration: 25 },
|
|
154
|
+
},
|
|
155
|
+
/**
|
|
156
|
+
* Defaults to `.vercel/output`. Mostly useful for testing purpose
|
|
157
|
+
*/
|
|
158
|
+
outDir: '.vercel/output',
|
|
159
|
+
},
|
|
160
|
+
});
|
|
161
|
+
```
|
|
65
162
|
|
|
66
163
|
## Demo
|
|
67
164
|
|
package/dist/index.cjs
CHANGED
|
@@ -322,7 +322,13 @@ async function buildFn(resolvedConfig, entry, buildOptions) {
|
|
|
322
322
|
}
|
|
323
323
|
}
|
|
324
324
|
if (entry.edge) {
|
|
325
|
-
options.conditions = [
|
|
325
|
+
options.conditions = [
|
|
326
|
+
"edge-light",
|
|
327
|
+
"browser",
|
|
328
|
+
"module",
|
|
329
|
+
"import",
|
|
330
|
+
"require"
|
|
331
|
+
];
|
|
326
332
|
}
|
|
327
333
|
await (0, import_esbuild.build)(options);
|
|
328
334
|
await writeVcConfig(resolvedConfig, entry.destination, Boolean(entry.edge));
|
|
@@ -481,25 +487,24 @@ async function getIsrConfig(resolvedConfig) {
|
|
|
481
487
|
var import_path5 = __toESM(require("path"), 1);
|
|
482
488
|
function vercelPlugin() {
|
|
483
489
|
let resolvedConfig;
|
|
490
|
+
let vpsFound = false;
|
|
484
491
|
return {
|
|
485
492
|
apply: "build",
|
|
486
493
|
name: "vite-plugin-vercel",
|
|
487
494
|
enforce: "post",
|
|
488
495
|
configResolved(config) {
|
|
489
496
|
resolvedConfig = config;
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
throw new Error(
|
|
494
|
-
"Missing ENABLE_VC_BUILD=1 to your environment variables in your project settings"
|
|
495
|
-
);
|
|
496
|
-
}
|
|
497
|
+
vpsFound = resolvedConfig.plugins.some(
|
|
498
|
+
(p) => p.name.startsWith("vite-plugin-ssr:")
|
|
499
|
+
);
|
|
497
500
|
},
|
|
498
501
|
async writeBundle() {
|
|
499
502
|
var _a;
|
|
500
503
|
if (!((_a = resolvedConfig.build) == null ? void 0 : _a.ssr)) {
|
|
501
504
|
await cleanOutputDirectory(resolvedConfig);
|
|
502
|
-
|
|
505
|
+
if (vpsFound) {
|
|
506
|
+
return;
|
|
507
|
+
}
|
|
503
508
|
}
|
|
504
509
|
const overrides = await execPrerender(resolvedConfig);
|
|
505
510
|
const userOverrides = await computeStaticHtmlOverrides(resolvedConfig);
|
package/dist/index.d.ts
CHANGED
|
@@ -521,8 +521,8 @@ type ViteVercelRedirect = Redirect & {
|
|
|
521
521
|
};
|
|
522
522
|
interface ViteVercelConfig {
|
|
523
523
|
/**
|
|
524
|
-
* How long Functions should be allowed to run for every request in seconds.
|
|
525
|
-
* If left empty, default value for your plan will
|
|
524
|
+
* How long Functions should be allowed to run for every request, in seconds.
|
|
525
|
+
* If left empty, default value for your plan will be used.
|
|
526
526
|
*/
|
|
527
527
|
defaultMaxDuration?: number;
|
|
528
528
|
/**
|
|
@@ -534,10 +534,26 @@ interface ViteVercelConfig {
|
|
|
534
534
|
expiration?: number;
|
|
535
535
|
/**
|
|
536
536
|
* Also known as Server Side Generation, or SSG.
|
|
537
|
-
* If present,
|
|
538
|
-
*
|
|
537
|
+
* If present, this function is responsible to create static files in `.vercel/output/static`.
|
|
538
|
+
* Defaults to `false`, which disables prerendering.
|
|
539
539
|
*/
|
|
540
540
|
prerender?: ViteVercelPrerenderFn | false;
|
|
541
|
+
/**
|
|
542
|
+
* @see {@link https://vercel.com/docs/projects/project-configuration#rewrites}
|
|
543
|
+
*/
|
|
544
|
+
rewrites?: ViteVercelRewrite[];
|
|
545
|
+
/**
|
|
546
|
+
* @see {@link https://vercel.com/docs/projects/project-configuration#redirects}
|
|
547
|
+
*/
|
|
548
|
+
redirects?: ViteVercelRedirect[];
|
|
549
|
+
/**
|
|
550
|
+
* @see {@link https://vercel.com/docs/projects/project-configuration#cleanurls}
|
|
551
|
+
*/
|
|
552
|
+
cleanUrls?: boolean;
|
|
553
|
+
/**
|
|
554
|
+
* @see {@link https://vercel.com/docs/projects/project-configuration#trailingslash}
|
|
555
|
+
*/
|
|
556
|
+
trailingSlash?: boolean;
|
|
541
557
|
/**
|
|
542
558
|
* By default, all `api/*` endpoints are compiled under `.vercel/output/functions/api/*.func`.
|
|
543
559
|
* If others serverless functions need to be compiled under `.vercel/output/functions`, they should be added here.
|
|
@@ -558,14 +574,10 @@ interface ViteVercelConfig {
|
|
|
558
574
|
* }
|
|
559
575
|
* ```
|
|
560
576
|
*/
|
|
561
|
-
rewrites?: ViteVercelRewrite[];
|
|
562
|
-
redirects?: ViteVercelRedirect[];
|
|
563
|
-
cleanUrls?: boolean;
|
|
564
|
-
trailingSlash?: boolean;
|
|
565
577
|
additionalEndpoints?: ViteVercelApiEntry[];
|
|
566
578
|
/**
|
|
567
579
|
* Advanced configuration to override .vercel/output/config.json
|
|
568
|
-
* @see {@link https://vercel.com/docs/build-output-api/v3#
|
|
580
|
+
* @see {@link https://vercel.com/docs/build-output-api/v3/configuration#configuration}
|
|
569
581
|
* @protected
|
|
570
582
|
*/
|
|
571
583
|
config?: Partial<Omit<VercelOutputConfig, 'version'>>;
|
package/dist/index.js
CHANGED
|
@@ -288,7 +288,13 @@ async function buildFn(resolvedConfig, entry, buildOptions) {
|
|
|
288
288
|
}
|
|
289
289
|
}
|
|
290
290
|
if (entry.edge) {
|
|
291
|
-
options.conditions = [
|
|
291
|
+
options.conditions = [
|
|
292
|
+
"edge-light",
|
|
293
|
+
"browser",
|
|
294
|
+
"module",
|
|
295
|
+
"import",
|
|
296
|
+
"require"
|
|
297
|
+
];
|
|
292
298
|
}
|
|
293
299
|
await build(options);
|
|
294
300
|
await writeVcConfig(resolvedConfig, entry.destination, Boolean(entry.edge));
|
|
@@ -447,25 +453,24 @@ async function getIsrConfig(resolvedConfig) {
|
|
|
447
453
|
import path5 from "path";
|
|
448
454
|
function vercelPlugin() {
|
|
449
455
|
let resolvedConfig;
|
|
456
|
+
let vpsFound = false;
|
|
450
457
|
return {
|
|
451
458
|
apply: "build",
|
|
452
459
|
name: "vite-plugin-vercel",
|
|
453
460
|
enforce: "post",
|
|
454
461
|
configResolved(config) {
|
|
455
462
|
resolvedConfig = config;
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
throw new Error(
|
|
460
|
-
"Missing ENABLE_VC_BUILD=1 to your environment variables in your project settings"
|
|
461
|
-
);
|
|
462
|
-
}
|
|
463
|
+
vpsFound = resolvedConfig.plugins.some(
|
|
464
|
+
(p) => p.name.startsWith("vite-plugin-ssr:")
|
|
465
|
+
);
|
|
463
466
|
},
|
|
464
467
|
async writeBundle() {
|
|
465
468
|
var _a;
|
|
466
469
|
if (!((_a = resolvedConfig.build) == null ? void 0 : _a.ssr)) {
|
|
467
470
|
await cleanOutputDirectory(resolvedConfig);
|
|
468
|
-
|
|
471
|
+
if (vpsFound) {
|
|
472
|
+
return;
|
|
473
|
+
}
|
|
469
474
|
}
|
|
470
475
|
const overrides = await execPrerender(resolvedConfig);
|
|
471
476
|
const userOverrides = await computeStaticHtmlOverrides(resolvedConfig);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-plugin-vercel",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist",
|
|
@@ -24,20 +24,20 @@
|
|
|
24
24
|
"vite": "^4.2.0"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"@types/node": "^16.18.
|
|
28
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
29
|
-
"@typescript-eslint/parser": "^5.
|
|
30
|
-
"eslint": "^8.
|
|
27
|
+
"@types/node": "^16.18.48",
|
|
28
|
+
"@typescript-eslint/eslint-plugin": "^5.62.0",
|
|
29
|
+
"@typescript-eslint/parser": "^5.62.0",
|
|
30
|
+
"eslint": "^8.48.0",
|
|
31
31
|
"tsup": "^6.7.0",
|
|
32
|
-
"typescript": "^5.
|
|
33
|
-
"vite": "^4.
|
|
32
|
+
"typescript": "^5.2.2",
|
|
33
|
+
"vite": "^4.4.9"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"@brillout/libassert": "^0.5.8",
|
|
37
37
|
"@vercel/routing-utils": "^2.2.1",
|
|
38
38
|
"esbuild": "^0.17.19",
|
|
39
|
-
"fast-glob": "^3.
|
|
40
|
-
"zod": "^3.
|
|
39
|
+
"fast-glob": "^3.3.1",
|
|
40
|
+
"zod": "^3.22.2"
|
|
41
41
|
},
|
|
42
42
|
"scripts": {
|
|
43
43
|
"build": "tsup",
|