Config + env
Put app options in the swelte key. Runtime environment variables override their
corresponding config values; unset runtime knobs use config or built-in defaults. Image and outbox
contracts are validated, and invalid options fail the build.
svelte.config.js (swelte key)
svelte.config.js
import { defineConfig } from '@swelte/core/config';
export default defineConfig({
preprocess: vitePreprocess(),
swelte: { name: 'myapp', routesDir: 'src/routes', libDir: 'src/lib',
outDir: '.swelte', distDir: 'dist', port: 8131, corsOrigin: '',
trailingSlash: 'ignore', base: '', assets: '', csp: '', csrf: 'ignore',
methodOverride: false, version: '', target: 'auto' }
});defineConfig keeps swelte non-enumerable: invisible to svelte(), readable by loadConfig.
Knobs
Rendering
prerender.entries: off | static | all+ siblingentries.ts→ additivedist/*.htmlisr: { '/blog': 60 }→ public HTML caching, background regeneration and atomic replacement (ISR guide)offline.fallback— opt-in service worker + precache (offline guide)images— native build-time PNG/JPEG resizing and WebP variants (image guide)serviceWorker.outbox— explicit persistent mutations, retries and Background Sync (outbox guide)- per-route
ssr = false— SPA shell, async universal load client-side - per-route
csr = false— SSR HTML only, client mount/hydrate is a deliberate no-op (independent corner, same sibling.tscarrier) - per-page
prerender = true | false | 'auto'— leaf wins, else nearest explicit wrapper, else globalprerender.entries(entries.tscan beasync, incl. paginated fetch loops)
Per-route overrides
limits = { rate, rateWindowMs, timeoutMs, bodyLimit {— longest-prefix match overrides the global hardening knobs (single binary, no regions/runtime)serializedHeaders = ['x-foo', ...]— allowlists which load-envelope headers land on the HTML navigation (Set-Cookieuntouched,Locationalways passes)layout = false | true | 'dir'— no@files:falserenders bare,'dir'keeps wrappers down todir,truepins the full chain back on (composition-only — skipped wrappers' loads/middleware still run)
Client router
goto/preloadData/preloadCode/pushState/replaceState(shallow —page.statesurvives traversal)captureSnapshot/restoreSnapshot(manual snapshot lite);beforeNavigate(cancellable) /afterNavigate/onNavigatepage/navigating/updatedstores (checkUpdated()pollsX-Swelte-Version);data-sveltekit-* / data-swelte-*link options honored
Lifecycle
src/app.v:@[startup](boot once),@[reroute](rewrite first); ticks live in@swelte/plus(not core)locals map[string]stringthreaded through dispatch + cookie helpersHEADauto-handled on GET arms;OPTIONSis CORS-preflight-only
| Env | Effect |
|---|---|
PORT | V backend port (wins over config) |
SWELTE_CORS_ORIGIN | CORS allowlist |
SWELTE_SSR / SWELTE_SSR_URL | embedded QuickJS / dev sidecar renderer |
SWELTE_BODY_LIMIT / RATE_LIMIT / HANDLER_TIMEOUT_MS | request hardening |
SWELTE_CSRF_CHECK_ORIGIN / METHOD_OVERRIDE | CSRF gate / ?_method= |
SWELTE_VERSION / SWELTE_ISR / SWELTE_SW | version stamp / ISR map / force service worker |