多个gulp src

时间:2017-01-02 02:55:46

标签: gulp

如何简化此任务?

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'))
    )
})

1 个答案:

答案 0 :(得分:0)

您需要使用public/views/作为目标路径,并删除源路径中的/views部分:

  • public / views / + dashboard / views = public / views / dashboard
  • public / views / + core / views = public / views / core
  • public / views / + auth / views = public / auth / auth
  • public / views / + templates / views = public / auth / templates

您可以使用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/'));
});