大量复制空目录 [英] Gulp copying empty directories

查看:94
本文介绍了大量复制空目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 gulp 版本中,我做了一个任务,它在所有编译,uglifying和缩小发生之后运行。该任务将从 src 中的所有内容复制到尚未被先前任务触及/处理的 dest 目录中。我遇到的小问题是,这会导致 dest 目录中的空目录。



有没有办法告诉 gulp.src glob只包含模式匹配中的文件(如提供'is_file'标志)?



谢谢。

解决方案

p>

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

// ...


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.

解决方案

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

// ...

这篇关于大量复制空目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆