How to pass gulp.watch () to a channel?

I have a simple default task for transfusion of modified js files:

    gulp.task('default', function() {
        // watch for JS changes
        gulp.watch(base + 'javascripts/**/*.js', function() {
            gulp.run('jshint');
        });
    });

The problem is that the task jshintreturns the files again:

    gulp.task('jshint', function() {
        gulp.src([base + 'javascripts/*.js'])
            .pipe(jshint())
            .pipe(jshint.reporter('default'));
    });

What happens is that all the files are lithiated, not just changed.

Is there a way to transfer only modified files to jshint?

+4
source share
1 answer

According to @OverZealous, I found this approach to work with gulp-watch:

gulp.task('default', function() {
    gulp.src(base + 'javascripts/**/*.js', { read: false })
        .pipe(watch())
        .pipe(jshint())
        .pipe(jshint.reporter('default'));
});

{ read: false }You must avoid involving all files at startup. This solution does not contain files that did not exist on first launch.

+2
source

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


All Articles