任务“复制图像”在首次吞咽运行时复制所有图像文件。然后,任务“监视源文件”监视图像源文件夹,imagesWatcher.on('add)
拦截添加的文件。如何从“ wathcer.on()”回调中调用“复制图像”?
请注意,骆驼任务中的gulp任务名称是不必要的限制。
我知道gulp.run
已在gulp4中删除,但是在这里可能非常方便。
gulp.task('Copy images', () => {
// ...
})
gulp.task('Watch source files, () => {
let imagesWatcher = gulp.watch('src/images/**/*.*');
watcher.on('add', function(path, stats) {
// How to call 'Copy images'?
});
})
答案 0 :(得分:1)
只需将“复制图像”任务变成一个函数(这对gulp4尤其有用),所以:
function Copy_Images() {
return gulp.src(paths.images.src)
.pipe(newer(paths.images.dist))
.pipe(gulp.dest(paths.images.dist));
}
function Watch_Source_Files() {
let imagesWatcher = gulp.watch('src/images/**/*.*');
watcher.on('add', function(path, stats) {
// How to call 'Copy images'?
Copy_Images();
});
}
函数名称就这么简单。不确定在这种情况下“使用别名的解决方案”是什么意思。