繁体   English   中英

使用Grunt Bake观看多个文件,而无需一次编译所有文件

[英]Watch multiple files with Grunt Bake without compiling all at once

我想在Grunt Bake的工作流程中使用Grunt Bake 这是我的grunt.js设置:

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']
        }
    }

});

我的问题:如果更改一个文件,则所有文件都会被编译。 我可以通过为每个文件创建一个监视程序来解决此问题,但这似乎不是一个聪明的解决方案:

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']
        }
    }

});

想象有20多个不同的html文件...因此,这不是我的选择。 还有其他解决方案吗?

好的,我知道了!

确实有一个新的任务可以做到这一点:

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']
        }
    }

});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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