Skip to content

Commit

Permalink
Update adapter-vercel to use new build output API (#4663)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Rich-Harris authored Apr 20, 2022
1 parent b0ffb4d commit 467cdb9
Show file tree
Hide file tree
Showing 11 changed files with 347 additions and 102 deletions.
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

0 comments on commit 467cdb9

Please sign in to comment.