The `vue-template-compiler` package is an internal component of the Vue 2 ecosystem, designed to pre-compile Vue 2.x template strings into JavaScript render functions. This process reduces runtime overhead, improves performance, and allows Vue applications to operate in environments with Content Security Policy (CSP) restrictions by avoiding `eval` usage. The current and final stable version is `2.7.16` ("Swan Song"), released as part of Vue 2.7, which aimed to backport some Vue 3 Composition API features to Vue 2. This package, like Vue 2 itself, reached its official End of Life (EOL) on December 31st, 2023, meaning it will no longer receive updates, bug fixes, or security patches. While direct usage is possible for custom build tools, it was primarily designed to be consumed by build integrations like `vue-loader` for Webpack or similar tools, providing the core compilation logic for `.vue` single file components.
npm install vue-template-compilerVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates compiling a simple Vue 2 template into render functions using `vue-template-compiler`. It outputs the main render function and any static render functions, illustrating the core functionality of the package. It also shows an example of using the `whitespace` option.
Plan a migration path to Vue 3. For continued support on Vue 2 beyond EOL, consider third-party extended support options or use Vue 2.7 as the final version for maintenance-only projects.
Ensure the environment where the generated render functions are executed is not in strict mode, or rely on `vue-loader` and Vue's internal runtime which correctly handles this. Direct execution of generated render functions outside of the Vue runtime is generally discouraged for this reason.
Only use custom compiler modules and directives if you are building highly specialized tooling and are aware of the implications regarding ecosystem compatibility. Prefer runtime directives/components when possible.
For new projects, use Vue 3 and its associated compilation tools (`@vue/compiler-sfc`, `@vue/compiler-dom`). For existing Vue 2 projects, continue using v2.7.16 but understand that it is no longer actively maintained.
Run `npm install vue-template-compiler` or `yarn add vue-template-compiler` in your project directory.
Avoid running generated render functions directly in strict mode contexts. This package is intended to be used by build tools and the Vue runtime, which manage the execution context correctly. If you're manually executing, ensure the function context is non-strict.
Verify that `vue-template-compiler` is correctly installed and imported. Ensure that `const compiler = require('vue-template-compiler')` or `import * as compiler from 'vue-template-compiler'` correctly assigns the module exports to the `compiler` variable.No dependency data recorded yet.