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'])
});
//
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With