How do you watch multiple files, but only run task on changed file, in Grunt.js?

前端 未结 7 1864
盖世英雄少女心
盖世英雄少女心 2020-12-01 00:12

In learning how to use grunt, I am trying to make a simple coffee-script watcher/compiler. The problem is, if I tell the watch task to watch several files, and

7条回答
  •  旧时难觅i
    2020-12-01 00:48

    So new to Grunt 0.4 is more named tasks

    Let us give you an example!

    watch: {
        package1: {
            files: [
                './modules/package1/**/*.coffee'
            ],
            tasks: ['coffee:package3']
        },
        package2: {
            files: [
                './test_packages/package2/**/*.coffee'
            ],
            tasks: ['coffee:package3']
        },
        package3: {
            files: [
                './test_packages/package3/**/*.coffee'
            ],
            tasks: ['coffee:package3']
        },
    }
    

    To run all those watch tasks, simply do grunt.registerTask('default', ['myInitialBuild', 'watch']);

    Where myInitialBuild is whatever initial build (all of the files) then follow it up with a watch on each package. In reality you could do this for every file but that sounds sucky.

提交回复
热议问题