diff --git a/documentation/docs/10-adapters.md b/documentation/docs/10-adapters.md index 96009a7ca050..fcfb8bbdef15 100644 --- a/documentation/docs/10-adapters.md +++ b/documentation/docs/10-adapters.md @@ -33,14 +33,13 @@ export default { A variety of official adapters exist for serverless platforms... -- [`adapter-begin`](https://github.com/sveltejs/kit/tree/master/packages/adapter-begin) — for [Begin](https://begin.com) - [`adapter-cloudflare-workers`](https://github.com/sveltejs/kit/tree/master/packages/adapter-cloudflare-workers) — for [Cloudflare Workers](https://developers.cloudflare.com/workers/) - [`adapter-netlify`](https://github.com/sveltejs/kit/tree/master/packages/adapter-netlify) — for [Netlify](https://netlify.com) - [`adapter-vercel`](https://github.com/sveltejs/kit/tree/master/packages/adapter-vercel) — for [Vercel](https://vercel.com) -...and others: +...and traditional platforms: - [`adapter-node`](https://github.com/sveltejs/kit/tree/master/packages/adapter-node) — for creating self-contained Node apps - [`adapter-static`](https://github.com/sveltejs/kit/tree/master/packages/adapter-static) — for prerendering your entire site as a collection of static files -> The adapter API is still in flux and will likely change before 1.0. +As well as [community-provided adapters](https://github.com/sveltejs/integrations#sveltekit-adapters). You may also [write your own adapter](#writing-an-adapter). diff --git a/documentation/docs/80-adapter-api.md b/documentation/docs/80-adapter-api.md new file mode 100644 index 000000000000..410a1da26876 --- /dev/null +++ b/documentation/docs/80-adapter-api.md @@ -0,0 +1,34 @@ +--- +title: Writing an Adapter +--- + +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. + +Adapters packages must implement the following API, which creates an `Adapter`: +``` +/** + * @param {AdapterSpecificOptions} options + */ +export default function (options) { + /** @type {import('@sveltejs/kit').Adapter} */ + return { + name: '', + async adapt({ utils, config }) { + } + }; +} +``` + +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). + +Within the `adapt` method, there are a number of things that an adapter should do: +- Clear out the build directory +- Output code that: + - Calls `init` + - 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 + - Globally shims `fetch` to work on the target platform. SvelteKit provides a `@sveltejs/kit/install-fetch` helper for platforms that can use `node-fetch` +- Bundle the output to avoid needing to install dependencies on the target platform, if desired +- Call `utils.prerender` +- Put the user's static files and the generated JS/CSS in the correct location for the target platform + +> The adapter API may change before 1.0.