Gulp copying empty directories

大憨熊 提交于 2019-12-05 03:27:03
null

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));

// ...
absolutholz

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!