Babel Plugin Transform Vue Template banner
egoist egoist

Babel Plugin Transform Vue Template

Productivity community

Description

Babel plugin to compile Vue template at build time.

Installation

This entry records only its repository, not the path inside it, so there is no exact command to give. Open the source below and copy the folder into ~/.claude/skills/, or the file into ~/.claude/agents/.

README

babel-plugin-transform-vue-template

[![NPM version](https://img.shields.io/npm/v/babel-plugin-transform-vue-template.svg?style=flat)](https://npmjs.com/package/babel-plugin-transform-vue-template) [![NPM downloads](https://img.shields.io/npm/dm/babel-plugin-transform-vue-template.svg?style=flat)](https://npmjs.com/package/babel-plugin-transform-vue-template) [![CircleCI](https://circleci.com/gh/egoist/babel-plugin-transform-vue-template/tree/master.svg?style=shield)](https://circleci.com/gh/egoist/babel-plugin-transform-vue-template/tree/master) [![donate](https://img.shields.io/badge/$-donate-ff69b4.svg?maxAge=2592000&style=flat)](https://github.com/egoist/donate)

Compile Vue template at build time via babel plugin.

Install

yarn add babel-plugin-transform-vue-template --dev

yarn add vue-template-compiler --dev
# vue-template-compiler is required as peer dependency

Usage

With `.babelrc`:

{
  "plugins": ["transform-vue-template"]
}

Then every object property `template` whose value is a template string literal will be compiled to `render` function at build time:

export default {
  template: `
Click me!
`, methods: { whatever() { // do whatever } } }

Compiled code:

export default {
  render: function render() {
    var _vm = this;

    var _h = _vm.$createElement;

    var _c = _vm._self._c || _h;

    return _c('div', [_c('button', {
      on: {
        "click": _vm.whatever
      }
    }, [_vm._v("Click me!")])]);
  },
  staticRenderFns: [],
  methods: {
    whatever() {// do whatever
    }

  }
};

Tagged template expression

This plugin also handles tagged template expression, it simply ignores the tag:

export default {
  template: html`
{{ message }}
` }

Note that the tag name can only be `html`.

Disable transforming for specific code

Add a comment block with `@transform-disable` to the previous line: