How to run two grunt watch tasks simultaneously

前端 未结 9 1040
情歌与酒
情歌与酒 2020-12-12 16:29

Is it possible to run two watch tasks simultaneously?

I understand that I can have any number of tasks I want inside watch settings and just launch grun

9条回答
  •  -上瘾入骨i
    2020-12-12 16:37

    grunt-concurrent or grunt-focus are both good solutions, but both of them break livereload functionality.

    My solution to this is to compose the watch configuration dynamically, with the assumption that you won't be running both configuration at the same time.

    You can do something like this

    grunt.config.merge({
      watch: {
        options: {
          livereload: true
        },
        C: {
          files: "js/dev/**/*.html",
          tasks: ["copy"]
        }
      }
    });
    
    grunt.registerTask('watch-forProd', function () {
      grunt.config.merge({
        watch: {
          A: {
            files: "js/dev/**/*.coffee",
            tasks: ["coffee", "requirejs"]
          }
        }
      });
    
      grunt.task.run('watch');
    });
    
    grunt.registerTask('watch-forDev', function () {
      grunt.config.merge({
        watch: {
          B: {
            files: "js/dev/**/*.coffee",
            tasks: ["coffee"]
          }
        }
      });
    
      grunt.task.run('watch');
    });
    
    grunt.registerTask("prod", ["watch-forProd"]);
    grunt.registerTask("dev", ["watch-forDev"]);

提交回复
热议问题