Gulp Watch JS infinite loop

Asked

Viewed 44 times

1

I’m Gulp’s new student, and I did this watch if my Java files are changed, it build-js. But when I run Gulp, it compiles all right but it keeps running the build-js an infinite loop. What I did 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']);

1 answer

1


The problem may be because you are applying the watch in all the js, where it fires if any of them change. Try applying this way:

gulp.watch(['lib/*.js', '!lib/bundle.js'], ['build-js']);
  • that’s right @Lucas, the problem is that the bundle.js is updated the first time, which triggers the watch in the infinite loop because it is the one that is always changed. But this code !lib/bundle.js didn’t work :(

  • 1

    the way lib/bundle.js this correct @Jackson?

  • Yes. Just to confirm... what you say there is: .js in the briefcase lib, but ignore the file bundle.js in the briefcase lib ? That sounds very right, but you’re not ignoring.. :(

  • That’s right! We can continue on Jackson chat if you want

  • It makes sense that... but unfortunately it doesn’t work here =(

Browser other questions tagged

You are not signed in. Login or sign up in order to post.