以下は、Gulp ES6 変換タスクです。正常に動作しますが、新しいファイルがキャッチされるように、gulp.watch を gulp-watch プラグインに置き換えようとしています。問題は、コールバックで gulp.watch が行うことを gulp-watch が教えてくれないことです。それについてどうすればよいかわかりません。
これが私の元の作業タスクです。
var gulp = require('gulp'),
rename = require('gulp-rename'),
plumber = require('gulp-plumber'),
gprint = require('gulp-print'),
notify = require('gulp-notify'),
babel = require('gulp-babel');
gulp.task('default', function() {
return gulp.watch('../**/**-es6.js', function(obj){
if (obj.type === 'changed') {
gulp.src(obj.path, { base: './' })
.pipe(plumber({
errorHandler: function (error) { /* elided */ }
}))
.pipe(babel())
.pipe(rename(function (path) {
path.basename = path.basename.replace(/-es6$/, '');
}))
.pipe(gulp.dest(''))
.pipe(gprint(function(filePath){ return "File processed: " + filePath; }));
}
});
});
そして、これがgulp-watchでこれまでに持っているすべてです:
var gulp = require('gulp'),
rename = require('gulp-rename'),
plumber = require('gulp-plumber'),
gprint = require('gulp-print'),
notify = require('gulp-notify'),
babel = require('gulp-babel'),
gWatch = require('gulp-watch');
gulp.task('default', function() {
return gWatch('../**/**-es6.js', function(obj){
console.log('watch event - ', Object.keys(obj).join(','));
console.log('watch event - ', obj.event);
console.log('watch event - ', obj.base);
return;
if (obj.type === 'changed') {
gulp.src(obj.path, { base: './' })
.pipe(plumber({
errorHandler: function (error) { /* elided */ }
}))
.pipe(babel())
.pipe(rename(function (path) {
path.basename = path.basename.replace(/-es6$/, '');
}))
.pipe(gulp.dest(''))
.pipe(gprint(function(filePath){ return "File processed: " + filePath; }));
}
});
});
ロギングの出力は次のとおりです。
イベントを見る - history,cwd,base,stat,_contents,event
イベントを見る - 変更
イベントを見る - ..
以前に持っていた情報を gulp-watch で取得するにはどうすればよいですか、またはタスクのコードを変更してこれを gulp-watch で再び機能させるにはどうすればよいですか?