Registry / web-framework / vue-compiler

vue-compiler

JSON →
library4.2.1jsnpmunverified

A standalone Vue single-file component (SFC) compiler for projects that cannot use webpack. Current stable version is 4.2.1, released on an irregular cadence by a community maintainer. Unlike official vue-loader, this package compiles .vue files directly to CommonJS modules without requiring webpack, supporting both async (compile) and sync (compileSync) APIs. It includes template compilation (via vue-template-compiler), style processing, and custom compiler hooks. However, the package is not actively maintained by the Vue core team and relies on an outdated peer dependency of vue-template-compiler ^2.6.10, meaning it only supports Vue 2.x. For Vue 3, use @vue/compiler-sfc instead.

npm install vue-compiler
INSTALL
IMPORT
SIG · VUE-COMPILER
V
vue-compiler
web-frameworkjavascriptv4.2.1
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.

compile (default)
import compile from 'vue-compiler'
const compile = require('vue-compiler').compile
The default export is the async compile function. Named exports are also available.
compileSync
import { compileSync } from 'vue-compiler'
const compileSync = require('vue-compiler').compileSync
Only available as named export, not as a default property.
parse
import { parse } from 'vue-compiler'
Exported as a named function for parsing SFC descriptors.
assemble
import { assemble } from 'vue-compiler'
Used to combine compiled parts into a final module.

Demonstrates async compilation of a Vue single-file component string to a CommonJS module.

import compile from 'vue-compiler'; const source = `<template><div>{{ msg }}</div></template><script>export default { data() { return { msg: 'Hello' } } }</script><style scoped>div { color: red }</style>`; const result = await compile(source, { filename: 'App.vue' }); console.log(result.code);
Debug
Known issues
breakingVue 2 only; does not support Vue 3 SFC syntax.
fix
Use @vue/compiler-sfc for Vue 3 projects.
affects: >=4.0.0
deprecatedThe peer dependency vue-template-compiler ^2.6.10 is outdated and may have security vulnerabilities.
fix
Update your project's vue-template-compiler to a newer patch within 2.6.x, or migrate to Vue 3.
affects: >=4.0.0
gotchaThe default export is the async compile function. Importing as `import { compile }` will not work.
fix
Use `import compile from 'vue-compiler'` for the async function.
affects: >=4.0.0
gotchaWhen using TypeScript, the package does not ship its own type definitions. You may need to create a declaration file.
fix
Add a .d.ts file: `declare module 'vue-compiler'` or use @types/vue-compiler if available.
affects: >=4.0.0
Errors
Common errors & fixes
Cannot find module 'vue-template-compiler'
Missing peer dependency.
fix
Run `npm install vue-template-compiler@^2.6.10` in your project.
TypeError: (0 , _vueCompiler.default) is not a function
Improper import: using named import for default export.
fix
Use `import compile from 'vue-compiler'` instead of `import { compile } from 'vue-compiler'`.
Expected vue-template-compiler to be a function, got object
Incompatible version of vue-template-compiler (e.g., Vue 3 version installed).
fix
Ensure you have vue-template-compiler@^2.6.10 installed, not @vue/compiler-sfc.
Upgrade
Version history
4.2.1latest on npm
Audit
Dependencies
vue-template-compilerrequiredpeer dependency for compiling Vue 2 templates
Agent activity
7 hits · last 30 days
node
6
OpenAI (training)
1
Resources
vue-compiler — npm install vue-compiler · libregistry