grunt-contrib-handlebars - 输出不同于当我运行句柄npm任务时 [英] grunt-contrib-handlebars - Output is different than when I run the handlebars npm task
问题描述
提前感谢您的时间和帮助。
Thank you in advance for your time and help.
我试图使用grunt-contrib-handlebars预编译句柄(.hbs)模板
I'm trying to precompile handlebars (.hbs) templates using grunt-contrib-handlebars
当我运行运行任务时,我最终得到:
When I run the run task I end up with this:
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 handlebars模块,我得到:
However, if I run the npm handlebars module from terminal I get this:
(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;
});
})();
第二个编译的模板(从终端运行)在我的应用程序中正常工作 - 才不是。
The second compiled template (run from terminal) works correctly in my app - but the one that grunt creates does not. Could someone perhaps point me in the right direction with what I might be doing wrong here?
我的gruntfile看起来像这样:
My gruntfile looks like this:
handlebars:
options:
wrapped: true
compile:
files: 'www/js/templates.js': ['app/templates/*.hbs']
再次感谢您的帮助!
推荐答案
证明这是一个由于使用不同版本的Handlebars导致的问题,其中grunt-contrib-handlebars版本不同于全局安装的handlepars模块。
Turns out this was a problem caused by using different versions of Handlebars where the grunt-contrib-handlebars version was different then the globally installed handlebars npm module.
这篇关于grunt-contrib-handlebars - 输出不同于当我运行句柄npm任务时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!