Skip to content
Migrate from Svelte · @pyreon/svelte-compat

Keep your stores. Move components to TSX.

@pyreon/svelte-compat runs the Svelte APIs your code imports, svelte/store plus lifecycle, context and events, on Pyreon's engine. It is not a .svelte compiler: components become TSX, and the store modules they share keep their imports.

npm install @pyreon/svelte-compat @pyreon/core @pyreon/reactivity @pyreon/runtime-dom npm install -D @pyreon/vite-plugin
before and after

The same Svelte code, on Pyreon.

Migrating from Svelte: before and after Svelte to Pyreon: the Svelte store module stays exactly as it is. The import from svelte/store resolves to @pyreon/svelte-compat, so 5 lines carry over unchanged. Code before: // stores/cart.ts: unchanged. `svelte/store` resolves to @pyreon/svelte-compat/store import { derived, writable } from 'svelte/store' export const items = writable<string[]>([]) export const count = derived(items, ($items: string[]) => $items.length) Code after: // stores/cart.ts: unchanged. `svelte/store` resolves to @pyreon/svelte-compat/store import { derived, writable } from 'svelte/store' export const items = writable<string[]>([]) export const count = derived(items, ($items: string[]) => $items.length) MIGRATE FROM SVELTE · WHAT STAYS: YOUR STORESSVELTE STORE MODULE · SAME FILE ON SVELTE-COMPAT// stores/cart.ts: unchanged. `svelte/store` resolves to @pyreon/svelte-compat/store+import { derived, writable } from 'svelte/store'export const items = writable<string[]>([])export const count = derived(items, ($items: string[]) => $items.length)unchanged: the import resolves to the compat package
An illustration of the code on each side, not a recording.
coverage

What @pyreon/svelte-compat covers, and what it does not.

covers
  • svelte/store: writable, readable, derived, readonly, get, with Svelte's lazy start and stop and its equality check.
  • svelte: onMount, onDestroy, beforeUpdate, afterUpdate, tick, setContext, getContext, hasContext, getAllContexts, createEventDispatcher, mount, unmount, flushSync.
  • Control-flow components re-exported for JSX: <For>, <Show>, <Switch>, <Match>, <ErrorBoundary>, <Suspense>.
does not cover
  • The .svelte compiler: single-file components, rune syntax ($state, $derived, $effect), $: statements and $store auto-subscription.
  • <svelte:component> and <svelte:element>.
  • onDestroy (and an onMount cleanup) also fires when a parent re-renders, not only on real unmount.
  • beforeUpdate / afterUpdate run after the first render only, not on every update.
  • getAllContexts() returns an empty Map; createEventDispatcher reaches the direct parent only, with no bubbling.
  • The create-zero scaffold has no Svelte option; set the plugin up by hand.
setup

Install it, point the config at it.

npm install @pyreon/svelte-compat @pyreon/core @pyreon/reactivity @pyreon/runtime-dom npm install -D @pyreon/vite-plugin
vite.config.ts
// vite.config.ts
import { defineConfig } from 'vite'
import pyreon from '@pyreon/vite-plugin'

export default defineConfig({
  plugins: [pyreon({ compat: 'svelte' })],
})

Aliases svelte, svelte/store, svelte/internal and the JSX runtime.

tsconfig.json
// tsconfig.json
{
  "compilerOptions": {
    "jsx": "react-jsx",
    "jsxImportSource": "@pyreon/svelte-compat"
  }
}

Types and the JSX runtime come from the compat package.

port it

What stays: your stores

Svelte store module · stores/cart.ts
// stores/cart.ts: unchanged. `svelte/store` resolves to @pyreon/svelte-compat/store
import { derived, writable } from 'svelte/store'

export const items = writable<string[]>([])
export const count = derived(items, ($items: string[]) => $items.length)
Same file on svelte-compat · stores/cart.ts
// stores/cart.ts: unchanged. `svelte/store` resolves to @pyreon/svelte-compat/store
import { derived, writable } from 'svelte/store'

export const items = writable<string[]>([])
export const count = derived(items, ($items: string[]) => $items.length)

No edits: the alias does the work, and the store contract (subscribe, set, update) behaves like Svelte's.

port it

What moves: components

Svelte 5 · Counter.svelte
<script lang="ts">
  let { step }: { step: number } = $props()
  let count = $state(0)
  const doubled = $derived(count * 2)
</script>

<button class="counter" onclick={() => (count += step)}>{count} / {doubled}</button>
Pyreon · Counter.tsx
import { computed, signal } from '@pyreon/reactivity'

export function Counter(props: { step: number }) {
  const count = signal(0)
  const doubled = computed(() => count() * 2)
  return (
    <button class="counter" onClick={() => count.update((c) => c + props.step)}>
      {count()} / {doubled()}
    </button>
  )
}

Prefer writing count++? Plain Mode ('use plain') keeps that style and compiles it to signals.