Vue2Svelte

raw JSON →
0.0.11 verified Fri May 01 auth: no javascript

A transpiler that converts Vue Single File Components (SFCs) into Svelte components. Current version 0.0.11 is in early development with sporadic releases. Supports simple HTML, props, data, v-if/v-else/v-for directives, and v-bind. Does not yet support methods, computed properties, lifecycle hooks, v-model, or mixins. Differentiates as a direct Vue-to-Svelte migration tool, but maturity is low. TypeScript type definitions are included.

error TypeError: Vue2Svelte is not a constructor
cause Using require() or incorrect import (named instead of default).
fix
Use import Vue2Svelte from 'vue2svelte' (ESM default import).
error Uncaught TypeError: vue2svelte__WEBPACK_IMPORTED_MODULE_0__.default is not a function
cause Attempting to call Vue2Svelte() as a function without `new`.
fix
Use new Vue2Svelte(component) to instantiate.
error Cannot find module 'vue2svelte'
cause Package not installed or module resolution issue.
fix
Run npm install vue2svelte or check your bundler configuration for ES modules.
breaking Many Vue features (methods, computed, lifecycle hooks, v-model, mixins) are not supported. Compilation may produce incomplete or non-functional Svelte code.
fix Only use with simple components that rely solely on template, props, data, and limited directives (v-if, v-for, v-bind).
gotcha Default import is a class; must be instantiated with `new Vue2Svelte(...)`. Do not attempt to call it as a function.
fix Correct usage: `const compiler = new Vue2Svelte(options); compiler.compile();`
gotcha The output is a raw string, not a Svelte component instance. You must write it to a .svelte file or use Svelte's runtime to compile it further.
fix Save the string as a .svelte file and import it with Svelte's bundler plugin.
npm install vue2svelte
yarn add vue2svelte
pnpm add vue2svelte

Shows basic usage: instantiate Vue2Svelte with a Vue options object, then call compile() to get a Svelte string.

import Vue2Svelte from 'vue2svelte';

const vueComponent = {
  template: `<div><span v-for="item in list">{{ item }}</span></div>`,
  props: {
    list: {
      default: ['item 1', 'item 2']
    }
  },
  data () {
    return { hello: 'world' }
  }
};

const svelteComponent = new Vue2Svelte(vueComponent);
console.log(svelteComponent.compile());
// Output: <script>export let list=["item 1","item 2"];let hello="world";</script><div>{#each list as item}<span>{item}</span>{/each}</div>