Skip to content
Migrate from Vue · @pyreon/vue-compat

Keep your composables. Port templates when you're ready.

@pyreon/vue-compat runs the Composition API on Pyreon's engine: ref, reactive, computed, watch, the lifecycle hooks, provide/inject, createApp. It is a runtime layer, so components are TSX functions: .vue files are ported to TSX, and the composables they import keep running unchanged.

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

The same Vue code, on Pyreon.

Migrating from Vue: before and after Vue to Pyreon, before and after: the same Vue single-file component component (11 lines) and its TSX on @pyreon/vue-compat version (11 lines). 10 lines change; the changed lines are marked with a minus rail in the before code and a plus rail in the after code. Code before: <script setup lang="ts"> import { computed, ref } from 'vue' const props = defineProps<{ step: number }>() const count = ref(0) const doubled = computed(() => count.value * 2) </script> <template> <button class="counter" @click="count += props.step">{{ count }} / {{ doubled }}</button> </template> Code after: import { computed, ref } from 'vue' // resolves to @pyreon/vue-compat export function Counter(props: { step: number }) { const count = ref(0) const doubled = computed(() => count.value * 2) return ( <button class="counter" onClick={() => (count.value += props.step)}> {count.value} / {doubled.value} </button> ) } MIGRATE FROM VUE · STEP 1: THE TEMPLATE BECOMES TSX, THE LOGIC STAYSBEFORE · VUE SINGLE-FILE COMPONENT−<script setup lang="ts">−import { computed, ref } from 'vue'−−const props = defineProps<{ step: number }>()−const count = ref(0)−const doubled = computed(() => count.value * 2)−</script>−<template>− <button class="counter" @click="count += props.step">{{ count }} / {{ doubled }}</button>−</template>AFTER · TSX ON @PYREON/VUE-COMPAT+import { computed, ref } from 'vue' // resolves to @pyreon/vue-compat+export function Counter(props: { step: number }) {+ const count = ref(0)+ const doubled = computed(() => count.value * 2)+ return (+ <button class="counter" onClick={() => (count.value += props.step)}>+ {count.value} / {doubled.value}+ </button>+ )+}
An illustration of the code on each side, not a recording.
coverage

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

covers
  • Refs: ref, shallowRef, triggerRef, isRef, unref, toValue, toRef, toRefs.
  • computed (getter and writable { get, set } forms); reactive, shallowReactive, readonly, shallowReadonly, toRaw, markRaw, isReactive, isReadonly, isProxy.
  • watch (single source, getter or array) and watchEffect.
  • Lifecycle: onMounted, onUnmounted, onUpdated, onBeforeMount, onBeforeUnmount, onErrorCaptured, onRenderTracked, onRenderTriggered; nextTick.
  • provide / inject, effectScope, getCurrentScope, onScopeDispose.
  • defineComponent, defineAsyncComponent (loading and error components, delay, timeout), createApp(component, props).
  • Built-ins: Teleport, KeepAlive, Transition.
does not cover
  • The .vue single-file component compiler, and with it <script setup>.
  • Template directives (v-if, v-for, v-model): use the JSX equivalents.
  • The Options API (data, methods, a computed block, created, beforeDestroy…).
  • Lifecycle hooks fire once per instance; onUpdated's render-driven re-fires become per-subscription effects.
setup

Install it, point the config at it.

npm install @pyreon/vue-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: 'vue' })],
})

Aliases vue and its JSX runtime to the compat package.

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

Types and the JSX runtime come from the compat package.

or start from a scaffold
npm create @pyreon/zero@latest my-app -- --compat vue
port it

Step 1: the template becomes TSX, the logic stays

Vue single-file component · Counter.vue
<script setup lang="ts">
import { computed, ref } from 'vue'

const props = defineProps<{ step: number }>()
const count = ref(0)
const doubled = computed(() => count.value * 2)
</script>

<template>
  <button class="counter" @click="count += props.step">{{ count }} / {{ doubled }}</button>
</template>
TSX on @pyreon/vue-compat · Counter.tsx
import { computed, ref } from 'vue' // resolves to @pyreon/vue-compat

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

ref, computed and .value are untouched; only the markup moved. Render it from a parent's JSX (<Counter step={2} />) so the compat runtime re-renders it.

port it

Step 2: refs become signals

TSX on @pyreon/vue-compat · Counter.tsx
import { computed, ref } from 'vue' // resolves to @pyreon/vue-compat

export function Counter(props: { step: number }) {
  const count = ref(0)
  const doubled = computed(() => count.value * 2)
  return (
    <button class="counter" onClick={() => (count.value += props.step)}>
      {count.value} / {doubled.value}
    </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>
  )
}

The Pyreon side is the final form, after compat is switched off.