Ad

Gulp : How To Shorten Destination Folder Of An Unknow Source?

- 1 answer

i recently tried to play with gulp a little bit and i'd like to use it to compile multiple sass files into one. So here's my task :

gulp.task('dev', function () { 
   return gulp
   .src('vendor/proj/**/**/src/assets/scss/dev.scss')
   .pipe(sass())
   .pipe( rename (function (path) {
       path.basename = 'dev';
   }))
   .pipe(gulp.dest('public/css'));
});

It work properly except that i'd like to modify the destination. I'm not sure if this is possible tho, but the compiled css end up in : public/css/folder1/subfolder1/src/assets/scss/dev.css
is there anyway for gulp to put the css into : public/css/folder1/subfolder1/dev.css ?

Thanks a lot !

Ad

Answer

You can use gulp-flatten for this. Your gulp task should look something like:

gulp.task('dev', function () { 
   return gulp
   .src('vendor/proj/**/**/src/assets/scss/dev.scss')
   .pipe(sass())
   .pipe( rename (function (path) {
       path.basename = 'dev';
   }))
   .pipe(flatten({ includeParents: 4} )) // number of parent folders to include
   .pipe(gulp.dest('public/css'));
});

This should put it in folder: public/css/folder1/subfolder1. You can play around with the includeParents option.

Ad
source: stackoverflow.com
Ad