简体   繁体   中英

Watch multiple files with Grunt Bake without compiling all at once

I want to use Grunt Bake for my grunt workflow. This is my grunt.js setup:

grunt.initConfig({

    bake: {
        build: {
            files: {
                'dev/foo.html': 'public/foo.html',
                'dev/bar.html': 'public/bar.html',
                'dev/foo2.html': 'public/foo2.html'
                // ...
            }
        }
    },

    watch: {
        bake: {
            files: ['dev/*.html'],
            tasks: ['bake:build']
        }
    }

});

My problem: If I change one file all files will be compiled. I could solve this with creating a watch listener for each file but this seems not to be a clever solution:

grunt.initConfig({

    bake: {
        foo: {
            files: {
                'dev/foo.html': 'public/foo.html'
            }
        },
        bar: {
            files: {
                'dev/bar.html': 'public/bar.html'
            }
        },
        foo2: {
            files: {
                'dev/foo2.html': 'public/foo2.html'
            }
        }
        // ...
    },

    watch: {
        foo1: {
            files: ['dev/foo.html'],
            tasks: ['bake:foo']
        },
        bar: {
            files: ['dev/bar.html'],
            tasks: ['bake:bar']
        },
        foo2: {
            files: ['dev/foo2.html'],
            tasks: ['bake:foo2']
        }
    }

});

Imagine there are 20+ different html files... So this is not an option for me. Any other solutions for doing that?

Ok, got it!

There is a newer task exactly for doing this:

grunt.initConfig({

    bake: {
        build: {
           files: {
                'dev/foo.html': 'public/foo.html',
                'dev/bar.html': 'public/bar.html',
                'dev/foo2.html': 'public/foo2.html'
                // ...
            }
        }
    },

    watch: {
        bake: {
            files: ['dev/*.html'],
            tasks: ['newer:bake:build']
        }
    }

});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM