Gulp Watch JS infinite loop

1

I'm a new Gulp student, and I made this watch so if my javascripts files change, it runs build-js . But when I run Gulp, it compiles everything right but it keeps running build-js in an infinite loop. What did I do wrong?

Thank you!

gulp.task('build-js', function (cb) {
            pump([
                gulp.src('lib/*.js'),
                uglify(),
                gulp.dest('dist')
            ],
                cb
            );
        });

gulp.task('watch-js', function () {
    gulp.watch('lib/*.js', ['build-js']);
})

gulp.task('default', ['build-js', 'watch-js']);
    
asked by anonymous 06.12.2017 / 19:31

1 answer

1

The problem may be because you're applying watch to all js , where it fires if any of them changes. Try applying it this way:

gulp.watch(['lib/*.js', '!lib/bundle.js'], ['build-js']);
    
06.12.2017 / 21:40