Skip to content

Commit d2d99e0

Browse files
authored
Docs for writing an adapter (#1846)
1 parent 6368eeb commit d2d99e0

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

documentation/docs/10-adapters.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,13 @@ export default {
3333

3434
A variety of official adapters exist for serverless platforms...
3535

36-
- [`adapter-begin`](https://github.com/sveltejs/kit/tree/master/packages/adapter-begin) — for [Begin](https://begin.com)
3736
- [`adapter-cloudflare-workers`](https://github.com/sveltejs/kit/tree/master/packages/adapter-cloudflare-workers) — for [Cloudflare Workers](https://developers.cloudflare.com/workers/)
3837
- [`adapter-netlify`](https://github.com/sveltejs/kit/tree/master/packages/adapter-netlify) — for [Netlify](https://netlify.com)
3938
- [`adapter-vercel`](https://github.com/sveltejs/kit/tree/master/packages/adapter-vercel) — for [Vercel](https://vercel.com)
4039

41-
...and others:
40+
...and traditional platforms:
4241

4342
- [`adapter-node`](https://github.com/sveltejs/kit/tree/master/packages/adapter-node) — for creating self-contained Node apps
4443
- [`adapter-static`](https://github.com/sveltejs/kit/tree/master/packages/adapter-static) — for prerendering your entire site as a collection of static files
4544

46-
> The adapter API is still in flux and will likely change before 1.0.
45+
As well as [community-provided adapters](https://github.com/sveltejs/integrations#sveltekit-adapters). You may also [write your own adapter](#writing-an-adapter).
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
title: Writing an Adapter
3+
---
4+
5+
We recommend [looking at the source for an adapter](https://github.com/sveltejs/kit/tree/master/packages) to a platform similar to yours and copying it as a starting point.
6+
7+
Adapters packages must implement the following API, which creates an `Adapter`:
8+
```
9+
/**
10+
* @param {AdapterSpecificOptions} options
11+
*/
12+
export default function (options) {
13+
/** @type {import('@sveltejs/kit').Adapter} */
14+
return {
15+
name: '',
16+
async adapt({ utils, config }) {
17+
}
18+
};
19+
}
20+
```
21+
22+
The types for `Adapter` and its parameters are available in [types/config.d.ts](https://github.com/sveltejs/kit/blob/master/packages/kit/types/config.d.ts).
23+
24+
Within the `adapt` method, there are a number of things that an adapter should do:
25+
- Clear out the build directory
26+
- Output code that:
27+
- Calls `init`
28+
- Converts from the patform's request to a [SvelteKit request](#hooks-handle), calls `render`, and converts from a [SvelteKit response](#hooks-handle) to the platform's
29+
- Globally shims `fetch` to work on the target platform. SvelteKit provides a `@sveltejs/kit/install-fetch` helper for platforms that can use `node-fetch`
30+
- Bundle the output to avoid needing to install dependencies on the target platform, if desired
31+
- Call `utils.prerender`
32+
- Put the user's static files and the generated JS/CSS in the correct location for the target platform
33+
34+
> The adapter API may change before 1.0.

0 commit comments

Comments
 (0)