Javascript grunt contrib handlebars-输出与运行handlebars npm任务时不同
提前感谢您的时间和帮助 我正在尝试使用grunt contrib Handlebar预编译Handlebar(.hbs)模板 当我运行run任务时,我的结果是:Javascript grunt contrib handlebars-输出与运行handlebars npm任务时不同,javascript,compilation,coffeescript,handlebars.js,gruntjs,Javascript,Compilation,Coffeescript,Handlebars.js,Gruntjs,提前感谢您的时间和帮助 我正在尝试使用grunt contrib Handlebar预编译Handlebar(.hbs)模板 当我运行run任务时,我的结果是: this["JST"] = this["JST"] || {}; this["JST"]["app/templates/err.hbs"] = Handlebars.template(function (Handlebars,depth0,helpers,partials,data) { this.compilerInfo = [
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;
});
再次感谢你的帮助 这是由于使用不同版本的把手而导致的问题,grunt contrib把手版本与全球安装的把手npm模块不同。您还可以使用函数作为“processName”,并在GrunFile中指定“命名空间”,例如,如果您只有一个名为
handlebar
的文件夹中的文件article\u snippet.handlebar
可以执行以下操作:
handlebars: {
compile: {
options: {
namespace: 'Handlebars.templates',
processName: function(filename) {
var name = filenaname.split('/')[1].split('.');
return name[0];
},
wrapped: true,
commonjs: null
},
files: {
"js/articles/templates.js": "handlebars/article_snippet.handlebars",
}
}
},
从中汲取灵感,您可以通过将选项
namespace
设置为false来避免名称空间,但是我不确定您是否可以获得与以前仅使用npm包时相同的输出。请注意,版本可能不同!感谢Anzeo-空间问题很有帮助。我仍然需要弄清楚为什么其余的输出是不同的。还有其他想法吗?像素世界,恐怕我还没有找到解决方案。当我从npm变体迁移到grunt包时,我最终选择了更新我的Handlebar编译模板在我的项目中的使用方式?尽管在项目中和全球范围内安装了相同版本的把手,但我还是遇到了同样的问题?信不信由你,我在2020年仍在处理这个问题。您是否有机会访问此项目并提供所使用的版本?
handlebars:
options:
wrapped: true
compile:
files: 'www/js/templates.js': ['app/templates/*.hbs']
handlebars: {
compile: {
options: {
namespace: 'Handlebars.templates',
processName: function(filename) {
var name = filenaname.split('/')[1].split('.');
return name[0];
},
wrapped: true,
commonjs: null
},
files: {
"js/articles/templates.js": "handlebars/article_snippet.handlebars",
}
}
},