我试图用grunt-contrib-less和grunt-contrib-watch设置grunt-notify.一般情况下,这种方法运行良好,但是当grunt-less成功执行时,我无法通知grunt-notify通知我.
如果有人对如何设置或调试有任何见解,很高兴有任何输入.
完整信息:
我已经设置了grunt-notify,只要少用手表运行就会触发.当较少的任务失败时,这很有效.给我一个很棒的弹出错误:
作为参考,这是控制台输出:
如果不太成功,我没有收到任何通知.我想收到通知,但无法弄清楚如何启用此功能.
当成功较少时,这是控制台输出:
这是我使用的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']); };
关于Github的原始问题
您需要将任务的消息添加到gruntfile,并指定要为其发送消息的任务.见下文
notify: { less:{ options:{ title: "CSS Files built", message: "Less task complete" } } }
作为参考,您可以在git repo自述文件中看到它们的使用
添加完整性:
正如uKolka在下面提到的那样,您还需要根据他的解决方案更新监视任务:
watch: { less: { files: '**/*.less', tasks: ['less', 'notify:less'] } },
凡notify:less
引用notifiy对象中的较少任务.
应该注意的是,指定通知任务......
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
前面提到的.