I’ve been really struggling with precompiling handlebar templates for ember.js
I have tried implementing a half dozen node packages, but have been unable to make it through the documentation before running into errors or dependency-issues that I can’t resolve.
I really don’t care about the technologies or method I need to use, I just want to see if there is a detailed guide somewhere on a tool that I can use to precompile handlebar files in a directory to a single JS file that is Ember ready.
do you use any build tool like Grunt or Gulp? if you use Grunt, take a look at https://github.com/dgeb/grunt-ember-templates which is just great (documentation is also good) - if you use Gulp, take the approach of @macu.
@hazeltree I had the same issue and made a small Broccoli plugin that you can pass a compile function. Here’s an example of how I use ember-template-compiler.js with the broccoli plugin to output a single file with all precompiled templates.
module.exports = function (broccoli) {
var compiler = require('ember-template-compiler');
var broccoliTemplateBuilder = require('broccoli-template-builder');
var templates = broccoli.makeTree('your/templates');
templates = broccoliTemplateBuilder(templates, {
extensions: ['hbs']
, outputFile: 'assets/templates.js'
, namespace: 'Ember.TEMPLATES'
, compile: function (string) {
return 'Ember.Handlebars.template('+compiler.precompile(string)+')';
}
});
return templates;
};