问题
I have an issue with the configuration of "grunt-contrib-handlebars", below is my setup at the moment.
handlebars: {
compile: {
options: {
namespace: "my.namespace"
},
files: {
"<%= dist %>/templates/templates.js": "<%= src %>/templates/*.handlebars"
}
}
}
This is what I get at the moment:
my.namespace["src/templates/baseTemplate.handlebars"]
This is what I want:
my.namespace["baseTemplate"]
So I can call the templates like this:
my.namespace.baseTemplate(templateObj);
Is it possible to get this?
回答1:
Take a look my solution

I implemented it with browserify.
- I generated a .js file that contains all my templates.
- Than I required it with browserify. Example:
var templates = require('templates/all_templates_in_this_js_file_without_extension')();
3.And now I can use it like backbonejs template
Backbone.View.extend({
template: templates.product, //or templates['product']
render: function(){
this.$el.html(this.template(this.model.toJSON()))
}
});
来源:https://stackoverflow.com/questions/22511292/grunt-contrib-handlebars-configuration-issue