vite-plugin-vercel 9.0.0 → 9.0.1

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 CHANGED
@@ -97,17 +97,13 @@ export default async function handler() {
97
97
 
98
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).
99
99
 
100
- ## Usage with vike
100
+ ## Usage with Vike
101
101
 
102
- [vike](https://vike.dev/) is supported through [@vite-plugin-vercel/vike](/packages/vike-integration/README.md) plugin.
102
+ [Vike](https://vike.dev/) is supported through [@vite-plugin-vercel/vike](/packages/vike-integration/README.md) plugin.
103
103
 
104
104
  You only need to install `@vite-plugin-vercel/vike`, the Vite config stays the same as above.
105
105
 
106
- > [!IMPORTANT]
107
- > `@vite-plugin-vercel/vike` supersedes the old `@magne4000/vite-plugin-vercel-ssr` package.
108
- > As such, you should remove `@magne4000/vite-plugin-vercel-ssr` from your package.json and vite config file.
109
-
110
- You can then leverage [config files](https://vike.dev/config) to customize ISR configuration:
106
+ You can then leverage [config files](https://vike.dev/config) to customize your endpoints:
111
107
 
112
108
  ```ts
113
109
  // /pages/product/+config.ts
@@ -115,9 +111,15 @@ You can then leverage [config files](https://vike.dev/config) to customize ISR c
115
111
  import Page from './Page';
116
112
  import type { Config } from 'vike/types';
117
113
 
118
- // Customize ISR config for this page
119
114
  export default {
115
+ // Customize ISR config for this page
120
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
+ }
121
123
  } satisfies Config;
122
124
  ```
123
125
 
@@ -172,6 +174,20 @@ export default defineConfig({
172
174
  * See https://vercel.com/docs/projects/project-configuration#rewrites
173
175
  */
174
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
+ ],
175
191
  /**
176
192
  * See https://vercel.com/docs/projects/project-configuration#redirects
177
193
  */
package/dist/index.cjs CHANGED
@@ -355,8 +355,18 @@ async function extractExports(filepath) {
355
355
  console.warn(`Warning: failed to read exports of '${filepath}'`, e);
356
356
  }
357
357
  }
358
+ async function extractHeaders(resolvedConfig) {
359
+ let headers = [];
360
+ if (typeof resolvedConfig.vercel?.headers === "function") {
361
+ headers = await resolvedConfig.vercel.headers();
362
+ } else if (Array.isArray(resolvedConfig.vercel?.headers)) {
363
+ headers = resolvedConfig.vercel.headers;
364
+ }
365
+ return headers;
366
+ }
358
367
  async function buildEndpoints(resolvedConfig) {
359
368
  const entries = await getEntries(resolvedConfig);
369
+ const headers = await extractHeaders(resolvedConfig);
360
370
  for (const entry of entries) {
361
371
  if (typeof entry.source === "string") {
362
372
  const exports2 = await extractExports(entry.source);
@@ -420,13 +430,16 @@ async function buildEndpoints(resolvedConfig) {
420
430
  };
421
431
  }),
422
432
  isr: Object.fromEntries(isrEntries),
423
- headers: entries.filter((e) => e.headers).map((e) => ({
424
- source: `/${e.destination.replace(/\.func$/, "")}`,
425
- headers: Object.entries(e.headers ?? {}).map(([key, value]) => ({
426
- key,
427
- value
428
- }))
429
- }))
433
+ headers: [
434
+ ...entries.filter((e) => e.headers).map((e) => ({
435
+ source: `/${e.destination.replace(/\.func$/, "")}`,
436
+ headers: Object.entries(e.headers ?? {}).map(([key, value]) => ({
437
+ key,
438
+ value
439
+ }))
440
+ })),
441
+ ...headers
442
+ ]
430
443
  };
431
444
  }
432
445
 
package/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { ResolvedConfig, PluginOption } from 'vite';
2
- import { Rewrite, Redirect } from '@vercel/routing-utils';
2
+ import { Rewrite, Redirect, Header } from '@vercel/routing-utils';
3
3
  import { StdinOptions, BuildOptions } from 'esbuild';
4
4
  import { z } from 'zod';
5
5
 
@@ -556,6 +556,11 @@ interface ViteVercelConfig {
556
556
  * @see {@link https://vercel.com/docs/projects/project-configuration#rewrites}
557
557
  */
558
558
  rewrites?: ViteVercelRewrite[];
559
+ /**
560
+ * @see {@link https://vercel.com/docs/projects/project-configuration#headers}
561
+ * @beta
562
+ */
563
+ headers?: Header[] | (() => Awaitable<Header[]>);
559
564
  /**
560
565
  * @see {@link https://vercel.com/docs/projects/project-configuration#redirects}
561
566
  */
@@ -673,7 +678,7 @@ interface ViteVercelApiEntry {
673
678
  /**
674
679
  * Additional headers
675
680
  */
676
- headers?: Record<string, string>;
681
+ headers?: Record<string, string> | null;
677
682
  /**
678
683
  * ISR config
679
684
  */
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { ResolvedConfig, PluginOption } from 'vite';
2
- import { Rewrite, Redirect } from '@vercel/routing-utils';
2
+ import { Rewrite, Redirect, Header } from '@vercel/routing-utils';
3
3
  import { StdinOptions, BuildOptions } from 'esbuild';
4
4
  import { z } from 'zod';
5
5
 
@@ -556,6 +556,11 @@ interface ViteVercelConfig {
556
556
  * @see {@link https://vercel.com/docs/projects/project-configuration#rewrites}
557
557
  */
558
558
  rewrites?: ViteVercelRewrite[];
559
+ /**
560
+ * @see {@link https://vercel.com/docs/projects/project-configuration#headers}
561
+ * @beta
562
+ */
563
+ headers?: Header[] | (() => Awaitable<Header[]>);
559
564
  /**
560
565
  * @see {@link https://vercel.com/docs/projects/project-configuration#redirects}
561
566
  */
@@ -673,7 +678,7 @@ interface ViteVercelApiEntry {
673
678
  /**
674
679
  * Additional headers
675
680
  */
676
- headers?: Record<string, string>;
681
+ headers?: Record<string, string> | null;
677
682
  /**
678
683
  * ISR config
679
684
  */
package/dist/index.js CHANGED
@@ -321,8 +321,18 @@ async function extractExports(filepath) {
321
321
  console.warn(`Warning: failed to read exports of '${filepath}'`, e);
322
322
  }
323
323
  }
324
+ async function extractHeaders(resolvedConfig) {
325
+ let headers = [];
326
+ if (typeof resolvedConfig.vercel?.headers === "function") {
327
+ headers = await resolvedConfig.vercel.headers();
328
+ } else if (Array.isArray(resolvedConfig.vercel?.headers)) {
329
+ headers = resolvedConfig.vercel.headers;
330
+ }
331
+ return headers;
332
+ }
324
333
  async function buildEndpoints(resolvedConfig) {
325
334
  const entries = await getEntries(resolvedConfig);
335
+ const headers = await extractHeaders(resolvedConfig);
326
336
  for (const entry of entries) {
327
337
  if (typeof entry.source === "string") {
328
338
  const exports = await extractExports(entry.source);
@@ -386,13 +396,16 @@ async function buildEndpoints(resolvedConfig) {
386
396
  };
387
397
  }),
388
398
  isr: Object.fromEntries(isrEntries),
389
- headers: entries.filter((e) => e.headers).map((e) => ({
390
- source: `/${e.destination.replace(/\.func$/, "")}`,
391
- headers: Object.entries(e.headers ?? {}).map(([key, value]) => ({
392
- key,
393
- value
394
- }))
395
- }))
399
+ headers: [
400
+ ...entries.filter((e) => e.headers).map((e) => ({
401
+ source: `/${e.destination.replace(/\.func$/, "")}`,
402
+ headers: Object.entries(e.headers ?? {}).map(([key, value]) => ({
403
+ key,
404
+ value
405
+ }))
406
+ })),
407
+ ...headers
408
+ ]
396
409
  };
397
410
  }
398
411
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-vercel",
3
- "version": "9.0.0",
3
+ "version": "9.0.1",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist",
@@ -26,7 +26,7 @@
26
26
  "peerDependencies": {
27
27
  "vike": "*",
28
28
  "vite": "^4.4 || ^5.0.2",
29
- "@vite-plugin-vercel/vike": "9.0.0"
29
+ "@vite-plugin-vercel/vike": "9.0.1"
30
30
  },
31
31
  "peerDependenciesMeta": {
32
32
  "@vite-plugin-vercel/vike": {
@@ -42,7 +42,7 @@
42
42
  "typescript": "^5.5.4",
43
43
  "vike": "^0.4.188",
44
44
  "vite": "^5.4.1",
45
- "@vite-plugin-vercel/vike": "9.0.0"
45
+ "@vite-plugin-vercel/vike": "9.0.1"
46
46
  },
47
47
  "dependencies": {
48
48
  "@brillout/libassert": "^0.5.8",