NullPoiиteя NullPoiиteя - 4 months ago 39
CSS Question

Gulp : How to copy multiple files and keep the folder structure

I am trying to copy file's from one folder to another folder using gulp

gulp.task('move-css',function(){
return gulp.src([
'./source/css/one.css',
'./source/other/css/two.css'

]).pipe(gulp.dest('./public/assets/css/'));
});


above code is copying
one.css
&
two.css
to
public/assets/css
folder

and if i use
gulp.src('./source/css/*.css')
it will copy all css file to
public/assets/css
folder which is not i want

my question is how to select multiple files and keep the folder stracture ?

Answer

To achieve this please specify base

¶ base - Specify the folder relative to the cwd. Default is where the glob begins. This is used to determine the file names when saving in .dest()

gulp.task('move-css',function(){
  return gulp.src([
      './source/css/one.css',
      './source/other/css/two.css'
  ],  {base: './source/'}) 
  .pipe(gulp.dest('./public/assets/'));
});

folder stracture

|-gulpfile.js
|-source
|   |-css
|   |-other
|      |-css
|-public
|   |-assets
Comments