配列をループする監視タスクがあります。配列内の文字列は、監視するさまざまなファイル パスを取得するために使用されます。それがウォッチ機能の行です。on 関数は、これらのファイル内の変更を探します。変更がある場合、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 は未定義です。配列から文字列の出力を取得する必要がありますが、変数をその位置に渡す方法がわかりません (書き込む必要がある正しいソース ファイルを取得する必要があります)。
こんにちは、ラース