@velin-dev/source-vue

Vue source tooling for Velin.
721 78
Install
npm install @velin-dev/source-vue
Latest Version:1.0.0-beta.8
Vue:3
License:MIT
Last Updated:Oct 23, 2026
Links: GitHub  ·  npm
Maintainer: nekomeowww

@velin-dev/source-vue

Vue source tooling for Velin.

Usage

import { componentFromSource, createSFC } from '@velin-dev/source-vue'

const source = createSFC('<p>Hello</p>', '', 'ts')

const Prompt = await componentFromSource<{ name: string }>(
  `
    <template>
      <p>{{ greeting }}</p>
    </template>

    <script setup lang="ts">
    import { useGreeting } from './composables/useGreeting'
    import type { PromptProps } from './types'

    const props = defineProps<PromptProps>()
    const greeting = useGreeting(props.name)
    </script>
  `,
  {
    filename: 'src/Prompt.vue',
    vfs: {
      'src/composables/useGreeting.ts': `
        export function useGreeting(name: string) {
          return \`Hello \${name}\`
        }
      `,
      'src/types.ts': `
        export interface PromptProps {
          name: string
        }
      `,
    },
  },
)

API

function createSFC(html: string, scriptContent: string, lang: string): string

interface VueComponentFromSourceOptions {
  filename?: string
  vfs?: Record<string, string> | Map<string, string>
}

function componentFromSource<Props = Record<string, unknown>>(
  source: string,
  options?: VueComponentFromSourceOptions,
): Promise<DefineComponent<Props>>

class File {
  constructor(filename: string, code?: string, hidden?: boolean)
  filename: string
  code: string
  hidden: boolean
  compiled: {
    js: string
    css: string
    ssr: string
    clientMap: string
    ssrMap: string
  }
  readonly language: 'vue' | 'html' | 'css' | 'typescript' | 'javascript'
}

function compileModulesForPreview(
  options: {
    files: Record<string, File>
    mainFile: string
  },
  isSSR?: boolean,
): string[]

componentFromSource compiles Vue SFC source with @vue/compiler-sfc, strips TypeScript with sucrase through @velin-dev/utils, resolves relative imports from the optional virtual file map, and evaluates the linked ESM with @unrteljs/eval. It is not a sandbox or security boundary and must only be used with trusted source.

Related Packages

@velin-dev/vue

Develop prompts with Vue SFC or Markdown like pro.

7,871 78
@velin-dev/utils

Develop prompts with Vue SFC or Markdown like pro.

200,743 78

Version History

Pre-releases (3)
Version Released Vue License
1.0.0-beta.8 >= 3 MIT
1.0.0-beta.6 >= 3 MIT
1.0.0-beta.3 >= 3 MIT