【问题标题】:grunt-notify: Doesn't trigger on successgrunt-notify:成功时不触发
【发布时间】:2014-09-25 15:16:15
【问题描述】:

我正在尝试使用grunt-contrib-lessgrunt-contrib-watch 设置grunt-notify。一般来说,这运行良好,但当 grunt-less 成功执行时,我无法让 grunt-notify 通知我。

如果有人对如何设置或调试有任何见解,很高兴有任何意见。


完整信息:

我已经设置了 grunt-notify 以在 less 使用手表运行时触发。当较少的任务失败时,这很有效。给我一个很大的弹出错误:

作为参考,这是控制台输出:

当 less 成功时,我没有收到任何通知。我想收到通知,但不知道如何启用它。

这是less成功时的控制台输出:

这是我正在使用的 GruntFile:

module.exports = function(grunt) {

    grunt.initConfig({

        less: {
            development: {
                options: {
                    compress: true
                },
                files: {
                    "FILE.css": "FILE2.less"
                }
            }
        },

        watch: {
            less: {
                files: '**/*.less',
                tasks: ['less', 'notify_hooks']
            }
        },


        notify_hooks: {
            options: {
                message: "MESSAGE"
            }

        }


    });

    grunt.loadNpmTasks('grunt-contrib-less');
    grunt.loadNpmTasks('grunt-contrib-watch');
    grunt.loadNpmTasks('grunt-notify');

    grunt.registerTask("default", ['less']);

};

Original question on Github

【问题讨论】:

    标签: javascript gruntjs less grunt-contrib-watch grunt-notify


    【解决方案1】:

    您需要为您的任务添加一条消息到 gruntfile 并指定它将为哪个任务提供该消息。见下文

    notify: {
        less:{
            options:{
                title: "CSS Files built",
                message: "Less task complete"
            }
        }
    }
    

    作为参考,您可以在git repo readme 中看到它们的使用

    为完整性添加:

    正如 uKolka 在下面提到的,您还需要按照他的解决方案更新监视任务:

    watch: {
        less: {
            files: '**/*.less',
            tasks: ['less', 'notify:less']
        }
    },
    

    notify:less 引用了通知对象中的较少任务。

    【讨论】:

    • 谢谢!我发誓我昨天试过这个,但它没有用。虽然现在可以工作,所以谢谢! - 将在 5 分钟内接受此作为接受的答案(一旦允许)。
    【解决方案2】:

    需要注意的是,指定通知任务...

    notify: {
        less:{
            options:{
                title: "CSS Files built"
                message: "Less task complete"
            }
        }
    }
    

    ...只是交易的一部分。

    它还应该注册在您希望触发它的任务中。

    所以原始 OP 的代码可以正常工作

        watch: {
            less: {
                files: '**/*.less',
                tasks: ['less', 'notify_hooks']
            }
        },
    

    应该改为

        watch: {
            less: {
                files: '**/*.less',
                tasks: ['less', 'notify:less']
            }
        },
    

    这里引用了前面提到的notify:less

    【讨论】:

    • 这个答案真正解决了大多数人在正确配置事情时可能步履蹒跚的问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-26
    • 1970-01-01
    • 2014-02-26
    • 1970-01-01
    相关资源
    最近更新 更多