【发布时间】:2019-06-22 01:38:00
【问题描述】:
我正在尝试设置一个serve 任务,它将执行以下操作:
- 调用
watch任务以监视任何源更改。 (监视任务调用build任务,将应用构建到“构建”文件夹中) - 使用 Nodemon (gulp-nodemon) 启动应用程序
- 如果发生源更改 - 重建应用程序并重新启动 nodemon
到目前为止,我已经编写了以下任务:
gulp.task('build', gulp.series(['lint'], () => {
del.sync(['./build/**/*.*']);
const tsCompile = gulp.src('./src/**/*.ts')
.pipe(gulpSourcemaps.init())
.pipe(project());
return tsCompile.js.pipe(gulpSourcemaps.write({
sourceRoot: file => path.relative(path.join(file.cwd, file.path), file.base)
}))
.pipe(gulp.dest('./build/'));
}));
gulp.task('watch', gulp.series(['build'], () => {
gulp.watch('./src/**/*.ts', gulp.series(['build']));
}));
gulp.task('serve', gulp.series(['watch'], () => {
return gulpNodemon({
script: './build/index.js',
watch: './build/'
});
}));
任务的当前行为是:
- 我通过输入
gulp serve启动应用程序 -
watch任务被调用并按预期工作 - Nodemon 未启动,进程卡在
watch任务上。如果我更改任何源代码,watch任务将被调用。
基本上,Nodemon 不会启动,只有 watch 任务在工作。
我无法弄清楚为什么会发生以下行为,我想问一下是否有人知道问题可能是什么?
【问题讨论】: