文档章节

handlebars预编译

浮世微凉
 浮世微凉
发布于 2015/11/27 09:26
字数 512
阅读 42
收藏 0

Using the Handlebars precompiler, you can precompile your Handlebars templates to save time on the client and reduce the required runtime size of the handlebars library.

Getting Started

First, you will need to install node and npm. On OS X:
$ brew install node
This assumes you already have Homebrew installed. If not,  install it first.
Next, install the Handlebars npm package.
$ npm install handlebars -g
Using the -g flag installs the package globally, so it can be used in any project.
Now, you're ready to use the precompiler:
$ handlebars <input> -f <output>
The compiler will insert templates in Handlebars.templates. If your input file is person.handlebars, the compiler will insert it at Handlebars.templates.person. This template will be a function that may be directly executed in the same manner as templates compiled locally. I.e.
Handlebars.templates.person(context, options);
If you're working with precompiled templates, you don't need to ship the compiler with your deployed application. Instead, you can use the smaller "runtime" build.
<script src="/libs/handlebars.runtime.js"></script>
In addition to reducing the download size, eliminating client-side compilation will significantly speed up boot time, as compilation is the most expensive part of Handlebars.

Optimizations

Because you are precompiling templates, you can also apply several optimization to the compiler. The first allows you to specify a list of the known helpers to the compiler
handlebars <input> -f <output> -k each -k if -k unless
The Handlebars compiler will optimize accesses to those helpers for performance.
When all helpers are known at compile time, the --knownOnly option provides the smallest generated code that also provides the fastest execution.

Usage

Usage: node ./bin/handlebars [template|directory]...

Options:
  -f, --output         Output File
  --map                Source Map File                                                    [string]  [default: undefined]
  -a, --amd            Exports amd style (require.js)
  -c, --commonjs       Exports CommonJS style, path to Handlebars module                                 [default: null]
  -h, --handlebarPath  Path to handlebar.js (only valid for amd-style)                                     [default: ""]
  -k, --known          Known helpers
  -o, --knownOnly      Known helpers only
  -m, --min            Minimize output
  -n, --namespace      Template namespace                                              [default: "Handlebars.templates"]
  -s, --simple         Output template function only.
  -N, --name           Name of passed string templates. Optional if running in a simple mode. Required when operating
                       on multiple templates.
  -i, --string         Generates a template from the passed CLI argument.
                       "-" is treated as a special value and causes stdin to be read for the template value.
  -r, --root           Template root. Base value that will be stripped from template names.
  -p, --partial        Compiling a partial template
  -d, --data           Include data when compiling
  -e, --extension      Template extension.                                                       [default: "handlebars"]
  -b, --bom            Removes the BOM (Byte Order Mark) from the beginning of the templates.
  -v, --version        Prints the current compiler version
  --help               Outputs this message
If using the precompiler's normal mode, the resulting templates will be stored to the Handlebars.templatesobject using the relative template name sans the extension. These templates may be executed in the same manner as templates.
If using the simple mode the precompiler will generate a single javascript method. To execute this method it must be passed to the Handlebars.template method and the resulting object may be used as normal.

本文转载自:http://handlebarsjs.com/precompilation.html

共有 人打赏支持
浮世微凉
粉丝 1
博文 13
码字总数 2789
作品 0
浦东
程序员
私信 提问
Node.js模板引擎(Hanldlebars)

Handlebars 是基于jQuery的插件,以json对象为数据源,支持逻辑判断,循环操作等。 60k左右。 采用Logic-less template(无逻辑模板),加载时被预编译,而不是到了客户端执行代码时再去编译...

jedi_knight
2015/10/20
53
0
handlebars 安装erro

handlebars 安装: 1、npm 2、npm install -g handlebars(后面可以加@3.0.1版本号) 3、handlebars public/js/template > public/js/template.js 在相应目录进行预编译 事先确定你的电脑上已经...

浮世微凉
2015/11/27
81
0
Handlebars中文文档(译自官方版)

Handlebars 为你提供了一个可以毫无挫折感的高效率书写 语义化的模板 所必需的一切。 Mustache 模板和 Handlebars 是兼容的,所以你可以把Mustache模板拿来导入到Handlebars中,并开始使用H...

浮世微凉
2015/11/27
34
0
把手模块编译器--Locator-Handlebars

Locator-Handlebars 是 Yahoo 开发的定位器把手模块编译器。locator-handlebars可插入到要编译把手模版(compile Handlebars templates)的定位组件中。然后编译模版可用于使用 express-view...

大胖森
2015/05/05
109
0
tempistry

tempistry 是超轻量级的序列化 JavaScript 模板和先后呈现逻辑注册。 安装: npm install tempistry 使用 temper 来编译,所以支持以下渲染引擎: jade ejs hogan.js mustache handlebars 服...

叶秀兰
2015/05/08
93
0

没有更多内容

加载失败,请刷新页面

加载更多

case when then

case具有两种格式。简单case函数和case搜索函数。 --简单case函数case sex when '1' then '男' when '2' then '女’ else '其他' end--case搜索函数case when sex = '1' the...

architect刘源源
8分钟前
0
0
Kubernetes探秘—kubelet的配置参数

kubelet是Kubernetes中的核心组件,需要在每一个节点安装,也是kubernetes集群启动的第一个服务。kubelet的参数存放在多个目录,修改时如果不完整就会导致各种错误,下面我们kubelet的参数存...

openthings
11分钟前
0
0
如何通过 MySQL 的二进制日志恢复数据库数据

经常有网站管理员因为各种原因和操作,导致网站数据误删,而且又没有做网站备份,结果不知所措,甚至给网站运营和盈利带来负面影响。所以本文我们将和大家一起分享学习下如何通过 MySQL 的二...

吴伟祥
20分钟前
0
0
org.apache.catalina.startup.Catalina stopServer SEVERE: Could not contact localhost:8005. Tomcat may

org.apache.catalina.startup.Catalina stopServer SEVERE: Could not contact localhost:8005. Tomcat may 2017年07月21日 14:52:10 子木HAPPY阳VIP 阅读数:14134 标签: tomcatnginx 更多......

linjin200
22分钟前
0
0
线下工坊|Blockchain Coding Day:零基础教你开发DAPP(北京)

我们的目标是通过编程学习让你更了解区块链技术。这将对区块链开发初学者一次很好的体验。这里需要强调一下,编程零基础也能学会。 我们将以小组的形式,由教练带领学员完成DAPP开发。每位学...

HiBlock
59分钟前
2
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部