吞噬nodemon,观察文件更改,“应用程序崩溃 – 在启动之前等待文件更改”

我试图自动化一个简单的gulp任务来运行/debugging节点,监视文件的变化,并重新启动节点,如果有任何文件更改。 我见过的最stream行的食谱使用gulp-nodemon ,但是当文件更改事件发生时,(gulp-) nodemon崩溃:

 [nodemon] app crashed - waiting for file changes before starting... 

崩溃发生不一致,所以有时我必须手动发送一个SIGINT来停止节点进程(哪种types会破坏nodemon的目的)。 我希望能够运行一个可以监视文件,运行或debugging节点的吞吐任务。 如何在没有nodemon崩溃的情况下实现这一点?

这不是幻想,但下面应该完成你想要的。

  'use strict' const gulp = require('gulp'); const spawn = require('child_process').spawn; gulp.task('debug', function() { let child = spawn("node", ["debug", "./server.js"], { stdio: 'inherit' }); gulp.watch([__dirname + "/*.js", '!gulpfile.js'], function(event) { console.log(`File %s was %s.`, event.path, event.type); if (child) { child.kill(); child = spawn("node", ["debug", "./server.js"], { stdio: 'inherit' }); } }); }); 

这假设你正在监视__dirname任何js文件的变化,除了你的gulp文件。