Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gulp watch causes infinite loop

When I run gulp js and make a change to a JS file it gets into an infinite loop when it gets called

Why is calling build from gulp.watch not ever returning?

var gulp = require("gulp");
var browserify = require("browserify");
var reactify = require("reactify");
var source = require("vinyl-source-stream");
var watch = require("gulp-watch");

function _bundle(config){
    return browserify({
        entries: ['./main.js'],
        transform: [reactify]
    }).bundle();
}
gulp.task('default',function(){
  "use strict";
  _bundle()
    .pipe(source('build.js'))
    .pipe(gulp.dest('./'));
});
gulp.task('build',function(){
    "use strict";
    _bundle()
        .pipe(source('build.js'))
        .pipe(gulp.dest('./'));

});



gulp.task('js', function() {

    //gulp.watch(['./*.js'], ['default']);
    gulp.watch(['./*.js'],['build'])
});

//

like image 996
wootscootinboogie Avatar asked Nov 14 '15 17:11

wootscootinboogie


1 Answers

You are specifying watch on all .js files (*.js), and triggering build when any of them change. Build in turn calls _bundle, which is going to result in modifications to main.js Since main.js matches the *.js of watch, build will again be triggered, and now you have a cycle that ensures infinite looping.

like image 116
Chamila Chulatunga Avatar answered Oct 19 '22 03:10

Chamila Chulatunga