Svelte 74 🧡 SvelteKit Adapters — @sveltejs/adapter-auto, adapter-node, adapter-static, adapter-vercel
SvelteKit is designed to be deployment-agnostic. This is achieved through an abstraction layer called an “adapter.” An adapter is a small build-time plugin that translates the output of your SvelteKit project into the specific format required by a host—whether that is a Node.js server, a collection of static files, or a serverless function on a cloud provider. By separating your application logic from the deployment environment, SvelteKit ensures that your codebase remains portable and decoupled from the infrastructure you choose.
When you run a build command, SvelteKit compiles your application into a generic internal format. The adapter then consumes this internal structure to create an “entry point” and a “manifest” tailored to the specific target environment. This mechanism allows you to change your hosting provider simply by swapping an adapter in svelte.config.js, without altering a single line of your actual Svelte component or load function logic.
Key point: Adapters are the translation layer between SvelteKit’s platform-agnostic build output and the target infrastructure; they handle the technical complexities of serverless execution, node runtime configurations, or static asset distribution so you can focus on application features.
Why exists
The deployment fragmentation problem. The modern web landscape consists of diverse environments: traditional servers, Vercel/Netlify serverless runtimes, Edge functions, and static object storage. Adapters exist to encapsulate the specific API calls, request formats, and environment variables unique to these platforms.
The portability requirement. Developers often change infrastructure based on cost, scale, or feature needs. Adapters decouple your source code from the hosting platform, allowing your app to move from a local Node.js environment to a global Edge network without rewriting your data-fetching patterns.
The resource optimization requirement. Different hosts have different capabilities. A static adapter generates only the essential files to keep builds small, whereas a Node adapter prepares a full server environment with http support, ensuring the app is optimized for the specific hardware/runtime constraints of the destination.
The framework integration requirement. Cloud providers often have specific requirements for where and how files are served (e.g., headers, rewrites, redirects). Adapters automate the generation of platform-specific configuration files (like vercel.json or netlify.toml), saving you from manually writing complex infrastructure manifests.
The build-process decoupling. By isolating the deployment logic into a build-time plugin, the core SvelteKit team can improve framework performance without needing to update the platform-specific code for every hosting provider. The community can maintain and iterate on adapters independently as platforms evolve.
a. How adapters function within the build process
An adapter is executed at the very end of the svelte-kit build process. After SvelteKit has generated the internal manifest of all your routes, static assets, and dynamic handlers, it calls the adapter. The adapter essentially receives a filesystem containing the server (the JS logic) and client (the static files) directories.
// The internal contract of an adapter
export default function adapter(options) {
return {
name: '@sveltejs/adapter-example',
async adapt(builder) {
// 1. Clean previous build
builder.rimraf(options.out);
// 2. Log build metrics
builder.log.info('Adapting build...');
// 3. Write files to target folder
builder.writeClient(options.out);
builder.writeServer(options.out);
}
};
}
This interface allows adapters to perform tasks like transpiling code for a specific runtime (e.g., minifying for Edge), creating platform-specific entry points (e.g., api/index.js for Vercel), or even executing post-build scripts to package the output into a Docker image or a ZIP file for AWS Lambda.
b. Standard adapters: Node.js and Static
adapter-node is the standard choice for self-hosting. It produces a standalone Node.js server that runs your SvelteKit app. It is the most flexible adapter because it gives you control over the underlying server process, allowing you to use middleware, custom health checks, or even integrate it with an existing express server.
// svelte.config.js for Node
import node from '@sveltejs/adapter-node';
export default {
kit: { adapter: node({ out: 'build' }) }
};
adapter-static is the choice for static sites. It takes your pre-rendered pages and assets and builds them into a flat directory structure. Unlike adapter-node, it cannot handle dynamic requests at runtime unless the logic is offloaded to a separate API service. It is perfect for low-cost, high-performance static hosting via CDNs like Cloudflare or GitHub Pages.
c. Cloud-native adapters: Auto and Vercel
adapter-auto is the “smart” adapter. During the build process, it attempts to detect your environment. If it sees you are deploying to Vercel, it automatically applies adapter-vercel settings. If it detects Netlify, it switches to adapter-netlify. This is the recommended choice for most users because it abstracts the platform choice entirely.
// svelte.config.js for Auto
import auto from '@sveltejs/adapter-auto';
export default {
kit: { adapter: auto() }
};
adapter-vercel (and similar platform-specific ones like adapter-netlify or adapter-cloudflare) provides deeper integration. It allows you to configure platform-exclusive features like Vercel’s Edge Config, ISR (Incremental Static Regeneration), or specific region settings. You use these explicitly when adapter-auto is insufficient for your specific infrastructure needs.
Complete Example Session
// ============================================
// PART 1: AUTO ADAPTER (THE DEFAULT)
// ============================================
import auto from '@sveltejs/adapter-auto';
export default { kit: { adapter: auto() } };
// ============================================
// PART 2: NODE ADAPTER (FOR CUSTOM SERVERS)
// ============================================
import node from '@sveltejs/adapter-node';
export default { kit: { adapter: node({ out: 'build' }) } };
// ============================================
// PART 3: STATIC ADAPTER (FOR CDNS)
// ============================================
import staticAdapter from '@sveltejs/adapter-static';
export default { kit: { adapter: staticAdapter({ fallback: '404.html' }) } };
// ============================================
// PART 4: VERCEL ADAPTER (FOR CLOUD FUNCTIONS)
// ============================================
import vercel from '@sveltejs/adapter-vercel';
export default { kit: { adapter: vercel({ runtime: 'nodejs18.x' }) } };
These parts illustrate how a single line in svelte.config.js determines the entire deployment infrastructure of your application.
Quick Reference
Primary Adapters
| Adapter | Target | Primary Use Case |
|---|---|---|
adapter-auto | Detected | General purpose, convenience |
adapter-node | Node.js | Self-hosting, Docker, VPS |
adapter-static | Flat files | CDNs, GitHub Pages, S3 |
adapter-vercel | Vercel | Vercel platform-specific features |
Configuration Key Features
| Adapter | Key Feature |
|---|---|
adapter-node | Custom out directory |
adapter-static | fallback page for SPA |
adapter-vercel | Runtime versions, edge support |
Best Practices
✅ Do This:
// Use adapter-auto for initial development
adapter: auto() // ✅
// Configure static fallback for SPA modes
fallback: 'index.html' // ✅
// Use adapter-node for Docker environments
adapter: node({ out: 'build' }) // ✅
❌ Don’t Do This:
// Don't switch adapters constantly in production
// (different adapters behave differently) // ❌
// Don't mix static adapter with SSR routes
// (build will fail or be incomplete) // ❌
// Don't ignore adapter-specific documentation
// (some have unique edge-case flags) // ❌
Common Pitfalls
| Pitfall | Why It Happens | Fix |
|---|---|---|
| Missing runtime | Platform doesn’t match adapter | Check adapter compatibility |
| 404 on Static | Fallback not configured | Set fallback: 'index.html' |
| Port Conflict | adapter-node defaults to 3000 | Set PORT env variable |
| Build Errors | adapter-static used on SSR route | Set prerender = true |
Real-World Examples
1. Standard Node Deployment
import node from '@sveltejs/adapter-node';
2. Static CDN deployment
import staticAdapter from '@sveltejs/adapter-static';
3. Targeted Vercel Deployment
import vercel from '@sveltejs/adapter-vercel';
4. Auto-detect deployment
import auto from '@sveltejs/adapter-auto';
5. Custom Output Directory (Node)
adapter: node({ out: 'server-build' })
6. SPA Fallback (Static)
adapter: staticAdapter({ fallback: 'index.html' })
7. Edge Runtime (Vercel)
adapter: vercel({ edge: true })
8. Prerendered Static
adapter: staticAdapter({ pages: 'public' })
9. Port Configuration (Node)
PORT=8080 node build
10. Multi-adapter testing
// Switch in svelte.config.js before build
Visual
The Adapter Build Pipeline
┌─────────────────────────────────────────────────────────┐
│ Source Code (SvelteKit) │
│ │ │
│ ▼ │
│ Build Manifest Generation │
│ │ │
│ ▼ │
│ Adapter Plugin (The Bridge) ──► Platform Config │
│ │ │
│ ▼ │
│ Output Directory (/build) ──► Upload to Cloud │
└─────────────────────────────────────────────────────────┘
Node vs Static Logic
┌─────────────────────────────────────────────────────────┐
│ adapter-node │ adapter-static │
│ ┌──────────────────────┐ │ ┌──────────────────────┐ │
│ │ Node Runtime Server │ │ │ Static HTML/CSS/JS │ │
│ │ (Process stays up) │ │ │ (Served via CDN) │ │
│ └──────────────────────┘ │ └──────────────────────┘ │
│ │ │ │ │
│ SSR & APIs available │ Client-side routing only │
└─────────────────────────────────────────────────────────┘
Summary
| Item | Value |
|---|---|
| Purpose | Infrastructure bridging |
| Config File | svelte.config.js |
| Primary Plugin | adapter-* |
| Build output | Platform-specific artifacts |
Key takeaways:
- Adapters are build plugins. They don’t change how your code works; they change how your code is packaged for the server or browser.
adapter-autois the starting point. It is designed to handle 90% of use cases by sniffing out your hosting environment.- Use
adapter-nodefor control. If you need to manage a VPS, a custom Docker image, or specific server middleware, this is your adapter. adapter-staticis for speed and simplicity. It is perfect for sites that can be pre-rendered or are pure SPAs, drastically lowering hosting costs.- Switching is seamless. Because of the adapter pattern, you can pivot your hosting infrastructure as your project grows without being forced to refactor your application logic.
Remember: Adapters turn your code into an artifact that your specific infrastructure can execute. Choose the adapter that best matches your target host, respect the constraints (like static adapter’s lack of server runtime), and you will find SvelteKit to be one of the most portable web frameworks in the ecosystem.
Stop using slow, ad-bloated tool sites! 🤮
🔎 Search “KandZ Tools” on Google to use many professional utilities for free.
KandZ.me is the ultimate minimalist hub for:
✅ Finance (Mortgage, Interest, Inflation)
✅ Tech (Base64, JSON, Dev Suite, IP)
✅ Health (BMI, BMR, TDEE)
✅ Productivity (Timer, Workspace, QR)
⚡️ Fast & Private
🔒 No data leaves your device
💎 100% Free
🔗 Use it now: https://tools.kandz.me
🔖 Bookmark it—you’ll need it later!