How to Deploy SvelteKit: Step-by-Step Guide
To deploy a
SvelteKit app, first choose an adapter like @sveltejs/adapter-vercel or @sveltejs/adapter-node. Then, install the adapter, update svelte.config.js, build your app with npm run build, and deploy using your platform's method or run the Node server.Syntax
Deploying SvelteKit involves configuring an adapter in svelte.config.js. The adapter tells SvelteKit how to prepare your app for the target platform.
- adapter: The package that builds your app for a specific environment (e.g., Vercel, Netlify, Node).
- build command: Usually
npm run buildto create production files. - deploy command: Depends on the platform, like
vercel deployor runningnode buildfor Node adapter.
javascript
import adapter from '@sveltejs/adapter-vercel'; /** @type {import('@sveltejs/kit').Config} */ const config = { kit: { adapter: adapter(), } }; export default config;
Example
This example shows how to deploy a SvelteKit app to Vercel using the official adapter.
javascript
import adapter from '@sveltejs/adapter-vercel'; /** @type {import('@sveltejs/kit').Config} */ const config = { kit: { adapter: adapter() } }; export default config;
Output
No visible output; config sets up deployment for Vercel.
Common Pitfalls
- Forgetting to install the adapter package with
npm install. - Not updating
svelte.config.jsto use the adapter. - Running
npm run devinstead ofnpm run buildbefore deploying. - Using the wrong adapter for your hosting platform.
- Not setting environment variables required by your platform.
javascript
/* Wrong: No adapter configured */ export default { kit: {} }; /* Right: Adapter added */ import adapter from '@sveltejs/adapter-netlify'; export default { kit: { adapter: adapter() } };
Quick Reference
| Step | Command / Action |
|---|---|
| Install adapter | npm install @sveltejs/adapter-vercel |
| Update config | Set adapter in svelte.config.js |
| Build app | npm run build |
| Deploy | vercel deploy (or platform-specific) |
| Run Node server (if adapter-node) | node build |
Key Takeaways
Always install and configure the correct adapter for your deployment platform.
Run npm run build before deploying to generate production-ready files.
Use platform-specific deploy commands or run the Node server if using adapter-node.
Check environment variables and platform docs for smooth deployment.
Avoid deploying without building or without adapter configuration.