grunt-contrib-handlebars - Output is different than when I run the handlebars npm task(grunt-contrib-handlebars - 输出与我运行把手 npm 任务时不同)
问题描述
提前感谢您的时间和帮助.
我正在尝试使用 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);数据 = 数据 ||{};var buffer = "", stack1, functionType="function", escapeExpression=this.escapeExpression;缓冲区+=错误:";if (stack1 = helpers.error) { stack1 = stack1.call(depth0, {hash:{},data:data});}否则 { stack1 = depth0.error;stack1 = typeof stack1 === functionType ?stack1.apply(depth0) : stack1;}缓冲区 += 转义表达式(stack1)+ "</div>";返回缓冲区;});但是,如果我从终端运行 npm 车把模块,我会得到:
(function() {var 模板 = Handlebars.template,模板 = Handlebars.templates = Handlebars.templates ||{};模板['err.hbs'] = 模板(功能(车把,深度0,助手,部分,数据){this.compilerInfo = [4,'>= 1.0.0'];helpers = this.merge(helpers, Handlebars.helpers);数据 = 数据 ||{};var buffer = "", stack1, functionType="function", escapeExpression=this.escapeExpression;缓冲区+=错误:";if (stack1 = helpers.error) { stack1 = stack1.call(depth0, {hash:{},data:data});}否则 { stack1 = depth0.error;stack1 = typeof stack1 === functionType ?stack1.apply(depth0) : stack1;}缓冲区 += 转义表达式(stack1)+ "</div>";返回缓冲区;});})();第二个编译模板(从终端运行)在我的应用程序中正常工作 - 但 grunt 创建的模板不能.有人可能会指出我在这里可能做错的事情的正确方向吗?
我的 gruntfile 看起来像这样:
车把:选项:包裹:真编译:文件:'www/js/templates.js':['app/templates/*.hbs']
再次感谢您的帮助!
解决方案 原来这是使用不同版本的 Handlebars 导致的问题,其中 grunt-contrib-handlebars 版本与全局安装的 handlebars npm 模块不同.
p>
Thank you in advance for your time and help.
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;
});
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?
My gruntfile looks like this:
handlebars:
options:
wrapped: true
compile:
files: 'www/js/templates.js': ['app/templates/*.hbs']
Thanks again for your help!
解决方案 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 任务时不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:grunt-contrib-handlebars - 输出与我运行把手 npm 任务时不同
基础教程推荐
- 我什么时候应该在导入时使用方括号 2022-01-01
- 在 JS 中获取客户端时区(不是 GMT 偏移量) 2022-01-01
- 悬停时滑动输入并停留几秒钟 2022-01-01
- Karma-Jasmine:如何正确监视 Modal? 2022-01-01
- 当用户滚动离开时如何暂停 youtube 嵌入 2022-01-01
- 在for循环中使用setTimeout 2022-01-01
- 有没有办法使用OpenLayers更改OpenStreetMap中某些要素 2022-09-06
- 动态更新多个选择框 2022-01-01
- 响应更改 div 大小保持纵横比 2022-01-01
- 角度Apollo设置WatchQuery结果为可用变量 2022-01-01