如何简化此任务?
const merge = require('merge-stream')
gulp.task('templates', ()=>{
return merge(
gulp.src('./src/dashboard/views/**/*').pipe(gulp.dest('public/views/dashboard')),
gulp.src('./src/core/views/**/*').pipe(gulp.dest('public/views/core')),
gulp.src('./src/auth/views/**/*').pipe(gulp.dest('public/views/auth')),
gulp.src('./src/templates/views/**/*').pipe(gulp.dest('public/views/templates'))
)
})
答案 0 :(得分:0)
您需要使用public/views/
作为目标路径,并删除源路径中的/views
部分:
您可以使用gulp-rename
执行此操作:
var rename = require('gulp-rename');
gulp.task('templates', ()=>{
return gulp.src('./src/*/views/**/*')
.pipe(rename(function(file) {
file.dirname = file.dirname.replace(/\/views/, '');
}))
.pipe(gulp.dest('public/views/'));
});
还有gulp-regex-rename
更短(从未使用过那个,所以我不能担保):
var rename = require('gulp-regex-rename');
gulp.task('default', ()=>{
return gulp.src('./src/*/views/**/*')
.pipe(rename(/\/views/, ''))
.pipe(gulp.dest('public/views/'));
});