ember hbs templates as separate files

前端 未结 3 2017
春和景丽
春和景丽 2020-12-28 17:54

I want to run ember.js (version 1.0.0 Final) examples provided on their first page.

They divided each handlebar template in separate file with .hbs exte

3条回答
  •  太阳男子
    2020-12-28 18:19

    I build my templates with Grunt. It creates one template.js file which I load after Ember. This is my own Grunt config on coffescript:

    module.exports = (grunt) ->
      tmpl_dir = 'app_src/templates'
      grunt.initConfig
        tmpl_dir: tmpl_dir
        ember_handlebars:
          options:
            processName: (path) ->
              re = new RegExp("^#{tmpl_dir}\/(.*)\.hbs$", 'i')
              r = path.match(re)
              path = r[1]
              path = path.replace /\_/g, '-'
              console.log '>', path
              path
          files:
            src: '<%= tmpl_dir %>/**/*.hbs'
            dest: 'public/js/templates.js'
    
      grunt.loadNpmTasks('grunt-ember-handlebars')
    

提交回复
热议问题