Encodera

Thanks for reading!

Donate to the site — we work hard for you.

Contents

Adapters and deployment

For the site to work beyond your computer, the project is built with npm run build. The result depends on where the site will run: on a server with Node.js, on a cloud platform or as a set of static files. For each target there is an adapter — a package that turns the SvelteKit build into the needed format.

The default adapter

A project from sv is already set up with adapter-auto:

// svelte.config.js
import adapter from '@sveltejs/adapter-auto';
 
const config = {
  kit: {
    adapter: adapter()
  }
};
 
export default config;

adapter-auto detects popular platforms — Vercel, Netlify, Cloudflare — and uses the right adapter when building there. For your own server you choose the adapter explicitly.

Your own server: adapter-node

Install the adapter:

npm install -D @sveltejs/adapter-node

And replace the import in the settings:

// svelte.config.js
import adapter from '@sveltejs/adapter-node';
 
const config = {
  kit: {
    adapter: adapter()
  }
};
 
export default config;

Now build and start the project:

npm run build
node build

The build appears in the build folder, and node build starts the server. The terminal shows an address — by default http://localhost:3000 — and the blog opens with its forms and API. The port is changed with an environment variable: PORT=8080 node build.

A static site: adapter-static

If a site has no server part — no form actions, no +server.js — it can be built into plain HTML files and put on any hosting:

npm install -D @sveltejs/adapter-static

In svelte.config.js import @sveltejs/adapter-static, and in the root layout enable prerendering of all pages:

// src/routes/+layout.js
export const prerender = true;

After npm run build the build folder contains ready HTML files for every page.

Which adapter to choose

Where the site runsAdapter
Vercel, Netlify, Cloudflareadapter-auto (or the platform's adapter)
your own server or Dockeradapter-node
static hostingadapter-static

Before publishing, check the build locally: npm run preview runs the built version.

Common mistake

Choosing adapter-static for a blog with forms and an API. Actions from +page.server.js and +server.js files need a running server, while a static site is only files. The build stops with an error about pages that cannot be prerendered. Such a site needs adapter-node or a cloud platform adapter.

Thanks for reading!

Donate to the site — we work hard for you.