当我在没有 node
任务的情况下运行 gulp 时,它工作正常并按预期处理客户端文件,如果我运行 gulp node
它按预期处理服务器文件。但是,如果我同时运行 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');
在 watch
任务中你有
monitorCtrlC();
这似乎是 this library
This function will prevent sending of SIGINT signal when Ctrl+C is pressed. Instead, the specified (or default) callback will be invoked.
关于javascript - 一起使用 gulp-nodemon 和 gulp.watch 时无法使用 Ctrl+C 停止 Gulp,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32953294/