vue-template-compiler

Precompiles Vue 2 templates into render functions ahead of time, avoiding runtime compilation overhead and CSP restrictions in build tooling.

Tool
npm
v2.7.16
211,646stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
59/100Fair
Development Activity0
Maintenance44
Community92
Maturity60
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
73/100Good
Architecture82
Code Quality78
Innovation62
Learning Curve70

vue-template-compiler is the standalone build-time compiler auto-generated from Vue 2’s internal src/platforms/web/entry-compiler.ts entry point. It exposes compile/compileToFunctions to turn Vue 2 single-file-component templates into JavaScript render functions before the app ships, so browsers never have to run the compiler themselves. This matters for two reasons: it removes the runtime cost of parsing templates on every page load, and it lets apps ship without eval/new Function-based compilation, which is blocked under strict Content-Security-Policy rules.

In practice almost nobody calls this package directly. It is the compiler dependency that vue-loader (webpack) and vueify (Browserify) pull in behind the scenes to precompile .vue files during a build step, and it also ships parseComponent for splitting a .vue file into its template/script/style blocks, plus SSR-specific compile variants (ssrCompile, ssrCompileToFunctions) used by vue-server-renderer. Because Vue 2 reached end-of-life on December 31, 2023, this package is functionally frozen at its final release; it remains widely installed only because it is a required peer/transitive dependency of every still-running Vue 2 build pipeline.

What You Get

  • compile() - turns a template string into { ast, render, staticRenderFns, errors } for build-time precompilation.
  • compileToFunctions() - same pipeline but returns instantiated JS functions directly, for environments without CSP restrictions.
  • ssrCompile() / ssrCompileToFunctions() - server-rendering-optimized variants that convert parts of the template into string concatenation for faster SSR output.
  • parseComponent() - splits a raw .vue Single-File Component into its template/script/style block descriptor, the primitive vue-loader builds on.
  • generateCodeFrame() - renders a source-mapped code frame around a template parse error for readable build-time diagnostics.
  • Pluggable compiler modules and directives options so custom template features (e.g. custom v-* directives) can hook into parsing and codegen.

Common Use Cases

  • Webpack builds via vue-loader - vue-loader calls into vue-template-compiler under the hood to precompile each .vue file’s <template> block during bundling.
  • Browserify builds via vueify - the Browserify equivalent of vue-loader uses the same compiler package for build-time transformation.
  • Strict-CSP applications - apps that disallow unsafe-eval must precompile templates ahead of time instead of compiling them in the browser at runtime.
  • Custom Vue 2 build tooling - authors writing bespoke bundler plugins or SFC tooling for legacy Vue 2 codebases call parseComponent/compile directly.
  • Server-side rendering pipelines - vue-server-renderer uses the SSR-optimized compile variants to generate faster string-concatenation render output.

Under The Hood

Architecture The package is a thin, auto-generated wrapper (src/platforms/web/entry-compiler.ts) around Vue 2’s core compiler pipeline in src/compiler/: parser/index.ts turns a template string into an AST via a streaming HTML tokenizer (html-parser.ts), optimizer.ts walks the AST marking static subtrees so codegen can skip re-rendering them, and codegen/index.ts emits render-function source strings from the optimized AST. create-compiler.ts wraps this base pipeline in a createCompilerCreator factory so the same parser/optimizer/codegen stages can be reused to build both the standard browser compiler and the SSR-optimized variant exported by server/compiler; error-detector.ts runs a separate pass over the AST to flag disallowed JS keywords or unary operators inside template expressions before codegen. The published npm package itself is not source-built from this repo directly — it is generated by scripts/build.js/scripts/config.js, which bundle the compiler entry point into packages/template-compiler/build.js and browser.js as part of Vue 2’s monorepo release process.

Tech Stack Written in TypeScript against Vue 2’s internal types/compiler declarations, built with a custom Rollup-based script (scripts/build.js) rather than a standard bundler config, and typed via hand-maintained .d.ts files rather than auto-generated ones. Runtime dependencies are minimal and intentionally low-level: de-indent for cleaning up indentation in extracted <script>/<style> blocks, and he for HTML entity encoding/decoding during parsing — reflecting that this package must run in both Node build tooling and legacy browser targets with no heavier dependencies.

Code Quality The compiler core has dedicated unit tests under test/unit/modules/compiler/ and test/unit/modules/server-compiler/ covering the parser, codegen, optimizer, error-detector code frames, and compiler options, run via Vitest as part of Vue 2’s broader npm test pipeline (ts-check, test:unit, test:ssr, test:e2e, test:sfc). Error handling favors explicit warning/error accumulation (a warn callback pushed into errors/tips arrays with optional source-range metadata) over throwing, so template mistakes surface as structured diagnostics rather than crashes. Since Vue 2 reached end-of-life in December 2023, the compiler is now feature-frozen — CI configuration and lint-staged hooks remain in place, but no new commits land against this code.

What Makes It Unique Unlike most template compilers that only target one output mode, this codebase’s createCompilerCreator abstraction lets the identical parser/optimizer/AST pipeline be reused to emit either standard render functions or SSR-optimized string-concatenation output from server/compiler, avoiding a second parallel implementation for server rendering. Its parseComponent SFC-splitting primitive is also the actual building block that downstream tools like vue-loader and vueify depend on for .vue file support, rather than each tool reimplementing SFC parsing independently.

Used by 11 apps in this directory

PHP
82%
Other

Akaunting

Invoicing Finance

10,111

Open-source online accounting for small businesses and freelancers — invoices, expenses, and reporting without monthly fees or vendor lock-in.

View details
98
Repo Health
73
Technical
63
Dependency
Built with
PHP82%
Blade13%
Updated yesterday
JavaScript
94%
MIT

Another Redis Desktop Manager

Developer Tools · Databases

34,729

Fast, stable Redis GUI with cluster, SSH, and massive key support

View details
83
Repo Health
56
Technical
67
Dependency
Built with
JavaScript94%
Updated 2 weeks ago
Python
59%
Apache 2.0

argilla

AI Development · Data Engineering

5,098

Collaborate on high-quality AI training data with a self-hosted annotation platform built for LLMs, NLP, and multimodal models.

View details
65
Repo Health
81
Technical
61
Dependency
Built with
Python59%
Jupyter Notebook21%
Updated 1 weeks ago
JavaScript
90%
Other

CodeSandbox

Code Editors · Developer Tools

13,640

Instantly ready browser-based IDE that runs full npm dependency resolution and transpilation entirely client-side, with no server needed.

View details
69
Repo Health
76
Technical
62
Dependency
Built with
JavaScript90%
Updated 1 weeks ago
Go
63%
Apache 2.0

Coroot

Analytics · Monitoring

7,907

eBPF-powered observability with AI root cause analysis — zero code changes required, full-stack visibility out of the box.

View details
88
Repo Health
80
Technical
65
Dependency
Built with
Go63%
Vue35%
Updated 3 days ago
Ruby
67%
Other

GitLab

Devops · Developer Tools

24,552

The complete DevOps platform that unifies Git hosting, CI/CD, issue tracking, and security scanning into a single self-hostable application.

View details
87
Repo Health
86
Technical
68
Dependency
Built with
Ruby67%
JavaScript20%
Updated today
PHP
85%
Other

Invoice Ninja

Invoicing Finance · Project Management

10,060

Self-hostable invoicing, time-tracking, and multi-gateway payment platform for freelancers and small businesses, with built-in e-invoicing compliance for EU and global standards.

View details
97
Repo Health
83
Technical
62
Dependency
Built with
PHP85%
XSLT10%
Updated 2 days ago
Go
42%
AGPL 3.0

listmonk

Marketing · Blogging

23,291

High-performance, self-hosted newsletter and mailing list manager packaged as a single binary with built-in analytics, transactional messaging, and multi-channel delivery.

View details
88
Repo Health
74
Technical
67
Dependency
Built with
Go42%
Vue24%
JavaScript19%
Updated yesterday
PHP
58%
AGPL 3.0

Pixelfed

Social Media

7,095

A decentralized, self-hosted photo sharing platform built on ActivityPub for the open Fediverse.

View details
90
Repo Health
68
Technical
68
Dependency
Built with
PHP58%
Vue30%
Blade12%
Updated 2 days ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search