esbuild-plugin-templatejs
TypeScript icon, indicating that this package has built-in type declarations

3.1.4 • Public • Published

template.js的 esbuild 编译插件。

安装

$ npm install --save @templatejs/runtime # 安装template运行时
$ npm install --save-dev esbuild-plugin-templatejs # 安装template编译插件

配置

配置参数同template.js参数一样,其中 expression 参数会作为获取 template 的表达式。

这里有一个通过 tempalte cli 创建的 vue 项目的示例:

https://github.com/yanhaijing/template.js/tree/master/packages/cli/template/esbuild/base

在esbuild配置文件,添加如下内容:

import * as esbuild from 'esbuild';
import templatejs from 'esbuild-plugin-templatejs';

await esbuild.build({
  entryPoints: ['./src/app.js'],
  bundle: true,
  outfile: './dist/index.js',
  plugins: [
    templatejs({
      sTag: '<%',
      eTag: '%>',
      expression: 'require("@templatejs/runtime")',
    }),
  ],
});

新建模版文件 demo.tmpl

<div><#=abc#></div>

在 js 中import模版文件,并渲染

import tpl from './demo.tmpl';

document.getElementById('test').innerHTML = tpl({ abc: 'yanhaijing' });

贡献者列表

contributors

⚙️ 更新日志

CHANGELOG.md

✈️ 计划列表

TODO.md

Readme

Keywords

Package Sidebar

Install

npm i esbuild-plugin-templatejs

Weekly Downloads

1

Version

3.1.4

License

MIT

Unpacked Size

60.7 kB

Total Files

10

Last publish

Collaborators

  • yanhaijing