# @templatejs/precompiler

> template.js的模板预编译器

Latest version **3.1.4** (published 2023-11-23) · MIT license · 0 weekly downloads

## Install

```sh
npm install @templatejs/precompiler
pnpm add @templatejs/precompiler
yarn add @templatejs/precompiler
bun add @templatejs/precompiler
```

## Health

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

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.1.4 |
| Published | 2023-11-23 |
| First published | 2019-11-07 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=14.0.0 |
| Dependencies | 4 |
| Unpacked size | 567 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1317 |
| Author | yanhaijing |
| Maintainers | yanhaijing |
| Keywords | template, template.js, js |

## Links

- npm: https://www.npmjs.com/package/@templatejs/precompiler
- Repository: https://github.com/yanhaijing/template.js
- Homepage: https://github.com/yanhaijing/template.js#readme
- Issues: https://github.com/yanhaijing/template.js/issues
- npm.io page: https://npm.io/package/@templatejs/precompiler

## Dependencies (4)

- [esprima](https://npm.io/package/esprima.md) ^4.0.1
- [estraverse](https://npm.io/package/estraverse.md) ^4.3.0
- [@jsmini/extend](https://npm.io/package/@jsmini/extend.md) ^0.5.0
- [@templatejs/parser](https://npm.io/package/@templatejs/parser.md) ^3.1.4

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 3.1.4 (latest) — 2023-11-23
- 3.1.3-alpha.0 (next) — 2023-11-23
- 3.1.2-alpha.0 — 2023-11-23
- 3.1.0-alpha.0 — 2023-11-22
- 3.0.0-alpha.0 — 2023-11-22
- 2.4.2 — 2020-07-05
- 2.4.1 — 2020-07-01
- 2.4.0 — 2019-12-18
- 2.3.0 — 2019-12-15
- 2.2.1 — 2019-12-11
- 2.2.0 — 2019-11-19
- 2.1.0 — 2019-11-17
- 2.0.2 — 2019-11-09
- 2.0.2-alpha.0 — 2019-11-07
- 2.0.1-alpha.0 — 2019-11-07

## README

# [precompiler](https://github.com/yanhaijing/template.js/blob/master/packages/precompiler)
[![](https://img.shields.io/badge/Powered%20by-jslib%20base-brightgreen.svg)](https://github.com/yanhaijing/jslib-base)

[template.js](https://github.com/yanhaijing/template.js)的模板预编译器

## 兼容性
单元测试保证支持如下环境：

| IE   | CH   | FF   | SF   | OP   | IOS  | Android   | Node  |
| ---- | ---- | ---- | ---- | ---- | ---- | ---- | ----- |
| 6+   | 29+ | 55+  | 9+   | 50+  | 9+   | 4+   | 4+ |

**注意：编译代码依赖ES5环境，对于ie6-8需要引入[es5-shim](http://github.com/es-shims/es5-shim/)才可以兼容，可以查看[demo/demo-global.html](./demo/demo-global.html)中的例子**

## 使用者指南

通过npm下载安装代码

```bash
$ npm install --save @templatejs/precompiler
```

如果你是node环境

```js
const precompiler = require('@templatejs/precompiler');

const tpl = `
<div><%=a%></div>
`;

// return a render function string like
// function render(data) { return '<div>' + data['a'] + '</div>'}
precompiler.precompile(tpl);
```

支持的参数

```js
// sTag 开始标签
// eTag 结束标签
// escape 是否默认转移输出变量
// expression 获取template运行时的表达式，默认为 template
// compress 是否对html进行压缩
// tplName 模板文件的名字，方便报错时的提示
precompiler.precompile(tpl, {sTag: '<#', eTag: '#>', escape: true});
```

## 贡献者列表

[contributors](https://github.com/yanhaijing/template.js/graphs/contributors)

## 更新日志
[CHANGELOG.md](https://github.com/yanhaijing/template.js/blob/master/CHANGELOG.md)

## 计划列表
[TODO.md](https://github.com/yanhaijing/template.js/blob/master/TODO.md)

---
_Source: https://npm.io/package/@templatejs/precompiler · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
