svelte.config.js file at the root of your project. This config object is used by SvelteKit and other tooling that integrates with Svelte.
Basic Example
Config
An array of file extensions that SvelteKit will treat as Svelte components.
KitConfig
Thekit property configures SvelteKit and can have the following properties:
Adapter
Your adapter is run when executing
vite build. It determines how the output is converted for different platforms.Alias
An object containing zero or more aliases used to replace values in
import statements. These aliases are automatically passed to Vite and TypeScript.Run
npm run dev to have SvelteKit generate the required alias configuration in jsconfig.json or tsconfig.json.App Directory
The directory where SvelteKit keeps its stuff, including static assets (such as JS and CSS) and internally-used routes.If
paths.assets is specified, there will be two app directories — ${paths.assets}/${appDir} and ${paths.base}/${appDir}.CSP
Content Security Policy configuration. CSP helps protect your users against cross-site scripting (XSS) attacks.
Whether to use hashes or nonces to restrict
<script> and <style> elements. 'auto' uses hashes for prerendered pages and nonces for dynamically rendered pages.Directives that will be added to
Content-Security-Policy headers.Directives that will be added to
Content-Security-Policy-Report-Only headers.CSRF
Protection against cross-site request forgery (CSRF) attacks.
Whether to check the incoming
origin header for POST, PUT, PATCH, or DELETE form submissions.An array of origins that are allowed to make cross-origin form submissions to your app.If the array contains
'*', all origins will be trusted (not recommended!).Embedded
Whether or not the app is embedded inside a larger app. If
true, SvelteKit will add its event listeners on the parent of %sveltekit.body% instead of window.It is generally not supported to embed multiple SvelteKit apps on the same page.
Environment Variables
Environment variable configuration.
The directory to search for
.env files.A prefix that signals that an environment variable is safe to expose to client-side code.See env/dynamic/public.
A prefix that signals that an environment variable is unsafe to expose to client-side code. Variables matching neither the public nor private prefix will be discarded.See env/dynamic/private.
Inline Style Threshold
Inline CSS inside a
<style> block at the head of the HTML. This value specifies the maximum length of a CSS file in UTF-16 code units to be inlined.This results in fewer initial requests but generates larger HTML output and reduces browser cache effectiveness. Use advisedly.
Module Extensions
An array of file extensions that SvelteKit will treat as modules. Files with extensions that match neither
config.extensions nor config.kit.moduleExtensions will be ignored by the router.Output Directory
The directory that SvelteKit writes files to during
dev and build. You should exclude this directory from version control.Output
Options related to the build output format.
SvelteKit will preload the JavaScript modules needed for the initial page to avoid import ‘waterfalls’.
modulepreload- uses<link rel="modulepreload">. Best results in Chromium, Firefox 115+, and Safari 17+.preload-js- uses<link rel="preload">. Prevents waterfalls but Chromium parses modules twice.preload-mjs- uses<link rel="preload">with.mjsextension to prevent double-parsing.
How JavaScript and CSS files are loaded.
'split'- Splits the app into multiple .js/.css files loaded lazily (recommended)'single'- Creates one .js bundle and one .css file for the entire app'inline'- Inlines all JavaScript and CSS into the HTML (usable without a server)
Paths
Path configuration for your app.
A root-relative path that must start, but not end with Use
/ (e.g. /base-path). Specifies where your app is served from.base from $app/paths in your links: <a href="{base}/page">Link</a>.An absolute path that your app’s files are served from. Useful if files are served from a storage bucket.
Whether to use relative asset paths.If
true, base and assets imported from $app/paths will be replaced with relative asset paths during server-side rendering.Set to false if your app uses a <base> element.Prerender
Prerendering configuration. See Prerendering.
How many pages can be prerendered simultaneously.
Whether SvelteKit should find pages to prerender by following links from
entries.An array of pages to prerender, or start crawling from. The
* string includes all routes with no required parameters.How to respond to HTTP errors encountered while prerendering.
The value of
url.origin during prerendering; useful if it is included in rendered content.Router
Router configuration.
What type of client-side router to use.
'pathname'- Current URL pathname determines the route (default)'hash'- Route determined bylocation.hash(disables SSR and prerendering)
How to determine which route to load when navigating.
'client'- Use manifest loaded upfront (faster navigation, larger initial load)'server'- Ask server for each navigation (smaller initial load, hidden route list)
Service Worker
Service worker configuration.
Whether to automatically register the service worker, if it exists.
kit.serviceWorker.files
(filename: string) => boolean
default:"(filename) => !/\\.DS_Store/.test(filename)"
Determine which files in your
static directory will be available in $service-worker.files.TypeScript
TypeScript configuration.
kit.typescript.config
(config: Record<string, any>) => Record<string, any> | void
default:"(config) => config"
A function that allows you to edit the generated
tsconfig.json. You can mutate the config or return a new one.Version
Client-side navigation can be buggy if you deploy a new version while people are using it. SvelteKit helps solve this through version management.
The current app version string. This must be deterministic (e.g. a commit ref rather than
Math.random()).The interval in milliseconds to poll for version changes. If
0, no polling occurs.