我不知道为什么我要
你忘了发出异步完成信号了吗?
这是我的装置:
gulp.task('compile-ts', () => {
return tsProject.src(config.files.src.ts)
.pipe($.tap((file, t) => {
logVerbose('Compiling "' + file.path + "'");
}))
.pipe($.sourcemaps.init())
.pipe($.typescript(tsProject))
.pipe($.sourcemaps.write('./'))
.pipe($.chmod(755))
.pipe(gulp.dest(config.dist));
});
gulp.task('copy-assets', () => {
return gulp.src(config.files.src.css_html_js, { base: config.src })
.pipe($.tap((file, t) => {
logVerbose('Copying "' + getFileName(file.path) + "'");
}))
.pipe($.chmod(755))
.pipe(gulp.dest(config.dist));
});
gulp.task('browser-sync', (done) => {
browserSync.init({
"port": 3000,
"startPath": "dist/index.html",
"browser": "chrome",
"logLevel": "silent",
"server": {
"middleware": {
"0": null
}
}
}, done);
process.on('exit', () => {
browserSync.exit();
});
})
gulp.task('watch', gulp.parallel(() => {
gulp.watch(config.files.ts, gulp.series('compile-ts'));
}, () => {
gulp.watch(config.files.css_html_js, gulp.series('copy-assets'));
}));
gulp.task('serve-dist', gulp.parallel('watch', 'browser-sync'));根据堆栈跟踪,违规行是
gulp.watch(config.files.ts, gulp.series('compile-ts'));在watch任务中。任务compile-ts正在工作,它返回一个流,该流应该足够信号完成。但我为什么要犯这个错误呢?
我是gulp@4.0.0-alpha.2。
编辑:
将watch任务更改为
gulp.task('watch', (done) => {
gulp.watch(config.files.css_html_js, gulp.series('copy-assets'));
gulp.watch(config.files.ts, gulp.series('compile-ts'));
done();
});我不再有任何错误了,但是任务在4ms内就完成了,什么也不做。如果删除done部件,则再次得到相同的错误。
EDIT2:为了找出问题,我把任务分成了几个部分,
gulp.task('watch-ts', () => {
return gulp.watch(config.files.ts, gulp.series('compile-ts'));
});
gulp.task('watch-assets', () => {
return gulp.watch(config.files.css_html_js, gulp.series('copy-assets'));
});
gulp.task('watch', gulp.parallel('watch-ts', 'watch-assets'));现在,watch-ts和watch-assets都给了我这个错误消息。据我所知,其中任何一个都会返回一条流。
发布于 2016-07-13 15:55:14
您的总是需要在中发出异步完成的信号--组成任务的每个函数。不只是那些异步的。不仅仅是那些使用流的人。如果没有在函数中返回流,则仍然需要以某种方式(通常通过调用回调)发出异步完成的信号。
因此,您的第一次编辑已经正确:
gulp.task('watch', (done) => {
gulp.watch(config.files.css_html_js, gulp.series('copy-assets'));
gulp.watch(config.files.ts, gulp.series('compile-ts'));
done();
});在这里调用回调,确保gulp知道您的watch任务已经成功完成。在这种情况下,“完成成功”意味着您的任务已经启动了这两个手表。即使在watch作业完成后,这两个手表也将继续运行。因此,watch任务在4ms之后终止这一事实没有什么问题。
但是,启动手表而不是是否会自动触发侦听器函数的执行。你必须先修改一个被监视的文件。或者,您可以将 option传递给gulp.watch(),它将在手表第一次启动时触发它:
gulp.task('watch', (done) => {
gulp.watch(config.files.css_html_js, {ignoreInitial:false}, gulp.series('copy-assets'));
gulp.watch(config.files.ts, {ignoreInitial:false}, gulp.series('compile-ts'));
done();
});https://stackoverflow.com/questions/38353152
复制相似问题