Cannot stop Gulp with Ctrl+C when using gulp-nodemon & gulp.watch together

人走茶凉 提交于 2019-12-02 11:35:00

Right at the top you have

var monitorCtrlC = require('monitorctrlc');

and inside of the watch task you have

monitorCtrlC();

Which seems to be this library

This function will prevent sending of SIGINT signal when Ctrl+C is pressed. Instead, the specified (or default) callback will be invoked.

I had a similar issue before this is what you're looking for :

process.on('SIGINT', function() {
  setTimeout(function() {
    gutil.log(gutil.colors.red('Successfully closed ' + process.pid));
    process.exit(1);
  }, 500);
});

Just add this code to your gulp file. It will watch the ctrl + C and properly terminate the process. You can put some other code in the timeout also if desired.

just in case it helps someone else, I deleted the node_modules and did npm install which fixed the issue for me...

The SIGINT solution did not work for me, probably because I'm also using gulp-nodemon but this worked:

    var monitor = $.nodemon(...)
    // Make sure we can exit on Ctrl+C
    process.once('SIGINT', function() {
    monitor.once('exit', function() {
          console.log('Closing gulp');
          process.exit();
        });
    });
    monitor.once('quit', function() {
        console.log('Closing gulp');
        process.exit();
    });

Got it from here.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!