使用带有Express的connect-assets来预编译Handlebar模板

时间:2013-12-13 17:58:35

标签: ember.js express handlebars.js connect-assets

我在Ember项目上使用Express,connect-assets。我坚持让connect-assets正确预编制车把模板。

我配置了这样的表达:

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

并且hbsAssets为:

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 + ');';
  }
};

问题是只渲染了hbs布局,{{outlet}}没有被插入。

任何帮助将不胜感激

1 个答案:

答案 0 :(得分:1)

最后我最终使用了https://npmjs.org/package/ember-template-compiler。它开箱即用。