问题
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