Skip to content

Commit 467cdb9

Browse files
authored
Update adapter-vercel to use new build output API (#4663)
* start working on v3 filesystem API * fix * support v1 and v3 * implement route splitting * WIP edge support * DYAC * lint * fix config and .vc-config.json * remove catch-all route * fixes * use overrides for prerendered pages * update README * changesets
1 parent b0ffb4d commit 467cdb9

File tree

11 files changed

+347
-102
lines changed

11 files changed

+347
-102
lines changed

.changeset/giant-ants-hang.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/adapter-vercel': patch
3+
---
4+
5+
Support build output API, with edge functions and code-splitting

.changeset/smooth-dodos-clap.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/kit': patch
3+
---
4+
5+
builder.createEntries returns a promise that awaits complete() callbacks

packages/adapter-vercel/README.md

+17-8
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ If you're using [adapter-auto](../adapter-auto), you don't need to install this
66

77
## Usage
88

9+
> The `edge` and `split` options depend on the Vercel Build Output API which is currently in beta. For now, you must opt in by visiting `https://vercel.com/svelte/[YOUR_PROJECT]/settings/environment-variables` and adding `ENABLE_VC_BUILD` with the value `1`.
10+
911
Add `"@sveltejs/adapter-vercel": "next"` to the `devDependencies` in your `package.json` and run `npm install`.
1012

1113
Then in your `svelte.config.js`:
@@ -15,18 +17,25 @@ import vercel from '@sveltejs/adapter-vercel';
1517

1618
export default {
1719
kit: {
18-
...
19-
adapter: vercel(options)
20+
// default options are shown
21+
adapter: vercel({
22+
// if true, will deploy the app using edge functions
23+
// (https://vercel.com/docs/concepts/functions/edge-functions)
24+
// rather than serverless functions
25+
edge: false,
26+
27+
// an array of dependencies that esbuild should treat
28+
// as external when bundling functions
29+
external: [],
30+
31+
// if true, will split your app into multiple functions
32+
// instead of creating a single one for the entire app
33+
split: false
34+
})
2035
}
2136
};
2237
```
2338

24-
## Options
25-
26-
You can pass an `options` argument, if necessary, with the following:
27-
28-
- `external` — an array of dependencies that [esbuild](https://esbuild.github.io/api/#external) should treat as external
29-
3039
## Changelog
3140

3241
[The Changelog for this package is available on GitHub](https://github.com/sveltejs/kit/blob/master/packages/adapter-vercel/CHANGELOG.md).

packages/adapter-vercel/files/edge.js

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { Server } from 'SERVER';
2+
import { manifest } from 'MANIFEST';
3+
4+
const server = new Server(manifest);
5+
6+
/**
7+
* @param {Request} request
8+
*/
9+
export default (request) => {
10+
return server.respond(request, {
11+
getClientAddress() {
12+
return request.headers.get('x-forwarded-for');
13+
}
14+
});
15+
};

packages/adapter-vercel/files/entry.js renamed to packages/adapter-vercel/files/serverless.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
import './shims';
1+
import { installFetch } from '@sveltejs/kit/install-fetch';
22
import { getRequest, setResponse } from '@sveltejs/kit/node';
33
import { Server } from 'SERVER';
44
import { manifest } from 'MANIFEST';
55

6+
installFetch();
7+
68
const server = new Server(manifest);
79

810
/**

packages/adapter-vercel/files/shims.js

-2
This file was deleted.

packages/adapter-vercel/index.d.ts

+2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import { Adapter } from '@sveltejs/kit';
22

33
type Options = {
4+
edge?: boolean;
45
external?: string[];
6+
split?: boolean;
57
};
68

79
declare function plugin(options?: Options): Adapter;

0 commit comments

Comments
 (0)