Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update adapter-vercel to use new build output API #4663

Merged
merged 14 commits into from
Apr 20, 2022
5 changes: 5 additions & 0 deletions .changeset/giant-ants-hang.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/adapter-vercel': patch
---

Support build output API, with edge functions and code-splitting
5 changes: 5 additions & 0 deletions .changeset/smooth-dodos-clap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

builder.createEntries returns a promise that awaits complete() callbacks
25 changes: 17 additions & 8 deletions packages/adapter-vercel/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ If you're using [adapter-auto](../adapter-auto), you don't need to install this

## Usage

> 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`.

Add `"@sveltejs/adapter-vercel": "next"` to the `devDependencies` in your `package.json` and run `npm install`.

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

export default {
kit: {
...
adapter: vercel(options)
// default options are shown
adapter: vercel({
// if true, will deploy the app using edge functions
// (https://vercel.com/docs/concepts/functions/edge-functions)
// rather than serverless functions
edge: false,

// an array of dependencies that esbuild should treat
// as external when bundling functions
external: [],

// if true, will split your app into multiple functions
// instead of creating a single one for the entire app
split: false
})
}
};
```

## Options

You can pass an `options` argument, if necessary, with the following:

- `external` — an array of dependencies that [esbuild](https://esbuild.github.io/api/#external) should treat as external

## Changelog

[The Changelog for this package is available on GitHub](https://github.com/sveltejs/kit/blob/master/packages/adapter-vercel/CHANGELOG.md).
15 changes: 15 additions & 0 deletions packages/adapter-vercel/files/edge.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Server } from 'SERVER';
import { manifest } from 'MANIFEST';

const server = new Server(manifest);

/**
* @param {Request} request
*/
export default (request) => {
return server.respond(request, {
getClientAddress() {
return request.headers.get('x-forwarded-for');
}
});
};
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import './shims';
import { installFetch } from '@sveltejs/kit/install-fetch';
import { getRequest, setResponse } from '@sveltejs/kit/node';
import { Server } from 'SERVER';
import { manifest } from 'MANIFEST';

installFetch();

const server = new Server(manifest);

/**
Expand Down
2 changes: 0 additions & 2 deletions packages/adapter-vercel/files/shims.js

This file was deleted.

2 changes: 2 additions & 0 deletions packages/adapter-vercel/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { Adapter } from '@sveltejs/kit';

type Options = {
edge?: boolean;
external?: string[];
split?: boolean;
};

declare function plugin(options?: Options): Adapter;
Expand Down
Loading