如何为车把模板制作grunt watch子文件夹(带有Yeoman的ember.js应用程序)

如何为车把模板制作grunt watch子文件夹(带有Yeoman的ember.js应用程序),ember.js,handlebars.js,gruntjs,yeoman,Ember.js,Handlebars.js,Gruntjs,Yeoman,使用Yeoman创建余烬应用程序时,它会为您创建一个Handlebar templates文件夹(.hbs) yeoman配置的设置方式如下: watch: { ember_templates: { files: '<%= yeoman.app %>/templates/**/*.hbs', tasks: ['ember_templates', 'livereload'] }, @Mishik(评论太长) 整

使用Yeoman创建余烬应用程序时,它会为您创建一个Handlebar templates文件夹(.hbs)

yeoman配置的设置方式如下:

watch: {
        ember_templates: {
          files: '<%= yeoman.app %>/templates/**/*.hbs',
          tasks: ['ember_templates', 'livereload']
        },

@Mishik(评论太长)

整个“手表”部分:

观察:{
ember_模板:{
文件:'/templates/***.hbs',
任务:['ember_templates','livereload']
},
咖啡:{
文件:['/scripts/{,*/}*.coffee'],
任务:['coffee:dist']
},
咖啡测试:{
文件:['test/spec/{,*/}*.coffee'],
任务:[“咖啡:测试”]
},
指南针:{
文件:['/styles/{,*/}*{scss,sass}'],
任务:['compass:server']
},
中性化:{
文件:['/scripts/{,*/}*.js'],
任务:['neuter','livereload']
},
利弗雷罗德:{
档案:[
“/*.html”,
“{.tmp,}/styles/{,*/}*.css”,
“/images/{,*/}*{png,jpg,jpeg,gif,webp,svg}”
],
任务:['livereload']
}
}
还有一些我第一次没看到的东西:

    ember_templates: {
        options: {
            templateName: function (sourceFile) {
                var templatePath = yeomanConfig.app + '/templates/';
                return sourceFile.replace(templatePath, '');
            }
        },
        dist: {
            files: {
                '.tmp/scripts/compiled-templates.js': '<%= yeoman.app %>/templates/{,*/}*.hbs'
            }
        }
    }
ember\u模板:{
选项:{
templateName:函数(源文件){
var templatePath=yeomanConfig.app+'/templates/';
返回sourceFile.replace(templatePath“”);
}
},
地区:{
档案:{
“.tmp/scripts/compiled templates.js”:“/templates/{,*/}*.hbs”
}
}
}

这是我应该修改的部分吗?我尝试了一些方法,但没有成功。

正如米希克所指出的,
模板/***。hbs
完全有效。如果我们谈论的是Yeoman,请注意,您需要在两个位置更改值:

  • 在watch任务中(这是您已经尝试过的)
  • 下面是把手内的任务

  • 这应该能解决你的问题

    我也遇到了同样的问题,但我发现是替换问题,“/templates/**”对我不起作用

    以下是我的例子:

           templateName: function (sourceFile) {
                    var templatePath = yeomanConfig.app + '/templates/web/';
                        sourceFile= sourceFile.replace(templatePath, '');
                    templatePath = yeomanConfig.app + '/templates/mobile/';
                        sourceFile= sourceFile.replace(templatePath, '');
                    templatePath = yeomanConfig.app + '/templates/tablet/';
                        sourceFile= sourceFile.replace(templatePath, '');
                    return sourceFile;
                }
    

    你能展示“灰烬模板”和“livereload”任务吗
    templates/***.hbs
    是在
    templates
    的所有子目录(任何级别)中查找
    *.hbs
    文件的有效指令。好的,这是我没有看到的把手任务。谢谢
        ember_templates: {
            options: {
                templateName: function (sourceFile) {
                    var templatePath = yeomanConfig.app + '/templates/';
                    return sourceFile.replace(templatePath, '');
                }
            },
            dist: {
                files: {
                    '.tmp/scripts/compiled-templates.js': '<%= yeoman.app %>/templates/{,*/}*.hbs'
                }
            }
        }
    
           templateName: function (sourceFile) {
                    var templatePath = yeomanConfig.app + '/templates/web/';
                        sourceFile= sourceFile.replace(templatePath, '');
                    templatePath = yeomanConfig.app + '/templates/mobile/';
                        sourceFile= sourceFile.replace(templatePath, '');
                    templatePath = yeomanConfig.app + '/templates/tablet/';
                        sourceFile= sourceFile.replace(templatePath, '');
                    return sourceFile;
                }