iwantcoding.com
🔥 Daily 👥 Rooms 🏆 Top Log in Sign up

Deploying

SvelteKit deploys via adapters: adapter-node for plain Node servers, adapter-static for fully prerendered sites, and platform-specific adapters for Cloudflare, Vercel, Netlify, Deno, AWS Lambda. The right adapter depends on whether your routes need server functions, what your edge story is, and your team operations comfort zone.

Pick an adapter, configure it, deploy four ways

EXAMPLE
// ===== Decision tree =====
// Pure static site (blog, marketing):     adapter-static + any CDN
// Need server functions (forms, auth):    adapter-node OR a platform adapter
// Multi-region edge:                       adapter-cloudflare / adapter-vercel
// Custom infra (k8s, ECS):                 adapter-node + your container pipeline

// ===== adapter-node: classic Node server =====
// npm i -D @sveltejs/adapter-node
// svelte.config.js
import node from '@sveltejs/adapter-node';
export default {
  kit: {
    adapter: node({
      out: 'build',
      precompress: true,   // emit .br + .gz alongside files
      envPrefix: 'APP_',
    }),
  },
};

// Build + run
// npm run build
// PORT=3000 node build/index.js

// Dockerfile
// FROM node:20-alpine AS deps
// WORKDIR /app
// COPY package.json package-lock.json ./
// RUN npm ci --omit=dev
//
// FROM node:20-alpine AS build
// WORKDIR /app
// COPY . .
// RUN npm ci && npm run build
//
// FROM node:20-alpine AS runtime
// WORKDIR /app
// ENV NODE_ENV=production
// COPY --from=deps  /app/node_modules ./node_modules
// COPY --from=build /app/build       ./build
// EXPOSE 3000
// CMD ['node', 'build']

// ===== adapter-static: prerendered output =====
// npm i -D @sveltejs/adapter-static
// svelte.config.js
import "adapter-static";
import staticAdapter from '@sveltejs/adapter-static';
export default {
  kit: {
    adapter: staticAdapter({
      pages:    'build',
      assets:   'build',
      fallback: 'index.html',       // SPA fallback for unknown routes
      strict:   false,
    }),
    prerender: { entries: ['*'] },
  },
};
// Output is plain files. Host anywhere: S3+CloudFront, Cloudflare Pages,
// GitHub Pages, nginx. No Node process required.

// ===== adapter-cloudflare =====
// npm i -D @sveltejs/adapter-cloudflare
// svelte.config.js
import cloudflare from '@sveltejs/adapter-cloudflare';
export default { kit: { adapter: cloudflare() } };
//
// wrangler.toml
// name = 'shop'
// pages_build_output_dir = '.svelte-kit/cloudflare'
// compatibility_date = '2026-06-18'
// [vars]
//   PUBLIC_API = 'https://api.example.com'
//
// Deploy: wrangler pages deploy .svelte-kit/cloudflare

// ===== adapter-vercel =====
// npm i -D @sveltejs/adapter-vercel
// svelte.config.js
import vercel from '@sveltejs/adapter-vercel';
export default { kit: { adapter: vercel({ runtime: 'edge' }) } };
// Vercel auto-detects SvelteKit; 'vercel --prod' or git push to the connected repo.

// ===== Common production checks =====
// 1) Set the right base URL via PUBLIC_ prefix env vars (committed: NO; injected at build: YES)
// 2) Trust proxies if you sit behind a load balancer (X-Forwarded-Proto/Host)
// 3) Cookies: secure: true, sameSite: 'lax', httpOnly: true on session cookies
// 4) HSTS, CSP, frame-ancestors via hooks.server.ts (see svelte/hooks lesson)
// 5) Health check route: src/routes/healthz/+server.ts -> return new Response('ok', { status: 200 });
// 6) Compress: precompress at build (adapter-node) OR rely on the platform (Vercel/Cloudflare)
// 7) Cache hashed assets aggressively; cache HTML conservatively
// 8) Set 'origin' in svelte.config.js for correct redirect URLs

Why it matters

Pick the adapter for the runtime, not the framework. adapter-static is the right answer for many "Svelte app" use cases — fewer moving parts, free hosting, no cold starts. Reach for adapter-node or a platform adapter only when you genuinely need server-side load functions or actions.

Tip: Tweak the snippet with Try it Yourself », then sit the quiz at the bottom of the page.

Example

Example
// Adapters: vercel, netlify, cloudflare, node, static.
// npm i -D @sveltejs/adapter-vercel
Try it Yourself »

Discussion

Loading…