Gulp watch multiple folders

In the project during development I want

  • Take a look and recompile the server-side code using Babel (since I want to use "ES6" in Parse)
  • Watch and recompile client-side code with Browserify / Watchify

How can i do this? I could write 2 hourly assignments, but I would need to open 2 terminal windows to see both of these directories. Isit can this be done in 1 gulp task? How to do 2 tasks?

+4
source share
1 answer

Yes, you can do what you want.

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

You can also add more to the array if you want to see other types of files. IE:'directoryA/**/*.html'

, , , :

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

gulp Browerify Babelify.

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
});

, , . , .

+19

Source: https://habr.com/ru/post/1622158/


All Articles