Copy only files inside a folder in Gulp

I am trying to execute a gulp task that copies all files inside a folder to another folder

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

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

Thus, the result ends as /fonts/[randomFolderName]/fonts/[the files]

Where I want /fonts/[the files]

+7
javascript gulp
source share
2 answers

Use gulp-flatten .

 var flatten = require('gulp-flatten'); gulp.src('./gulp-tmp/**/fonts/*') .pipe(flatten()) .pipe(gulp.dest('fonts')); 
+18
source share

I use simple code without external libraries, for example:

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

or just html files:

 gulp.src('./src/templates/*.html') .pipe(gulp.dest('/build/templates')); 
+5
source share

All Articles