1

concat插件为例,我们可以在 Gruntfile.js 中设置调试和发布目标:

grunt.initConfig({
  concat: {
    debug: {
    },
    release: {
    },
  }

grunt-contrib-watch插件可以有多种配置吗?

这样做时:

watch: {
  debug: {
    options: {
      livereload: true,
      nospawn: true
    },
    copy: {
      files: ['js/app/**/*.js', 'js-amd/**/*.js'],
      tasks: ['copy']
    }

我收到一条错误消息verifying property watch.debug.files exists in config

这也不起作用:

watch: {
   debug: {
      options: {
        livereload: true,
        nospawn: true
      },
      files: ['js/app/**/*.js', 'js-amd/**/*.js'],
      tasks: ['copy'],

      files: ['jade/**/*.jade'],
      tasks: ['jade:devmock']

...因为我不能有两个files-arrays 或两个tasks-arrays。(它忽略除第一对之外的所有files/tasks内容)

还有其他方法可以实现我想要的吗?

4

3 回答 3

1

If you want two sets of files, you will need a new set of config

watch: {
    debug: {
      files: ['js/app/**/*.js', 'js-amd/**/*.js'],
      tasks: ['copy'],
      options: {
        livereload: true,
        nospawn: true
      }
    },
    other-debug: {
      files: ['js/app/**/*.js', 'js-amd/**/*.js'],
      tasks: ['copy'],
      options: {
        livereload: true,
        nospawn: true
      }
    }
  }
于 2013-06-25T10:55:40.790 回答
1

是的。

配置比较扁平。

  watch: {
    debug: {
      files: ['js/app/**/*.js', 'js-amd/**/*.js'],
      tasks: ['copy'],
      options: {
        livereload: true,
        nospawn: true
      }
    }
  }

您将在此处找到更多示例:https ://github.com/gruntjs/grunt-contrib-watch

于 2013-06-25T09:42:44.967 回答
0

我使用的一个解决方案是定义多个监视目标并重命名监视任务,如下所示:

watch: {
    scripts: {
        files: ['js/**/*.js'],
        tasks: ['concat', 'uglify'],
        options: {
            spawn: false
        }
    }
},

// Don't uglify in dev task
watchdev: {
    scripts: {
        files: ['js/**/*.js'],
        tasks: ['concat'],
        options: {
            spawn: false
        }
    }
}

grunt.loadNpmTasks('grunt-contrib-watch');
// Rename watch to watchdev and load it again
grunt.renameTask('watch', 'watchdev');
grunt.loadNpmTasks('grunt-contrib-watch');

grunt.registerTask('default', ['watch']);
grunt.registerTask('dev', ['watchdev']);
于 2014-02-13T03:32:02.203 回答