仅复制Gulp中文件夹内的文件

时间:2022-12-09 00:27:40

I'm trying to to a gulp task which copies all files inside a folder to another folder

我正在尝试将一个文件夹中的所有文件复制到另一个文件夹的gulp任务

gulp.task('copy-fonts', ['unzip'], function() {
    return gulp.src('./gulp-tmp/**/fonts/*')
        .pipe(gulp.dest('fonts'));
});

The problem is, the name of the directory after gulp-tmp varies, so I had to use ** there.

问题是,gulp-tmp之后的目录名称有所不同,所以我不得不在那里使用**。

So the result ends up like /fonts/[randomFolderName]/fonts/[the files]

结果就像/ fonts / [randomFolderName] / fonts / [文件]一样结果

Where what I want is /fonts/[the files]

我想要的是/ fonts / [文件]

2 个解决方案

#1


19  

Use gulp-flatten.

使用gulp-flatten。

var flatten = require('gulp-flatten');

gulp.src('./gulp-tmp/**/fonts/*')
  .pipe(flatten())
  .pipe(gulp.dest('fonts'));

#2


5  

I use simple code without external libs, for example:

我使用没有外部库的简单代码,例如:

gulp.src('./src/fonts/*.{ttf,woff,eof,svg}')
  .pipe(gulp.dest('/build/fonts'));

or only html files:

或只有html文件:

gulp.src('./src/templates/*.html')
  .pipe(gulp.dest('/build/templates'));

#1


19  

Use gulp-flatten.

使用gulp-flatten。

var flatten = require('gulp-flatten');

gulp.src('./gulp-tmp/**/fonts/*')
  .pipe(flatten())
  .pipe(gulp.dest('fonts'));

#2


5  

I use simple code without external libs, for example:

我使用没有外部库的简单代码,例如:

gulp.src('./src/fonts/*.{ttf,woff,eof,svg}')
  .pipe(gulp.dest('/build/fonts'));

or only html files:

或只有html文件:

gulp.src('./src/templates/*.html')
  .pipe(gulp.dest('/build/templates'));