CompileOptions object that controls how your components are compiled.
Core Options
string
Used for debugging hints and sourcemaps. Your bundler plugin will set it automatically.
boolean
default:"false"
If
true, causes extra code to be added that performs runtime checks and provides debugging information during development.'client' | 'server' | false
default:"'client'"
'client': Emits code designed to run in the browser'server': Emits code suitable for server-side renderingfalse: Generates nothing (useful for tooling that only needs warnings)
string
Sets the name of the resulting JavaScript class (though the compiler will rename it if it would otherwise conflict with other variables in scope). If unspecified, will be inferred from
filename.Component Behavior
boolean | undefined
default:"undefined"
true: Forces runes mode for the entire componentfalse: Forces the compiler to ignore runes, even if detectedundefined: Infers runes mode from component code (default)
boolean
default:"false"
If
true, tells the compiler to generate a custom element constructor instead of a regular Svelte component.'html' | 'svg' | 'mathml'
default:"'html'"
The namespace of the component’s elements.
boolean
default:"false"
If
true, getters and setters will be created for the component’s props. If false, they will only be created for readonly exported values. If compiling with customElement: true, this defaults to true.boolean
default:"false"
If
true, tells the compiler that you promise not to mutate any objects. This allows it to be less conservative about checking whether values have changed.CSS Options
'injected' | 'external'
'injected': Styles are included in theheadwhen usingrender(), and injected when the component mounts. For custom elements, styles are injected to the shadow root.'external': CSS is only returned in thecssfield of the compilation result. Most bundler plugins use this for better performance (smaller JS bundles, cacheable CSS files).
'injected' when customElement: true.CssHashGetter
A function that takes Type:
{ hash, css, name, filename } and returns the string used as a classname for scoped CSS. Defaults to svelte-${hash(filename ?? css)}.Code Generation
boolean
default:"false"
If
true, your HTML comments will be preserved in the output. By default, they are stripped out.boolean
default:"false"
If
true, whitespace inside and between elements is kept as you typed it, rather than removed or collapsed to a single space where possible.'html' | 'tree'
default:"'html'"
Which strategy to use when cloning DOM fragments:
'html': Populates a<template>withinnerHTMLand clones it (faster, but incompatible with strict CSP)'tree': Creates the fragment one element at a time and then clones it (slower, works everywhere)
'tree' if your Content Security Policy includes require-trusted-types-for 'script'.boolean
default:"true"
If
true, exposes the Svelte major version in the browser by adding it to a Set stored in window.__svelte.v.Sourcemaps
object | string
An initial sourcemap that will be merged into the final output sourcemap. This is usually the preprocessor sourcemap.
string
Used for your JavaScript sourcemap.
string
Used for your CSS sourcemap.
Module Options
string
default:"process.cwd()"
Used for ensuring filenames don’t leak filesystem information. Your bundler plugin will set it automatically.
(warning: Warning) => boolean
A function that filters warnings. Return
true to keep the warning, false to discard it.Advanced Options
boolean
default:"false"
If
true, compiles components with hot reloading support.boolean
default:"false"
If
true, returns the modern version of the AST. Will become true by default in Svelte 6, and the option will be removed in Svelte 7.object
4 | 5
default:"5"
Applies a transformation so the default export can be instantiated the same way as in Svelte 4:
- As a class when compiling for the browser (like using
createClassComponent()fromsvelte/legacy) - As an object with a
.render()method when compiling for the server
object
Experimental compiler features.
boolean
Allow
await keyword in deriveds, template expressions, and the top level of components.Usage Examples
Development Build
Production Build
SSR Configuration
Custom Element
Strict CSP Environment
With Vite Plugin
Related
- compile() - Main compilation function
- preprocess() - Preprocess before compiling
- migrate() - Migrate from Svelte 4 to 5