Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Copy only files inside a folder in Gulp

I'm trying to to a gulp task which 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, the name of the directory after gulp-tmp varies, so I had to use ** there.

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

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

like image 715
Casper Avatar asked Sep 03 '14 18:09

Casper


2 Answers

Use gulp-flatten.

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

gulp.src('./gulp-tmp/**/fonts/*')
  .pipe(flatten())
  .pipe(gulp.dest('fonts'));
like image 98
Vadim Avatar answered Oct 20 '22 00:10

Vadim


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:

gulp.src('./src/templates/*.html')
  .pipe(gulp.dest('/build/templates'));
like image 25
Sergey Karasev Avatar answered Oct 19 '22 23:10

Sergey Karasev