文档章节

handlebars预编译

浮世微凉
 浮世微凉
发布于 2015/11/27 09:26
字数 512
阅读 40
收藏 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

没有更多内容

加载失败,请刷新页面

加载更多

Linux 中不适用功能键切换TTY

本简要指南介绍了在类 Unix 操作系统中如何在不使用功能键的情况下切换 TTY。在进一步讨论之前,我们将了解 TTY 是什么。正如在 AskUbuntu 论坛的一个答案[1]中所提到的,TTY这个词来自 Tele...

问题终结者
1分钟前
0
0
OSChina 周三乱弹 —— 我自己总觉得我的灵魂有毒

Osc乱弹歌单(2018)请戳(这里) 【今日歌曲】 @Devoes :分享王菲的单曲《匆匆那年 (Fleet of Time)》 《匆匆那年 (Fleet of Time)》- 王菲 手机党少年们想听歌,请使劲儿戳(这里) 天长地...

小小编辑
8分钟前
1
2
深度学习与图像处理实例:人像背景虚化与背景替换

简单人像背景虚化处理思路如下: 对图像内容分割,提取人像,背景 背景模糊处理 人像与模糊处理后的背景融合 本实例使用DeepLabV3图像分割深度学习模型实现。代码如下: import numpy as np...

IOTService
昨天
0
0
八月新增开源项目:假装自己是图形界面的 Git 命令行工具

每月新增开源项目。顾名思义,每月更新一期。我们会从社区上个月新收录的开源项目中,挑选出有价值的、有用的、优秀的、或者好玩的开源项目来和大家分享。数量不多,但我们力求推荐的都是精品...

编辑部的故事
昨天
7
0
20180918 find命令与Linux文件扩展名

命令find 用来查找搜索文件。 搜索文件相关命令: which 从环境变量里的目录中去搜索 whereis(不常用) 从一个固定的库中搜索 locate(需要单独安装 yum install -y mlocate) 查询时会从/var/...

野雪球
昨天
1
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部