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.
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) andwatchEffect.- 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
.vuesingle-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, acomputedblock,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.
read more