CompileOptions object that controls how your components are compiled.
Core Options
Used for debugging hints and sourcemaps. Your bundler plugin will set it automatically.
If
true, causes extra code to be added that performs runtime checks and provides debugging information during development.'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)
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
true: Forces runes mode for the entire componentfalse: Forces the compiler to ignore runes, even if detectedundefined: Infers runes mode from component code (default)
If
true, tells the compiler to generate a custom element constructor instead of a regular Svelte component.The namespace of the component’s elements.
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.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': 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.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
If
true, your HTML comments will be preserved in the output. By default, they are stripped out.If
true, whitespace inside and between elements is kept as you typed it, rather than removed or collapsed to a single space where possible.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'.If
true, exposes the Svelte major version in the browser by adding it to a Set stored in window.__svelte.v.Sourcemaps
An initial sourcemap that will be merged into the final output sourcemap. This is usually the preprocessor sourcemap.
Used for your JavaScript sourcemap.
Used for your CSS sourcemap.
Module Options
Used for ensuring filenames don’t leak filesystem information. Your bundler plugin will set it automatically.
A function that filters warnings. Return
true to keep the warning, false to discard it.Advanced Options
If
true, compiles components with hot reloading support.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.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
Experimental compiler features.
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