-1

我有一个包含任务和 jshint 的 grunt 文件,在下面给我一个重复键的警告:

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

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

如何一键完成此操作,以便默认运行['public', 'build', 'css/main.css', 'css/print.css']

4

2 回答 2

2

您应该为此使用不同的目标

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

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

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

每当您对一项任务有多个目标时,最好明确命名它们,以便您将来知道每个目标的目的是什么。

于 2013-10-29T15:22:35.137 回答
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();
  });

};
于 2013-10-29T15:12:01.507 回答