把手编译function与选项参数

我想在handlejars在NodeJS环境下编译时缩小我的模板。

我search了这个,发现了handlebars.compile(templateLoaded); 有更多的parameter passing给它,而不仅仅是编译器的模板。 我想知道如何通过function和其他选项,我可以通过minify选项。

这里是一个链接到允许这个句柄代码: https : //github.com/wycats/handlebars.js/blob/271106d43fae96fc1287898568d000b871f19084/lib/handlebars/compiler/javascript-compiler.js

注意第46和48行。

我build议以下资源: http : //www.adamwadeharris.com/how-to-precompile-handlebars-templates/

你可以通过它(如果你有cli工具通过npm -g install handlebars )-m标志最小化,所以它会是这样的: handlebars -m js/templates/ js/templates/templates.js

然后而不是:

 var source = $("#handlebarsScriptId").html(); var template = Handlebars.compile(source); 

你传递: var template = Handlebars.templates.handlebarsScriptId;

你需要在你的html中包含:

 <script src="js/handlebars.js"></script> <script src="js/templates/templates.js"></script>