0

当您使用 Yeoman 创建 ember 应用程序时,它会为您创建一个车把模板文件夹 (.hbs)。

yeoman 配置是这样设置的:

watch: {
        ember_templates: {
          files: '<%= yeoman.app %>/templates/**/*.hbs',
          tasks: ['ember_templates', 'livereload']
        },
  • 当模板位于文件夹根目录中时,它可以工作
  • 当模板位于子文件夹template/mySubfolder中时,不会呈现模板(不返回 html)
  • 缺少模板时,ember 会抛出错误

因此,当模板位于子文件夹中时,它会被检测到...但是为什么不渲染

我尝试了各种表达方式,Gruntfile.js但它并没有改善它。

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

@Mishik(评论太长了)

整个“手表”部分:

    watch: {
        ember_templates: {
          files: '<%= yeoman.app %>/templates/**/*.hbs',
          tasks: ['ember_templates', 'livereload']
        },
        coffee: {
            files: ['<%= yeoman.app %>/scripts/{,*/}*.coffee'],
            tasks: ['coffee:dist']
        },
        coffeeTest: {
            files: ['test/spec/{,*/}*.coffee'],
            tasks: ['coffee:test']
        },
        compass: {
            files: ['<%= yeoman.app %>/styles/{,*/}*.{scss,sass}'],
            tasks: ['compass:server']
        },
        neuter: {
          files: ['<%= yeoman.app %>/scripts/{,*/}*.js'],
          tasks: ['neuter', 'livereload']
        },
        livereload: {
            files: [
                '<%= yeoman.app %>/*.html',
                '{.tmp,<%= yeoman.app %>}/styles/{,*/}*.css',
                '<%= yeoman.app %>/images/{,*/}*.{png,jpg,jpeg,gif,webp,svg}'
            ],
            tasks: ['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'
            }
        }
    }

这是我应该修改的部分吗?我尝试了几件事,但没有成功。

4

2 回答 2

2

正如 mishik 所指出的,templates/**/*.hbs是完全有效的。如果我们谈论的是 Yeoman,请注意您需要在 2 个地方更改值:

  1. 在 watch 任务中(这是你已经尝试过的)
  2. 在车把任务的下方。

这应该可以解决您的问题。

于 2013-06-25T03:31:06.923 回答
0

我遇到了同样的问题,但我发现这是替换问题,'/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;
            }
于 2014-09-02T22:52:04.240 回答