使用`gulp.src`中的glob排除gulp中的目录模式

时间:2016-02-15 14:10:57

标签: path gulp glob

我正在尝试使用gulp.src()覆盖所有文件和目录,以及以字符_开头的所有目录(即_Stuff/)。我怎样才能做到这一点?

1 个答案:

答案 0 :(得分:8)

假设您有一个包含以下文件的文件夹project/src

file.txt
folder
folder/file.txt
folder/_subfolder
folder/_subfolder/file.txt
folder/subfolder
folder/subfolder/file.txt
_folder
_folder/file.txt
_folder/_subfolder
_folder/_subfolder/file.txt
_folder/subfolder
_folder/subfolder/file.txt

然后在project/Gulpfile.js中执行此任务:

gulp.task('default', function() {
  return gulp.src([
      'src/**/*',         //select all files
      '!src/**/_*/',      //exclude folders starting with '_'
      '!src/**/_*/**/*',  //exclude files/subfolders in folders starting with '_'
    ])
    .pipe(gulp.dest('dist'));
});

将导致以下文件写入project/dist

file.txt
folder
folder/file.txt
folder/subfolder
folder/subfolder/file.txt