Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gulp copying empty directories

In my gulp build I've made a task that runs after all compiling, uglifying and minification has occurred. This task simply copies everything from the src into the dest directory that hasn't been touched/processed by earlier tasks. The little issue I'm having is that this results in empty directories in the dest directory.

Is there a way to tell the gulp.src glob to only include files in the pattern matching (like providing the 'is_file' flag)?

Thanks.

like image 487
null Avatar asked May 18 '14 07:05

null


2 Answers

Fixed it by adding a filter to the pipeline:

var es = require('event-stream');


var onlyDirs = function(es) {
  return es.map(function(file, cb) {
      if (file.stat.isFile()) {
        return cb(null, file);
      } else {
        return cb();
      }
  });
};
// ...

var s = gulp.src(globs)
        .pipe(onlyDirs(es))
        .pipe(gulp.dest(folders.dest + '/' + module.folder));

// ...
like image 52
null Avatar answered Nov 07 '22 01:11

null


I know I'm late to the party on this one, but for anyone else stumbling upon this question, there is another way to do this that seems pretty elegant in my eyes. I found it in this question

To exclude the empty folders I added { nodir: true } after the glob pattern.

Your general pattern could be such (using the variables from Nick's answer):

gulp.src(globs, { nodir: true })
    .pipe(gulp.dest(folders.dest + '/' + module.folder));

Mine was as follows:

gulp.src(['src/**/*', '!src/scss/**/*.scss', '!src/js/**/*.js'], { nodir: true })
    .pipe(gulp.dest('dev/'));

This selects all the files from the src directory that are not scss or js files, and does not copy any empty folders from those two directories either.

like image 23
absolutholz Avatar answered Nov 07 '22 02:11

absolutholz