I have a watch task that goes through an array. The lines inside the array are used to get different file paths for viewing. This is a line with a watch function. The on-function function looks for changes inside these files. If there is a change, a new function is called that starts compiling the sass files.
function setWatchPipe(groupName) {
gulp
.watch(watchStyles[groupName])
.on('change', function(e, groupName) {
console.log(groupName);
return gulp.src(appFiles.styles.src + groupName)
.pipe($.plumber({ errorHandler: function (error) {}}))
.pipe($.rubySass({
style: sassStyle,
compass: true,
noCache: true
}))
.pipe(isProduction ? $.combineMediaQueries({ log: true }) : _.noop())
.pipe(isProduction ? $.minifyCss({ keepSpecialComments: 1 }) : _.noop())
.pipe($.plumber.stop())
.pipe(gulp.dest(paths.styles.dest))
.pipe($.size({
showFiles: true
}));
});
}
var watchArray = ['base', 'front'];
gulp.task('watch', ['build-styles'], function() {
for(var i = 0; i < watchArray.length; i++)
setWatchPipe(watchArray[i]);
});
My problem is the "groupName" parameter inside. The watch task is responsive, but console.log is undefined. I need to get the output of strings from an array, but I don’t know how to pass the variable to this position (I needed to get the correct source file that needs to be written).
Hello lars