提前感谢您的时间和帮助。
我正在尝试使用 grunt-contrib-handlebars 预编译把手(.hbs)模板
当我运行运行任务时,我最终得到了这个:
this["JST"] = this["JST"] || {};
this["JST"]["app/templates/err.hbs"] = Handlebars.template(function (Handlebars,depth0,helpers,partials,data) {
this.compilerInfo = [4,'>= 1.0.0'];
helpers = this.merge(helpers, Handlebars.helpers); data = data || {};
var buffer = "", stack1, functionType="function", escapeExpression=this.escapeExpression;
buffer += "<div>Error: ";
if (stack1 = helpers.error) { stack1 = stack1.call(depth0, {hash:{},data:data}); }
else { stack1 = depth0.error; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; }
buffer += escapeExpression(stack1)
+ "</div>";
return buffer;
});
但是,如果我从终端运行 npm 车把模块,我会得到:
(function() {
var template = Handlebars.template, templates = Handlebars.templates = Handlebars.templates || {};
templates['err.hbs'] = template(function (Handlebars,depth0,helpers,partials,data) {
this.compilerInfo = [4,'>= 1.0.0'];
helpers = this.merge(helpers, Handlebars.helpers); data = data || {};
var buffer = "", stack1, functionType="function", escapeExpression=this.escapeExpression;
buffer += "<div>Error: ";
if (stack1 = helpers.error) { stack1 = stack1.call(depth0, {hash:{},data:data}); }
else { stack1 = depth0.error; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; }
buffer += escapeExpression(stack1)
+ "</div>";
return buffer;
});
})();
第二个编译模板(从终端运行)在我的应用程序中正常工作 - 但 grunt 创建的模板不能。有人可能会指出我在这里可能做错的事情的正确方向吗?
我的 gruntfile 看起来像这样:
handlebars:
options:
wrapped: true
compile:
files: 'www/js/templates.js': ['app/templates/*.hbs']
再次感谢你的帮助!