Given the following gulp tasks I'm able to successfully start the gulp, webpack and nodemon process, but the webpack tasks are open ended, so they will continue to fire the completion handler when their watch / compile cycle is complete.
鉴于以下gulp任务,我能够成功启动gulp,webpack和nodemon进程,但webpack任务是开放式的,因此当他们的监视/编译周期完成时,他们将继续触发完成处理程序。
The server task depends on the client task output, so I need these operations to be synchronous, hence the done
服务器任务取决于客户端任务输出,因此我需要这些操作是同步的,因此完成
function onBuild(done) {
return function(err, stats) {
if(err) {
gutil.log('Error', err);
if(done) {
done();
}
} else {
Object.keys(stats.compilation.assets).forEach(function(key){
gutil.log('Webpack: output ', gutil.colors.green(key));
});
gutil.log('Webpack: ', gutil.colors.blue('finished ', stats.compilation.name));
if(done) {
done();
}
}
}
}
//dev watch
gulp.task('webpack-client-watch', function(done) {
webpack(devConfig[0]).watch(100, function(err, stats) {
onBuild(done)(err, stats);
});
});
gulp.task('webpack-server-watch', function(done) {
webpack(devConfig[1]).watch(100, function(err, stats) {
onBuild(done)(err, stats);
nodemon.restart();
});
});
gulp.task('webpack-watch',function(callback) {
runSequence(
'webpack-client-watch',
'webpack-server-watch',
callback
);
});
gulp.task('nodemon', ['webpack-watch'], function() {
nodemon({
script: path.join('server/dist/index.js'),
//ignore everything
ignore: ['*'],
watch: ['foo/'],
ext: 'noop'
}).on('restart', function() {
gutil.log(gutil.colors.cyan('Restarted'));
});
});
When I change a file, the watcher does its thing and gulp complains about the callback being called yet again.
当我改变一个文件时,观察者做了它的事情,并且gulp抱怨再次调用回调。
[15:00:25] Error: task completion callback called too many times
[15:00:25]错误:任务完成回调调用次数过多
I've looked at this, but not sure if its applicable.
我看过这个,但不确定它是否适用。
Why might I be getting "task completion callback called too many times" in gulp?
为什么我会在gulp中获得“多次调用任务完成回调”?
Basically, I just want this to work synchronously and continuously without error.
基本上,我只是想让它同步并连续工作而不会出错。
gulp nodemon
2 个解决方案
#1
8
This solved it for me: Just don't call the callback
parameter in your webpack-watch
task. Leave it out completely.
After that, the watcher works fine and fast without complaining.
这为我解决了这个问题:只是不要在webpack-watch任务中调用callback参数。完全不要理会。在那之后,观察者工作得很好而且没有抱怨。
#2
0
If public folder exists in your application. Please remove and re-run, after you can see this issue resolved.
如果您的应用程序中存在公用文件夹在您看到此问题已解决后,请删除并重新运行。
#1
8
This solved it for me: Just don't call the callback
parameter in your webpack-watch
task. Leave it out completely.
After that, the watcher works fine and fast without complaining.
这为我解决了这个问题:只是不要在webpack-watch任务中调用callback参数。完全不要理会。在那之后,观察者工作得很好而且没有抱怨。
#2
0
If public folder exists in your application. Please remove and re-run, after you can see this issue resolved.
如果您的应用程序中存在公用文件夹在您看到此问题已解决后,请删除并重新运行。