I am trying to set up a serve
task that will do the following:
watch
task to watch for any source changes. ( the watch task calls a build
task that builds the app into a "build" folder )So far I've written the following tasks:
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/'
});
}));
The current behavior of the tasks is:
gulp serve
watch
tasks is called and it works as expectedwatch
task. If I change any of the source code, the watch
task will be called.Basically, Nodemon does not start and only the watch
task is working.
I am not able to figure out why the following behavior happens and I want to ask if anyone knows what the problem could be?
Use are running your watch
task in series.
However, the watch
task does not end so nodemon never starts.
Try using gulp.parallel()
instead of gulp.series()
:
gulp.task('serve', gulp.parallel('watch', () => {
return gulpNodemon({
script: './build/index.js',
watch: './build/'
});
}));
Hopefully this should solve your problem.