Gulp 观看多个文件夹

Gulp watch multiple folders

在一个项目中,在开发过程中,我想

我该怎么做?我可以写 2 个监视任务,但我必须打开 2 个终端 windows 才能监视这两个目录。是否可以在 1 gulp 任务中完成?比如做2个任务?

是的,你可以随心所欲。

gulp.task('watch', function() {
    gulp.watch(['directoryA/**/*.js', 'directoryB/js/**/*.js'], ['task']);
});

如果您想观看其他文件类型,您也可以在数组中添加更多。即:'directoryA/**/*.html'

如果您希望他们 运行 您提到的两项不同的任务,请将其更改为:

gulp.task('watch', function() {
    gulp.watch(['directoryA/**/*.js'], ['taskA']);
    gulp.watch(['directoryB/**/*.js'], ['taskB']);
});

我使用 Browerify and Babelify.

的示例 gulp 任务
gulp.task('taskA', function() {
    return browserify('path/to/file.js')
    .transform('babelify')
    .bundle()
    .pipe(source('file.js')) // this is the output file name
    .pipe(gulp.dest('destination/directory/')); // and this is where it ends up
});

编辑

我刚刚意识到我没有解决您是否需要一项或两项任务。技术上你可以做任何一个,但最好的方法是有两个单独的任务。