Grunt任务重复键

时间:2013-10-29 15:03:59

标签: javascript gruntjs

我有一个带有任务的grunt文件,jshint在下面给出了重复键的警告:

       clean: ['public', 'build', 'css/main.css', 'css/print.css'],

        clean : {
            aftertest :['js/libs']
        },

如何在一个键中创建它,以便默认情况下它运行['public', 'build', 'css/main.css', 'css/print.css']

2 个答案:

答案 0 :(得分:2)

您应该使用different targets

grunt.initConfig({
  clean: {
    build: ['public', 'build', 'css/main.css', 'css/print.css'],
    aftertest: ['js/libs']
  }
});

然后在您的构建别名中,您可能希望像这样使用它:

grunt.registerTask('build', ['clean:build', 'stylus', 'jade', 'jshint']);

每当您为一项任务设置多个目标时,最好明确指定它们,以便将来知道每个目标的目的是什么。

答案 1 :(得分:1)

错误是因为您传递给grunt.initConfig的对象有两个具有相同名称的键。

这是gjslint任务的Gruntfile.js示例

module.exports = function(grunt) {
  // Project configuration.
  grunt.initConfig({
    watch: {
      files: ['<%= jshint.files %>'],
      tasks: ['jshint', 'qunit']
    },
    gjslint: {
      options: {
        flags: [
          '--nojsdoc'
        ],
        reporter: {
          name: 'console'
        }
      },
      app: {
        src: ['www/app/**/*.js']
      }
    }

  });

  grunt.loadNpmTasks('grunt-contrib-watch');
  grunt.loadNpmTasks('grunt-gjslint');
  grunt.registerTask('build', 'Grunt build taskt...', function() {
    grunt.log.write('you can log here some stuff...').ok();
  });

};