vite-plugin-vercel 0.2.1 → 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.
Files changed (3) hide show
  1. package/README.md +118 -21
  2. package/dist/index.d.ts +21 -9
  3. package/package.json +9 -9
package/README.md CHANGED
@@ -1,42 +1,43 @@
1
1
  # vite-plugin-vercel
2
2
 
3
- This is a **Work In Progress** Vercel adapter for [`vite`](https://vitejs.dev/).
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#vercel-primitives/static-files)
11
- - see [`prerender` config](/packages/vercel/src/types.ts#L33)
12
- - [x] [SSR/Serverless functions support](https://vercel.com/docs/build-output-api/v3#vercel-primitives/serverless-functions)
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#L54)
15
- - [x] [ISR/Prerender functions support](https://vercel.com/docs/build-output-api/v3#vercel-primitives/prerender-functions)
16
- - see [`isr` config](/packages/vercel/src/types.ts#L81). 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#vercel-primitives/edge-functions)
18
- - [ ] [Images optimization support](https://vercel.com/docs/build-output-api/v3#build-output-configuration/supported-properties/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#L15)
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
- ## Usage
23
+ ## Simple usage
24
24
 
25
- First, make sure `ENABLE_VC_BUILD=1` is declared as an Environment Variable in your deployment configuration.
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: [ssr(), vercel()],
33
+ plugins: [vercel()],
34
+ vercel: {
35
+ // optional configuration options, see below for details
36
+ },
36
37
  });
37
38
  ```
38
39
 
39
- ### Usage with vite-plugin-ssr
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
- // Tweak what you need, check TS definition for details
57
+ // optional configuration options, see below for details
57
58
  },
58
59
  };
59
60
  });
60
61
  ```
61
62
 
62
- ### Config
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
- See [TS types](/packages/vercel/src/types.ts#L15) for details.
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.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 is used.
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, must build static files in `.vercel/output/static`.
538
- * Can be set to `false` to disable prerendering completely.
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#build-output-configuration}
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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-vercel",
3
- "version": "0.2.1",
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.37",
28
- "@typescript-eslint/eslint-plugin": "^5.60.1",
29
- "@typescript-eslint/parser": "^5.60.1",
30
- "eslint": "^8.43.0",
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.1.6",
33
- "vite": "^4.3.9"
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.3.0",
40
- "zod": "^3.21.4"
39
+ "fast-glob": "^3.3.1",
40
+ "zod": "^3.22.2"
41
41
  },
42
42
  "scripts": {
43
43
  "build": "tsup",