1

我想知道如何在这里观看文件:

module.exports = function(grunt) {

  grunt.loadNpmTasks('grunt-contrib-watch');
  grunt.loadNpmTasks('grunt-contrib-handlebars');

  // Project configuration.
  grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),
    handlebars: {
      compile: {
        files: {
          "app/handlebars/handlebars-templates.js" : [
            "app/handlebars/*.handlebars"
          ]
        }
      }
    },
    watch: {
      handlebars: {
        files: [
          '<%= handlebars.compile.files %>' <== what to put here ?
        ],
        tasks: 'default'
      }
    }
  });

  grunt.registerTask('default', 'handlebars');
};

我可以放“app/handlebars/*.handlebars”,但我想写一些动态走正确路径的东西

4

1 回答 1

1

<%= handlebars.compile.files %>在您的配置中指向一个对象。所以手表不知道你真正想要哪些文件。尝试像这样添加/读取配置变量:

grunt.initConfig({
  pkg: grunt.file.readJSON('package.json'),
  handlebars_path: "app/handlebars/*.handlebars",
  handlebars: {
    compile: {
      files: {
        "app/handlebars/handlebars-templates.js" : [
          "<%= handlebars_path %>"
        ]
      }
    }
  },
  watch: {
    handlebars: {
      files: [
        "<%= handlebars_path %>"
      ],
      tasks: 'default'
    }
  }
});

或者使用更明确的配置:

handlebars: {
  compile: {
    src: ['app/handlebars/*.handlebars'],
    dest: 'app/handlebars/handlebars-templates.js'
  }
}

和得到<%= handlebars.compile.src %>

于 2013-02-23T23:24:47.447 回答