npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

vue-compiler-sfc-plugin

v3.5.26

Published

Vue 3 compiler-sfc helper package

Readme

vue-compiler-sfc-plugin

This package is a Vue 3 compatible helper that wraps @vue/compiler-sfc and provides build-time integration hooks. For pull requests please see the Vue 3 core repository.

This package can be used to integrate Vue 3 SFC (Single File Component) compilation into custom build pipelines. In most cases you should be using it with @vitejs/plugin-vue or vue-loader, you will only need it separately if you are writing build tools with very specific needs.

Installation

npm install vue-compiler-sfc-plugin
const { parse, compileTemplate, compileScript, compileStyleAsync } = require('@vue/compiler-sfc')

Version Compatibility

This package requires Vue >=3.0.0. The version of this package follows Vue 3's minor releases to indicate compatibility.

| vue-compiler-sfc-plugin | Vue 3 | |------------------------|-------| | 3.5.x | ^3.5.0 | | 3.4.x | ^3.4.0 |

API

This package re-exports and extends @vue/compiler-sfc. For the full API reference, see the @vue/compiler-sfc documentation.

parse(source, options)

Parse a Vue SFC source string into a descriptor object:

const { parse } = require('@vue/compiler-sfc')

const { descriptor, errors } = parse(`
  <template>
    <div>Hello</div>
  </template>

  <script>
  export default {}
  </script>
`)

The returned descriptor is an SFCDescriptor object with the following structure:

{
  filename: string,
  source: string,
  template: SFCTemplateBlock | null,
  script: SFCScriptBlock | null,
  scriptSetup: SFCScriptBlock | null,
  styles: SFCStyleBlock[],
  customBlocks: SFCBlock[],
  cssVars: string[],
  slotted: boolean,
  shouldForceReload: (prevImports: Record<string, ImportBinding>) => boolean
}

compileTemplate(options)

Compile the <template> block of an SFC into a render function:

const { compileTemplate } = require('@vue/compiler-sfc')

const { code, errors } = compileTemplate({
  source: `<div>Hello</div>`,
  filename: 'example.vue',
  id: 'data-v-xxxxxx'
})

Options

  • source — Template source string (required)
  • filename — Used for error messages (required)
  • id — Scope ID for CSS scoping (required)
  • scoped — Whether to generate scoped CSS attribute (boolean, default false)
  • isProd — Optimize output for production (boolean, default false)
  • ssr — Compile to SSR render function (boolean, default false)
  • ssrCssVars — CSS variable bindings for SSR (string[])
  • compilerOptions — Options passed to the underlying @vue/compiler-dom

compileScript(descriptor, options)

Compile the <script> or <script setup> block of an SFC:

const { compileScript } = require('@vue/compiler-sfc')

const scriptBlock = compileScript(descriptor, {
  id: 'data-v-xxxxxx'
})

Returns an SFCScriptBlock with the compiled content and inferred bindings.


compileStyleAsync(options)

Compile a <style> block asynchronously, with support for CSS Modules and scoped styles:

const { compileStyleAsync } = require('@vue/compiler-sfc')

const result = await compileStyleAsync({
  source: `.foo { color: red; }`,
  filename: 'example.vue',
  id: 'data-v-xxxxxx',
  scoped: true,
  modules: false
})

generateCodeFrame(source, start, end)

Generate a code frame highlighting a range in the source string. Useful for error reporting in higher-level tooling:

const { generateCodeFrame } = require('@vue/compiler-sfc')

const frame = generateCodeFrame(source, start, end)
// Returns a string with the highlighted code range

Usage with Vite

When using Vite, @vitejs/plugin-vue handles SFC compilation automatically. This package is only needed if you are building custom Vite plugins or tooling that processes .vue files directly.

// vite.config.js
import vue from '@vitejs/plugin-vue'

export default {
  plugins: [vue()]
}

Usage with webpack

When using webpack with Vue 3, use vue-loader@17+:

// webpack.config.js
const { VueLoaderPlugin } = require('vue-loader')

module.exports = {
  plugins: [new VueLoaderPlugin()],
  module: {
    rules: [
      { test: /\.vue$/, loader: 'vue-loader' }
    ]
  }
}

License

MIT