javascript - Namespaces in gulp -


i have gulpfile constant path object. 1 of fields array. want iterate through , assign different watch react different tasks. when try assing task in loop:

  for(var = 0; < path.php[i].module.length; i++){   gulp.task('sync-'+path.php[i].module, function(){     return gulp.src(path.php[i].in)       .pipe(newer(path.php[i].out))       .pipe(gulp.dest(path.php[i].out));   }); } 

path.php[i] not defined within anonymous function. reason need because if watch whole folder takes time syncing remote, if preprocessed through plugins "gulp-newer" , "gulp-changed".

the problem asynchronous function call inside loop. when callback fires @ it's final value, every callback called same value i.

you need wrap async function call inside new function, ensure value of i intended in each callback. try pattern:

for(var = 0; < path.php[i].module.length; i++){   (function(i){     gulp.task('sync-'+path.php[i].module, function(){       return gulp.src(path.php[i].in)         .pipe(newer(path.php[i].out))         .pipe(gulp.dest(path.php[i].out));     });   })(i); } 

Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -