Writing adapters
Edit this page on GitHubIf an adapter for your preferred environment doesn't yet exist, you can build your own. We recommend looking at the source for an adapter to a platform similar to yours and copying it as a starting point.
Adapters packages must implement the following API, which creates an Adapter
:
ts
/** @param {AdapterSpecificOptions} options */export default function (options ) {constadapter = {name : 'adapter-package-name',asyncadapt (builder ) {// adapter implementation}};returnadapter ;}
The types for Adapter
and its parameters are available in types/index.d.ts.
Within the adapt
method, there are a number of things that an adapter should do:
- Clear out the build directory
- Write SvelteKit output with
builder.writeClient
,builder.writeServer
, andbuilder.writePrerendered
- Output code that:
- Imports
Server
from${builder.getServerDirectory()}/index.js .ts
- Instantiates the app with a manifest generated with
builder.generateManifest({ relativePath })
- Listens for requests from the platform, converts them to a standard Request if necessary, calls the
server.respond(request, { getClientAddress })
function to generate a Response and responds with it - expose any platform-specific information to SvelteKit via the
platform
option passed toserver.respond
- Globally shims
fetch
to work on the target platform, if necessary. SvelteKit provides a@sveltejs/kit/install-fetch
helper for platforms that can usenode-fetch
- Imports
- Bundle the output to avoid needing to install dependencies on the target platform, if necessary
- Put the user's static files and the generated JS/CSS in the correct location for the target platform
Where possible, we recommend putting the adapter output under the build/
directory with any intermediate output placed under .svelte-kit/[adapter-name]
.
previous
Vercel
next
Advanced routing