@sveltejs/kit/vite module exports the SvelteKit Vite plugin that powers the framework’s build system and development server.
sveltekit
Returns an array of Vite plugins that enable SvelteKit functionality. This is the main entry point for integrating SvelteKit with Vite.A Promise that resolves to an array of Vite plugins, including the Svelte plugin and SvelteKit-specific plugins.
Basic Usage
What It Does
Thesveltekit() function returns multiple plugins that handle:
- Svelte compilation - Integrates
@sveltejs/vite-plugin-svelte - Routing - Scans your routes directory and generates the manifest
- Server-side rendering - Configures SSR build and dev server
- Code generation - Creates virtual modules like
$app/*,$env/*,$service-worker - Development mode - Provides HMR and the dev server
- Production builds - Orchestrates client, server, and service worker builds
- Prerendering - Handles static page generation
- Adapter integration - Runs your configured adapter after build
Configuration
The plugin reads your configuration fromsvelte.config.js. Most options are configured there:
Vite Config Integration
Virtual Modules
The SvelteKit plugin provides several virtual modules:$app/*
$env/*
$service-worker
Development Server
In development mode, the plugin:- Starts a Vite dev server with HMR
- Handles SSR for all routes
- Provides detailed error overlays
- Auto-reloads on configuration changes
- Optimizes dependencies
Production Builds
The plugin orchestrates multiple build steps:- Server build - Builds the SSR server and analyzes routes
- Client build - Builds the browser bundle with code splitting
- Service worker build - If configured, builds the service worker
- Prerendering - Generates static HTML for prerenderable pages
- Adapter - Runs your adapter to prepare for deployment
Advanced: Multiple Plugins
You can combine the SvelteKit plugin with other Vite plugins:Config Enforcement
SvelteKit enforces certain Vite configuration options to ensure correct operation. The following options will be overridden:appTypebasebuild.cssCodeSplitbuild.emptyOutDirbuild.manifestbuild.outDirbuild.rollupOptions.inputbuild.rollupOptions.outputbuild.rollupOptions.preserveEntrySignaturespublicDirresolve.alias(partially - SvelteKit aliases are added)root
vite.config.js, you’ll see a warning during build.
TypeScript
For TypeScript support, ensure you have the proper types:Environment Variables
The plugin handles environment variables based on SvelteKit conventions:PUBLIC_*variables are available in$env/static/publicand$env/dynamic/public- All variables are available in
$env/static/privateand$env/dynamic/private(server-only) - Variables are loaded from
.envfiles