Akshay Rawat
Akshay Rawat

Reputation: 4784

Using connect-assets with Express to precompile Handlebar templates

I'm using Express, connect-assets on an Ember project. I'm stuck with making connect-assets to properly precompile the handlebar templates.

I've configured express like this:

app.use(assets({
  src: app_root + 'app',
  buildDir: './public',
  jsCompilers: {
    hbs: hbsAssets
  }
}));

and with hbsAssets being:

module.exports = {
  match: /\.js$/,
  compileSync: function(sourcePath, source) {
    var match = sourcePath.match(/^.*\/app\/js\/templates\/(.+)\.hbs/)
    , templateName = match[1];

    var filename = path.basename(sourcePath, '.hbs')
    , js = handlebars.precompile(source).toString();

    return 'Ember.TEMPLATES' + '["' + templateName + '"] = Handlebars.template(' + js + ');';
  }
};

The problem is that the only the hbs layouts get rendered, the {{outlet}}s don't get inserted.

Any help would be appreciated

Upvotes: 0

Views: 327

Answers (1)

Akshay Rawat
Akshay Rawat

Reputation: 4784

In the end I ended up using https://npmjs.org/package/ember-template-compiler . It worked out of the box.

Upvotes: 1

Related Questions