我在 gulp 上有一个简单的手表,当其中一个文件发生更改时,它会重新加载所有 js 文件(使用 gulp-connect),但是每当相关任务运行时,我都会收到以下错误:
[15:14:35] Starting 'livereload:js'...
events.js:160
throw er; // Unhandled 'error' event
^
Error: write after end
at ServerResponse.OutgoingMessage.write (_http_outgoing.js:439:15)
at ServerResponse.res.inject.res.write (C:\dev\test-livereload\node_modules\connect-livereload\index.js:115:37)
at ReadStream.ondata (_stream_readable.js:555:20)
at emitOne (events.js:96:13)
at ReadStream.emit (events.js:188:7)
at readableAddChunk (_stream_readable.js:176:18)
at ReadStream.Readable.push (_stream_readable.js:134:10)
at onread (fs.js:1984:12)
at FSReqWrap.wrapper [as oncomplete] (fs.js:681:17)
这是代码:
gulp.task('livereload:js', function() {
return gulp.src([paths.APP_ROOT + '/**/*.js'])
//.pipe(wait(2000)) // if I add a small wait it doesn't crash as often
.pipe(connect.reload());
});
gulp.task('run-watch', function() {
gulp.watch([paths.APP_ROOT + '/**/*.js'], ['livereload:js']);
});
我有一个类似的任务,检查 scss 文件中的更改并在重新加载之前编译它们工作正常。