Vue Template ES2015 Compiler
This package is an internal build-time utility primarily used by `vue-loader` and `vueify` in Vue 2 projects. Its main function is to post-process raw render functions generated by `vue-template-compiler` to introduce support for ES2015+ features within template expressions, leveraging a custom fork of Buble. Additionally, it removes the `with` block from render functions to ensure strict-mode compliance. The current stable version is 1.9.1, but the package has not seen updates since February 2019, indicating it is no longer actively maintained for modern Vue development. It is a critical component for enabling advanced JavaScript syntax in Vue 2 templates during the build process, distinguishing itself by its specific focus on ES2015+ transpilation and strict-mode compatibility for Vue 2's compilation output.
Common errors
-
Object.assign is not a function
cause Attempting to use object rest/spread syntax in Vue 2 templates (transpiled by this compiler) in an environment (e.g., IE) that lacks native `Object.assign` support without a polyfill.fixInclude a polyfill for `Object.assign` in your project's build process or runtime environment to support older browsers. Modern build setups often include `core-js` for this. -
Unknown custom element: <YourComponent> - did you register the component correctly?
cause Using `vue-template-es2015-compiler` in a Vue 3 project, or misconfiguring Vue 2 components when relying on an outdated build chain. This compiler is Vue 2 specific.fixEnsure you are using the correct compiler for your Vue version. For Vue 3, this compiler is not used; `@vue/compiler-sfc` and `@vue/compiler-dom` are the standard. If in Vue 2, verify `vue-loader` and `vue-template-compiler` versions are compatible.
Warnings
- deprecated This package is exclusively for Vue 2 projects. It is superseded by `@vue/compiler-sfc` and `@vue/compiler-dom` in Vue 3 and should not be used in Vue 3 applications.
- breaking Since version 1.8.0, object rest spread usage within templates is transpiled to `Object.assign` calls. This requires a polyfill for `Object.assign` in older browsers, such as Internet Explorer, to prevent runtime errors.
- gotcha This is an internal package primarily used by build tools like `vue-loader` and `vueify`. Direct programmatic usage by end-user applications is rare and generally not recommended, as its API is subject to change without public deprecation cycles.
- gotcha The package has not been updated since February 2019 (version 1.9.1). This indicates a lack of ongoing maintenance, which may lead to compatibility issues with newer JavaScript features, tooling, or environments not present at the time of its last release.
Install
-
npm install vue-template-es2015-compiler -
yarn add vue-template-es2015-compiler -
pnpm add vue-template-es2015-compiler
Imports
- compile
const { compile } = require('vue-template-es2015-compiler')import compile from 'vue-template-es2015-compiler'
- processRenderFunction
const processRenderFunction = require('vue-template-es2015-compiler');
Quickstart
const compile = require('vue-template-es2015-compiler');
// Simulate a render function string from vue-template-compiler output
const rawRenderFn = `
with(this){
return _c('div', [
_v('Hello ' + (name)),
_c('button', { on: { click: () => ({ ...user, active: true }) } }, ['Click'])
])
}
`;
// Options can be passed, though typically defaults are used by vue-loader
const options = {};
try {
const compiledResult = compile(rawRenderFn, options);
console.log('Processed Render Function:\n', compiledResult);
// Expected output will have 'with' removed and ES2015+ features transpiled
// e.g., fat arrow functions, object spread to Object.assign
} catch (error) {
console.error('Compilation Error:', error);
}