Registry / devops / vue-compiler-sfc-plugin

vue-compiler-sfc-plugin

JSON →
library3.5.26jsnpmunverified

A Vue 3 SFC compilation helper that wraps @vue/compiler-sfc, providing build-time integration hooks for custom pipelines. Current stable version is 3.5.26, following Vue 3 minor releases for compatibility (e.g., 3.5.x supports Vue ^3.5.0). It re-exports key functions (parse, compileTemplate, compileScript, compileStyleAsync) from @vue/compiler-sfc. Differentiators: explicitly designed for tool authors needing separate SFC compilation outside of Vite or vue-loader; it extends the core compiler-sfc with plugin-friendly hooks.

npm install vue-compiler-sfc-plugin
INSTALL
IMPORT
SIG · VUE-COMPILER-SFC-P
V
vue-compiler-sfc-plugin
devopsjavascriptv3.5.26
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

parse
import { parse } from '@vue/compiler-sfc'
const parse = require('vue-compiler-sfc-plugin').parse
This package re-exports from @vue/compiler-sfc; import directly from '@vue/compiler-sfc' for library code.
compileScript
import { compileScript } from '@vue/compiler-sfc'
import { compileScript } from 'vue-compiler-sfc-plugin'
Functions are re-exported, but direct import from @vue/compiler-sfc avoids potential wrapper issues.
SFCDescriptor
import type { SFCDescriptor } from '@vue/compiler-sfc'
import { SFCDescriptor } from 'vue-compiler-sfc-plugin'
Type-only import; use the core package for type definitions.

Demonstrates parsing an SFC string and compiling template, script, and style blocks.

import { parse, compileTemplate, compileScript, compileStyleAsync } from '@vue/compiler-sfc'; const source = ` <template> <div>Hello</div> </template> <script setup> const msg = 'World' </script> <style scoped> .foo { color: red; } </style> `; const { descriptor } = parse(source); if (descriptor.template) { const { code } = compileTemplate({ source: descriptor.template.content, filename: 'Example.vue', id: 'data-v-xxxxxx' }); console.log('Template code:', code); } if (descriptor.scriptSetup) { const scriptBlock = compileScript(descriptor, { id: 'data-v-xxxxxx' }); console.log('Script content:', scriptBlock.content); } if (descriptor.styles.length) { const result = await compileStyleAsync({ source: descriptor.styles[0].content, filename: 'Example.vue', id: 'data-v-xxxxxx', scoped: descriptor.styles[0].scoped }); console.log('Style code:', result.code); }
Debug
Known issues
gotchaImport functions from '@vue/compiler-sfc', not from 'vue-compiler-sfc-plugin'. The plugin package is a thin wrapper that may not export all members.
fix
Use direct imports from '@vue/compiler-sfc' for all compiler functions.
affects: >=3.0.0
breakingVue 3 removed the deprecated 'compileStyle' synchronous function; use 'compileStyleAsync' instead.
fix
Replace compileStyle calls with await compileStyleAsync({...}).
affects: >=3.4.0
deprecatedSFC parsing options like 'pad' are deprecated and will be removed in Vue 3.6.
fix
Avoid using 'pad' in parse options.
affects: >=3.5.0
Errors
Common errors & fixes
Cannot find module '@vue/compiler-sfc' or its corresponding type declarations.
@vue/compiler-sfc is a peer dependency and not installed automatically.
fix
Run: npm install @vue/compiler-sfc --save-dev
TypeError: compileStyle is not a function
compileStyle was removed in Vue 3.4+ in favor of compileStyleAsync.
fix
Use compileStyleAsync with await instead.
The requested module 'vue-compiler-sfc-plugin' does not provide an export named 'parse'
The package re-exports from @vue/compiler-sfc but may have changed export patterns.
fix
Import directly from '@vue/compiler-sfc'.
Upgrade
Version history
3.5.26latest on npm
Audit
Dependencies
@vue/compiler-sfcrequiredCore dependency for parsing and compiling Vue SFCs.
Agent activity
4 hits · last 30 days
node
4
Resources
vue-compiler-sfc-plugin — npm install vue-compiler-sfc-plugin · libregistry