Deploying SvelteKit Applications

Tilda provides first-class support for SvelteKit applications, making it easy to deploy your Svelte projects. This guide will walk you through the process of deploying a SvelteKit application on Tilda.

Prerequisites

Installation

First, install the Tilda CLI globally:

Install Tilda CLI
Bash
npm install -g @tildacloud/cli@latest

Project Structure

Tilda expects a standard SvelteKit project structure. Your project should have:

Building Your Application

Adapter Configuration

Tilda uses the official @sveltejs/adapter-node for SvelteKit deployments. Tilda will pass the necessary environment variables to SvelteKit during the build process to configure the adapter.

You don't need to manually configure the adapter or modify your SvelteKit configuration - the build process handles this automatically.

If you have any issues configuring the adapter, refer to SvelteKit's Node servers documentation on how to configure the adapter.

Build Command

To build your SvelteKit application for deployment, use the tilda build svelte command:

Build Command
Bash
tilda build svelte

Build Options

The build command supports several options:

Build Options
Bash
# Specify project directory
tilda build svelte --projectDir ./my-sveltekit-app

# Use custom build command
tilda build svelte --buildCommand 'npm run build:custom'

Deployment

After building your application, deploy it using:

Deploy Command
Bash
tilda deploy --project my-project --site my-site

Static Assets

Place your static assets in the static/ directory. They will be automatically served at the root path of your site.

Development Workflow

For local development:

  1. Make changes to your SvelteKit application
  2. Test locally using npm run dev
  3. Build using tilda build svelte
  4. Deploy using tilda deploy

CI/CD Integration

Here's an example GitHub Actions workflow:

GitHub Actions Workflow
YAML
name: Deploy SvelteKit App
on:
  push:
    branches: [ main ]

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Use Node.js
        uses: actions/setup-node@v4
        with:
          node-version: '20.x'
      - name: Install dependencies
        run: npm ci
      - name: Install Tilda CLI
        run: npm install -g @tildacloud/cli
      - name: Build and Deploy
        env:
          TILDA_CLI_INLINE_IDENTITY_JSON: ${{ secrets.TILDA_DEPLOYMENT_KEY }}
        run: |
          tilda build svelte
          tilda deploy --project my-project --site my-site

Troubleshooting

Build Failures

If your build fails, check:

Runtime Errors

For runtime errors:

Tip: Enable source maps in your production build for better error tracking.