admin管理员组文章数量:1414605
When I run gulp without the node
task, it works fine and processes client file as expected, If I run gulp node
it processes server file as expected. However if I run both gulp
it processes both client and server file as expected, however, it won't let me quit by pressing 'Ctrl + C' (Tried it on windows 10 & Mac El Capitan). Is there something I'm doing wrong here?
'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']);
When I run gulp without the node
task, it works fine and processes client file as expected, If I run gulp node
it processes server file as expected. However if I run both gulp
it processes both client and server file as expected, however, it won't let me quit by pressing 'Ctrl + C' (Tried it on windows 10 & Mac El Capitan). Is there something I'm doing wrong here?
'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']);
Share
Improve this question
edited Oct 5, 2015 at 16:40
Bellicose Agnostic
asked Oct 5, 2015 at 16:22
Bellicose AgnosticBellicose Agnostic
761 silver badge9 bronze badges
2
- Can you get this down to the smallest amount of code that demonstrates your problem? – George Mauer Commented Oct 5, 2015 at 16:33
- I've removed the part that was unnecessary – Bellicose Agnostic Commented Oct 5, 2015 at 16:41
4 Answers
Reset to default 4I 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.
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.
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.
just in case it helps someone else, I deleted the node_modules
and did npm install
which fixed the issue for me...
本文标签: javascriptCannot stop Gulp with CtrlC when using gulpnodemon amp gulpwatch togetherStack Overflow
版权声明:本文标题:javascript - Cannot stop Gulp with Ctrl+C when using gulp-nodemon & gulp.watch together - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745194720a2647082.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论