I have this gulp task:
var abc = {
src: [
'app/**/abc.html',
'app/**/def.html'
],
};
gulp.task('watchHTMLs', function () {
gulp.watch(abc.src, function (file) {
return gulp.src(file.path, { base: process.cwd() })
.pipe(rename({ basename: 'base' }))
.pipe(gulp.dest('./'));
});
});
Is there some way that I can see an output from where I run the gulp script that would show which file is changed?
Something like this:
> cmd.exe /c gulp -b "C:\H\user\user" --color --gulpfile "C:\H\user\user\Gulpfile.js" watchHTMLs
[11:37:29] Using gulpfile C:\H\user\user\Gulpfile.js
[11:37:29] Starting 'watchHTMLs'...
[11:37:29] Finished 'watchHTMLs' after 60 ms
Found file /app/xxx/abc.html Found file /app/yyy/abc.html Found file /app/xxx/def.html
Take a look at gulp-print :
gulp.watch(abc.src, function (file) {
return gulp.src(file.path, { base: process.cwd() })
.pipe(rename({ basename: 'base' }))
.pipe(gulp.dest('./'));
});
gulp.watch
returns an EventEmitter so you can simply listen to changes:
var watcher = gulp.watch(abc.src, 'task');
watcher.on('change', event => {
console.log(event.path);
});
Alternatively, if you want to follow your approach I recommend using gulp-debug
:
var debug = require('gulp-debug');
...
gulp.watch(abc.src, function (file) {
return gulp.src(file.path, { base: process.cwd() })
.pipe(debug())
.pipe(rename({ basename: 'base' }))
.pipe(gulp.dest('./'));
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.