Skip to content

Commit 31a2625

Browse files
committed
Docs for writing an adapter API
1 parent 71480bb commit 31a2625

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

documentation/docs/10-adapters.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ A variety of official adapters exist for serverless platforms...
3838
- [`adapter-netlify`](https://github.com/sveltejs/kit/tree/master/packages/adapter-netlify) — for [Netlify](https://netlify.com)
3939
- [`adapter-vercel`](https://github.com/sveltejs/kit/tree/master/packages/adapter-vercel) — for [Vercel](https://vercel.com)
4040

41-
...and others:
41+
...and traditional platforms:
4242

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

46-
> The adapter API is still in flux and will likely change before 1.0.
46+
You may also [write your own](#writing-an-adapter).
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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 must implement the following API:
8+
```
9+
export default function () {
10+
/** @type {import('@sveltejs/kit').Adapter} */
11+
return {
12+
name: '',
13+
async adapt({ utils, config }) {
14+
}
15+
};
16+
}
17+
```
18+
19+
Within the `adapt` method, there are a number of things that an adapter should do:
20+
- Clear out the build directory
21+
- Provide code that:
22+
- Calls `init`
23+
- Converts from the patform's request to a SvelteKit request, call `render`, convert from a SveteKit reponse to the platform's
24+
- Bundle the output to avoid needing to install dependencies on the target platform, etc. if desired
25+
- Globally shim `fetch` to work on the target platform. SvelteKit provides a `@sveltejs/kit/install-fetch` helper to use `node-fetch`
26+
- Call `prerender`
27+
- Put the user's static files and the generated JS/CSS in the correct location for the target platform
28+
29+
> The adapter API may change before 1.0.

0 commit comments

Comments
 (0)