2013-02-22 81 views
1

我不知道我怎麼能看這裏的文件:gruntjs棘手的配置

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

我可以把「應用程序/車把/ *車把。」但我希望編寫採取正確的路徑動態

東西
+0

你可能也想看看[grunt-regarde](https://github.com/yeoman/grunt-regarde)。我認爲它能更好地完成這項工作。 – 2013-02-25 11:40:26

回答

1

<%= handlebars.compile.files %>在你的配置中指向一個對象。所以手錶不知道你真正想要的文件。嘗試添加/讀取配置VAR是這樣的:

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 %>得到。