【问题标题】:Running grunt task only on changed file仅在更改的文件上运行 grunt 任务
【发布时间】:2014-09-10 09:57:52
【问题描述】:

我有一个将打字稿文件转换为 javascript 的 grunt ts 任务。在 gunt serve 上,我正在编译我拥有的所有 .ts 文件。然后我想配置 grunt 来观看 .ts 文件,但只转换已更改的 .ts 文件。

在网上搜索后,我发现了以下选项:

Grunt ts 任务:

ts: {
        all: {
            src: ['scripts/**/*.ts'],
            reference: 'scripts/_references.ts'
        }
    },

这是 grunt 任务,然后我正在监听 watch 事件:

grunt.event.on('watch', function (action, filepath, target) {
    switch (target) {
        case 'ts':
        {
            grunt.config(['ts.all.src'], filepath);
            grunt.config('watch.ts.tasks', 'ts');
            break;
        }
    }

问题是任务运行,但我更新到 ts.all.sec 变量的文件与 grunt serve 上的文件相同,并且任务再次转换所有文件。

谢谢!

【问题讨论】:

    标签: gruntjs typescript grunt-contrib-watch grunt-ts


    【解决方案1】:

    但仅转换已更改的 .ts 文件。

    如果你不使用reference.ts,grunt-ts 可以做到这一点(因为打字稿编译器会走上树,否则会编译所有引用的文件),不要使用--out(你是很好......你没有使用它)并改用外部模块。更多:(https://github.com/grunt-ts/grunt-ts#fast-compile

    【讨论】:

      【解决方案2】:

      您正在寻找名为grunt-newer 的插件。它完全满足您的需求。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-05-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多