Skip to main content
Svelte Fundamentals
CHAPTER 29 Beginner

Deploying Svelte Applications

Updated: May 18, 2026
5 min read

# CHAPTER 29

Deploying Svelte Applications

1. Chapter Introduction

Your Svelte app is built — now it needs to reach the world. This chapter covers the complete deployment workflow: building for production, configuring environment variables, and deploying to the three most popular platforms for Svelte: Vercel (official recommended), Netlify, and Firebase Hosting.

2. Learning Objectives

  • Build a production-optimized Svelte bundle.
  • Configure environment variables securely.
  • Deploy to Vercel (recommended for SvelteKit).
  • Deploy to Netlify.
  • Deploy to Firebase Hosting.
  • Set up custom domains.

3. Production Build

bash
12345
# Build for production
npm run build

# Preview the production build locally
npm run preview
text
123456
Output in /dist:
dist/
├── index.html
├── assets/
│   ├── index-abc123.js     ← Your compiled Svelte code (minified)
│   └── index-def456.css    ← Compiled CSS

4. Environment Variables

bash
1234567
# .env (NOT committed to git)
VITE_API_URL=https://api.myapp.com
VITE_FIREBASE_API_KEY=your_key_here

# .env.example (committed to git — template for others)
VITE_API_URL=
VITE_FIREBASE_API_KEY=
javascript
1234
// Access in Svelte components
const apiUrl = import.meta.env.VITE_API_URL;
const mode = import.meta.env.MODE; // 'development' or 'production'
const isDev = import.meta.env.DEV;

5. SvelteKit Adapters

SvelteKit needs an adapter that matches your deployment target:
bash
1234567891011
# For Vercel
npm install @sveltejs/adapter-vercel

# For Netlify
npm install @sveltejs/adapter-netlify

# For static sites (GitHub Pages, Firebase Hosting)
npm install @sveltejs/adapter-static

# Auto-detect (good for most platforms)
npm install @sveltejs/adapter-auto
svelte.config.js
1234567
import adapter from '@sveltejs/adapter-vercel';

export default {
  kit: {
    adapter: adapter()
  }
};

6. Deploying to Vercel

Method 1: Vercel CLI

bash
1234
npm install -g vercel
vercel login
vercel          # Follow prompts
vercel --prod   # Deploy to production

Method 2: GitHub Integration (recommended)

  1. 1. Push your project to GitHub.
  1. 2. Go to vercel.com → New Project.
  1. 3. Import from GitHub.
  1. 4. Vercel auto-detects SvelteKit.
  1. 5. Add environment variables in Vercel dashboard.
  1. 6. Click Deploy — live in ~60 seconds!

Every git push to main auto-deploys!

7. Deploying to Netlify

bash
1234
npm install -g netlify-cli
netlify login
npm run build
netlify deploy --dir=dist --prod
netlify.toml
12345678
[build]
  command = "npm run build"
  publish = "dist"

[[redirects]]
  from = "/*"
  to = "/index.html"
  status = 200

GitHub Integration:

  1. 1. Push to GitHub.
  1. 2. Go to app.netlify.com → New site from Git.
  1. 3. Select your repo.
  1. 4. Build command: npm run build, Publish dir: dist.
  1. 5. Add environment variables in Netlify settings.

8. Deploying to Firebase Hosting

bash
123456789
npm install -g firebase-tools
firebase login
firebase init hosting

# Select 'dist' as public directory
# Configure as SPA: Yes

npm run build
firebase deploy --only hosting
firebase.json
123456789
{
  "hosting": {
    "public": "dist",
    "ignore": ["firebase.json", "**/.*", "**/node_modules/**"],
    "rewrites": [
      { "source": "**", "destination": "/index.html" }
    ]
  }
}

9. CI/CD with GitHub Actions

yaml
12345678910111213141516171819202122
# .github/workflows/deploy.yml
name: Deploy to Vercel

on:
  push:
    branches: [main]

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-node@v3
        with: { node-version: '18' }
      - run: npm ci
      - run: npm run build
      - uses: amondnet/vercel-action@v25
        with:
          vercel-token: ${{ secrets.VERCEL_TOKEN }}
          vercel-org-id: ${{ secrets.VERCEL_ORG_ID }}
          vercel-project-id: ${{ secrets.VERCEL_PROJECT_ID }}
          vercel-args: '--prod'

10. Performance Checklist for Production

text
12345678
✅ npm run build (production mode)
✅ Environment variables set in hosting dashboard
✅ Images optimized (WebP format)
✅ Lazy load heavy components
✅ Enable gzip/brotli on host (usually auto)
✅ Set Cache-Control headers for assets
✅ Custom domain configured
✅ HTTPS enabled (all major hosts auto-provide)

11. MCQs

Question 1

What command creates a production build?

Question 2

What Vite prefix is required for env vars accessible in the browser?

Question 3

What is a SvelteKit adapter?

Question 4

What adapter is recommended for Vercel?

Question 5

What adapter creates a fully static site?

Question 6

What Netlify config file specifies build settings?

Question 7

Why do SPAs need a redirect rule on hosting?

Question 8

How does GitHub integration with Vercel/Netlify work?

Question 9

What does import.meta.env.VITEAPIURL return?

Question 10

Should .env be committed to version control?

12. Interview Questions

  • Q: What is a SvelteKit adapter and why is it needed for different deployment targets?
  • Q: How do you securely manage API keys in a Svelte application?

13. Summary

Deploying Svelte is one of the fastest and simplest experiences in modern web development. Vercel's zero-configuration SvelteKit support means a project goes from code to production URL in under 2 minutes. For static Svelte apps, any hosting provider works with a one-command deploy.

14. Next Chapter Recommendation

In Chapter 30: Final Projects and Real-World Applications, we review complete project blueprints — from an ecommerce frontend to a real-time chat application — that consolidate everything learned in this course.

Finish this Chapter

Save your progress on your learning path and prepare for coding interview challenges.

Discussion

Join the discussion

Log in or create a free account to participate.

Sort: ·