Javascript 无法使用Ctrl+;C当使用gulp nodemon&;一起喝,一起看

Javascript 无法使用Ctrl+;C当使用gulp nodemon&;一起喝,一起看,javascript,gulp,Javascript,Gulp,当我在没有节点任务的情况下运行gulp时,它工作正常并按预期处理客户机文件,如果我运行gulp节点它按预期处理服务器文件。但是,如果我同时运行gulp它会按预期处理客户端和服务器文件,但它不会让我按Ctrl+C退出(在windows 10和Mac El Capitan上试用过)。我有什么地方做错了吗 'use strict'; var gulp = require('gulp'); var connect = require('gulp-connect'); var bro

当我在没有
节点
任务的情况下运行gulp时,它工作正常并按预期处理客户机文件,如果我运行
gulp节点
它按预期处理服务器文件。但是,如果我同时运行
gulp
它会按预期处理客户端和服务器文件,但它不会让我按Ctrl+C退出(在windows 10和Mac El Capitan上试用过)。我有什么地方做错了吗

'use strict';
  var gulp = require('gulp');
    var connect = require('gulp-connect'); 
    var browserify = require('browserify'); 
    var source = require('vinyl-source-stream'); 
    var nodemon = require('gulp-nodemon');

    var config = {
        port: 9005,
        devBaseUrl: 'http://localhost',
        paths: {
            html: './src/*.html',
            dist: './dist',
            js: './src/**/*.js',
            images: './src/images/*',
            mainJs: './src/main.js',
            css: [
                'node_modules/bootstrap/dist/css/bootstrap.min.css',
                'node_modules/bootstrap/dist/css/bootstrap-theme.min.css'
            ]
        }
    };

gulp.task('connect', function () {
    connect.server({
        root: ['dist'],
        port: config.port,
        base: config.devBaseUrl,
        livereload: true
    });
});


gulp.task('html', function () {
    gulp.src(config.paths.html)
        .pipe(gulp.dest(config.paths.dist))
});

gulp.task('js', function () {
    browserify(config.paths.mainJs)
        .bundle()
        .on('error', console.error.bind(console))
        .pipe(source('bundle.js'))
        .pipe(gulp.dest(config.paths.dist + '/scripts'))
        .pipe(connect.reload())

});

gulp.task('node', function () {
    nodemon({
        script: 'server/index.js',
        ext: 'js',
        env: {
            PORT: 8000
        },
        ignore: ['node_modules/**','src/**','dist/**']
    })
    .on('restart', function () {
        console.log('Restarting node server...');
    })
});

gulp.task('watch', function () {
    gulp.watch(config.paths.js, ['js']);
});

gulp.task('default', ['html', 'js', 'connect', 'node', 'watch']);

就在你的最上面

var monitorCtrlC = require('monitorctrlc');
监视
任务的内部

monitorCtrlC();
似乎是

当按下Ctrl+C时,此功能将防止发送SIGINT信号 按下。相反,将调用指定(或默认)回调


就在你的最上面

var monitorCtrlC = require('monitorctrlc');
监视
任务的内部

monitorCtrlC();
似乎是

当按下Ctrl+C时,此功能将防止发送SIGINT信号 按下。相反,将调用指定(或默认)回调


为了防止它对其他人有帮助,我删除了
node\u模块
,并安装了
npm
,为我解决了这个问题…

为了防止它对其他人有帮助,我删除了
node\u模块
,并安装了
npm
,这为我解决了问题…

在这之前,我遇到了类似的问题,这是您正在寻找的:

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

只需将此代码添加到您的gulp文件中。它将监视ctrl+C并正确终止进程。如果需要,您也可以在超时中添加一些其他代码。

在此之前,我也遇到过类似的问题,这是您要查找的:

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

只需将此代码添加到您的gulp文件中。它将监视ctrl+C并正确终止进程。如果需要,您也可以在超时中添加一些其他代码。

SIGINT解决方案对我不起作用,可能是因为我也在使用gulp nodemon,但它起到了作用:

    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();
    });

从中获取。

SIGINT解决方案对我不起作用,可能是因为我也在使用gulp nodemon,但它起了作用:

    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();
    });

这是我在windows上开发时使用的。由于在windows上,需要先按“Ctrl+C”,然后确认“是/否”以结束批处理过程,MonitorCtrc()仅帮助删除windows中的额外步骤。但是,我已经尝试完全删除它,因为我在Mac上不需要它,最终结果还是一样的。你可能不应该把它包括在这个问题中,因为它正是你所抱怨的:)对不起,我删除它是为了避免混淆这是我在windows上开发时使用的东西。由于在windows上,需要先按“Ctrl+C”,然后确认“是/否”以结束批处理过程,MonitorCtrc()仅帮助删除windows中的额外步骤。但是,我已经尝试完全删除它,因为我在Mac上不需要它,最终结果仍然是一样的。你可能不应该在这个问题中包括它,因为它正是你所抱怨的:)对不起,为了避免混淆,我删除了它。你能把它减少到最少的代码量来演示你的问题吗?我删除了不必要的部分。你能把它减少到最少的代码量来演示你的问题吗?我删除了不必要的部分