Exclude Directory-Pattern in gulp with glob in `gulp.src`

…衆ロ難τιáo~ 提交于 2021-02-19 03:19:11

问题


I am trying to glob all files&directories with gulp.src() expcept all directories starting with the character _ (i.e. _Stuff/). How can I achieve that?


回答1:


Say you have a folder project/src that contains the following files:

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

Then this task in 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'));
});

Will result in the following files being written to project/dist:

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


来源:https://stackoverflow.com/questions/35411576/exclude-directory-pattern-in-gulp-with-glob-in-gulp-src

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