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 + sibling entries.ts → additive dist/*.html
  • isr: { '/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 .ts carrier)
  • per-page prerender = true | false | 'auto' — leaf wins, else nearest explicit wrapper, else global prerender.entries (entries.ts can be async, 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-Cookie untouched, Location always passes)
  • layout = false | true | 'dir' — no @ files: false renders bare, 'dir' keeps wrappers down to dir, true pins the full chain back on (composition-only — skipped wrappers' loads/middleware still run)

Client router

  • goto / preloadData / preloadCode / pushState / replaceState (shallow — page.state survives traversal)
  • captureSnapshot / restoreSnapshot (manual snapshot lite); beforeNavigate (cancellable) / afterNavigate / onNavigate
  • page / navigating / updated stores (checkUpdated() polls X-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]string threaded through dispatch + cookie helpers
  • HEAD auto-handled on GET arms; OPTIONS is CORS-preflight-only
EnvEffect
PORTV backend port (wins over config)
SWELTE_CORS_ORIGINCORS allowlist
SWELTE_SSR / SWELTE_SSR_URLembedded QuickJS / dev sidecar renderer
SWELTE_BODY_LIMIT / RATE_LIMIT / HANDLER_TIMEOUT_MSrequest hardening
SWELTE_CSRF_CHECK_ORIGIN / METHOD_OVERRIDECSRF gate / ?_method=
SWELTE_VERSION / SWELTE_ISR / SWELTE_SWversion stamp / ISR map / force service worker