Flatten glob down to one directory

后端 未结 3 1617
太阳男子
太阳男子 2020-12-09 08:19

Within Gulp, I am using gulp.src to select every font file from a directory:

gulp.task(\'copy-fonts\', function() {
   gulp.src(\'components/**/         


        
3条回答
  •  囚心锁ツ
    2020-12-09 09:07

    Another option is to simply rewrite the file path inside gulp.dest:

    var path = require('path');
    gulp.task('copy-fonts', function() {
        return gulp.src('components/**/*.{ttf,woff,eof,svg}')
            .pipe(gulp.dest(function(file) {
                file.path = file.base + path.basename(file.path);
                return 'build/fonts';
            }));
    });
    

    You can also use this technique with gulp-changed:

    var path = require('path');
    var changed = require('gulp-changed');
    
    gulp.task('copy-fonts', function() {
      var dest = 'build/fonts';
      return gulp.src('components/**/*.{ttf,woff,eof,svg}')
        .pipe(changed(function(file) {
          file.path = file.base + path.basename(file.path);
          return dest;
        }))
        .pipe(gulp.dest(dest));
    });
    

提交回复
热议问题