我有一个循环遍历数组的监视任务。数组中的字符串用于获取要监视的不同文件路径。这就是手表功能的路线。on-function 在这些文件中查找更改。如果有更改,将调用一个新函数,该函数开始编译 sass 文件。
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]);
});
我的问题是里面的参数“groupName”。监视任务对更改做出反应,但 console.log 未定义。我需要从数组中获取字符串的输出,但我不知道如何将变量传递到该位置(需要获取正确的源文件,必须写入)。
问候,拉斯