如何使grunt watch和grunt nodemon一起工作

我在node.js中有一个web应用程序,我想从nodemon开始,所以每次主脚本更改时,webapp都可以重新启动。 同时,我有我的咖啡脚本文件,我需要重新编译每次他们任何一个变化。 我已经设置了一个grunt-contrib-watch任务来侦听app/frontend/*.coffee文件,以分派咖啡分析器。 但是,这似乎并没有发生,因为nodemon任务也在监听。 我在nodemon ignore中设置了app/frontend/文件夹。 我也设置了nodemon并观察并发。 不过,每次我编辑咖啡脚本,咖啡任务都不会执行。

这是我的Gruntfile

 module.exports = function(grunt) { // Project configuration. grunt.initConfig({ concurrent: { dev: [ 'nodemon', 'watch' ], options: { logConcurrentOutput: true } }, coffee: { compile: { files: { 'app/public/app.js': ['app/frontend/*.coffee'] } } }, nodemon: { dev: { script: 'app/index.js', options: { ignore: ['app/frontend/**', 'app/public/**'] } } }, watch: { scripts: { files: 'app/frontend/*.coffee', tasks: ['coffee'], options: { spawn: false } } } }); grunt.loadNpmTasks('grunt-concurrent'); grunt.loadNpmTasks('grunt-contrib-coffee'); grunt.loadNpmTasks('grunt-contrib-watch'); grunt.loadNpmTasks('grunt-nodemon'); // Default task(s). grunt.registerTask('default', ['coffee', 'nodemon', 'watch']); }; 

您的Gruntfile指示Grunt运行nodemon并作为默认任务按顺序watch (因此,从不会像nodemon永不完成一样运行nodemon )。

您需要在最后一行中明确包含concurrent任务:

 grunt.registerTask('default', ['coffee', 'concurrent']);