From 6247669d02f72a3f4c8de92dddcbf0438bf89966 Mon Sep 17 00:00:00 2001 From: Ben McCann <322311+benmccann@users.noreply.github.com> Date: Wed, 7 Jul 2021 06:53:57 -0700 Subject: [PATCH] Docs for writing an adapter API --- documentation/docs/80-adapter-api.md | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 documentation/docs/80-adapter-api.md diff --git a/documentation/docs/80-adapter-api.md b/documentation/docs/80-adapter-api.md new file mode 100644 index 0000000000000..0f2e3127394d4 --- /dev/null +++ b/documentation/docs/80-adapter-api.md @@ -0,0 +1,27 @@ +--- +title: Writing Adapters +--- + +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 must implement the following API: +``` +export default function () { + /** @type {import('@sveltejs/kit').Adapter} */ + return { + name: '', + async adapt({ utils, config }) { + } + }; +} +``` + +Within the `adapt` method, there are a few things an adapter should do: +- Clear out the build directory +- Provide code that runs: + - Call `init` + - Convert from the patform's request to a SvelteKit request, call `render`, convert from a SveteKit reponse to the platform's +- Adapters typically bundle the output to avoid needing to install dependencies on the target platform, etc. +- Globally shim `fetch` to work on the target platform. SvelteKit provides a `@sveltejs/kit/install-fetch` helper to use `node-fetch` +- Call `prerender` +- Put the user's static files and the generated JS/CSS in the correct location for the target platform