# babel-plugin-transform-vue-inline-template-next

> transform vue inline template to render function Babel plugin

Latest version **1.0.5** (published 2023-01-17) · MIT license · 0 weekly downloads

## Install

```sh
npm install babel-plugin-transform-vue-inline-template-next
pnpm add babel-plugin-transform-vue-inline-template-next
yarn add babel-plugin-transform-vue-inline-template-next
bun add babel-plugin-transform-vue-inline-template-next
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.5 |
| Published | 2023-01-17 |
| First published | 2022-04-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 2 |
| Unpacked size | 8.9 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Di Yuan Liang |
| Maintainers | liangdiyuan |
| Keywords | vue, inline, template, render, Babel, plugin, babel-plugin |

## Links

- npm: https://www.npmjs.com/package/babel-plugin-transform-vue-inline-template-next
- Repository: https://github.com/liangdiyuan/babel-plugin-transform-vue-template
- Homepage: https://github.com/liangdiyuan/babel-plugin-transform-vue-template/
- Issues: https://github.com/liangdiyuan/babel-plugin-transform-vue-template/issues
- npm.io page: https://npm.io/package/babel-plugin-transform-vue-inline-template-next

## Dependencies (2)

- [vue-template-compiler](https://npm.io/package/vue-template-compiler.md) ^2.0.0
- [vue-template-es2015-compiler](https://npm.io/package/vue-template-es2015-compiler.md) ^1.9.0

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 1.0.5 (latest) — 2023-01-17
- 1.0.4 — 2022-09-11
- 1.0.3 — 2022-04-11
- 1.0.2 — 2022-04-10
- 1.0.1 — 2022-04-10
- 1.0.0 — 2022-04-10

## README

# babel-plugin-transform-vue-inline-template-next

#### 介绍

转换内联 vue template 模板 Babel 插件，外部依赖 vue-template-compiler、vue-template-es2015-compiler，使用时必须根据不同的 vue 版本安装对应的 vue-template-compiler、vue-template-es2015-compiler。

#### 安装教程

```bash
1.  npm install -D babel-plugin-transform-vue-inline-template-next
```

#### 1.4 版本更新，添加自定义 vue-template-compile、vue-template-es2015-compiler 配置项

vueTemplateCompilerOpts、 vueTemplateEs2015CompilerOpts，与 vue-template-compile、vue-template-es2015-compiler 配置一样，默认配置也一样。

#### 使用说明

babel 配置

```js
{
     plugins: [
      ['babel-plugin-transform-vue-inline-template-next', {
          flagStr: "h", // 标记编译魔法注释，全量编译不开启时，在代码中添加该魔法注释，将编译代码
          compileAll: false, // 是否开启全量编译
          ignoreFlagStr: "ignore", // 忽略编译魔法注释，全量编译开启时，在代码中添加该魔法注释，将忽略编译代码
          vueTemplateCompilerOpts: {  // vue-template-compile 配置
            whitespace: "condense",
            pad: "line",
          },
          vueTemplateEs2015CompilerOpts: { // vue-template-es2015-compiler 配置
            modules: false,
            stripWith: true,
            stripWithFunctional: false,
          },
        }
      ]
    ],
}
```

在 vue 的内联模板 template 上方加上魔法注释 /* h */，打包时便会识别到编译成 render 函数。

代码示例

```js
new Vue({
  el: "#app",
  data: function () {
    return {
      test2: 18,
      test: "test",
    };
  },
  /* h */
  template: `
    <div v-show="test2 > 1" @click="testFn" :test="test2">{{test}}</div>
  `,
  methods: {
    testFn() {
      console.log(this.test2);
      this.test2--;
    },
  },
});

// or

var test = {
  el: "#app",
  data: function () {
    return {
      test2: 18,
      test: "test",
    };
  },
  /* h */
  template: `
    <div v-show="test2 > 1" @click="testFn" :test="test2">{{test}}</div>
  `,
  methods: {
    testFn() {
      console.log(this.test2);
      this.test2--;
    },
  },
};
```

编译后的代码

```js
new Vue({
  el: "#app",
  data: function data() {
    return {
      test2: 18,
      test: "test",
    };
  },
  render: function _render1() {
    var _vm = this;

    var _h = _vm.$createElement;

    var _c = _vm._self._c || _h;

    return _c(
      "div",
      {
        directives: [
          {
            name: "show",
            rawName: "v-show",
            value: _vm.test2 > 1,
            expression: "test2 > 1",
          },
        ],
        attrs: {
          test: _vm.test2,
        },
        on: {
          click: _vm.testFn,
        },
      },
      [_vm._v(_vm._s(_vm.test))]
    );
  },
  methods: {
    testFn: function testFn() {
      console.log(this.test2);
      this.test2--;
    },
  },
});

// or

var test = {
  el: "#app",
  data: function () {
    return {
      test2: 18,
      test: "test",
    };
  },
  render: function _render1() {
    var _vm = this;

    var _h = _vm.$createElement;

    var _c = _vm._self._c || _h;

    return _c(
      "div",
      {
        directives: [
          {
            name: "show",
            rawName: "v-show",
            value: _vm.test2 > 1,
            expression: "test2 > 1",
          },
        ],
        attrs: {
          test: _vm.test2,
        },
        on: {
          click: _vm.testFn,
        },
      },
      [_vm._v(_vm._s(_vm.test))]
    );
  },
  methods: {
    testFn() {
      console.log(this.test2);
      this.test2--;
    },
  },
};
```

自定义魔法注释

```js
// flagStr 标记编译，ignoreFlagStr标记忽略编译，只有开启全量编译ignoreFlagStr才有效
{
  plugins: [['babel-plugin-transform-vue-inline-template-next', {
      flagStr: "custom h",
      ignoreFlagStr: "custom ignore1"
    }
  ]],
}
```

全量编译会忽略 flagStr 魔法注释，所有的 vue 内联都会编译

```js
// compileAll
{
  plugins: [['babel-plugin-transform-vue-inline-template-next',
   {compileAll: true}
  ]],
}
```

可以用过魔法注释/* ignore1 */忽略编译

```js
new Vue({
  el: "#app",
  data: function () {
    return {
      test2: 18,
      test: "test",
    };
  },
  /* ignore1 */
  template: `
    <div v-show="test2 > 1" @click="testFn" :test="test2">{{test}}</div>
  `,
  methods: {
    testFn() {
      console.log(this.test2);
      this.test2--;
    },
  },
});
```

---
_Source: https://npm.io/package/babel-plugin-transform-vue-inline-template-next · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
