Javascript 使用 Gulp 在同一目录中的多个文件扩展名
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28876469/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Multiple file extensions within the same directory using Gulp
提问by mildrenben
So I have a gulpfile.js setup.
所以我有一个 gulpfile.js 设置。
In an images folder I have a few images, some are pngs, some jpgs and some gifs.
在图像文件夹中,我有一些图像,有些是 png,有些是 jpg,有些是 gif。
I want to target all the pngs, jpgs and gifs in the images folder.
我想定位图像文件夹中的所有 png、jpg 和 gif。
I could use **/* to target everything in the folder, but I don't want to, I want it to be specific to the file types.
我可以使用 **/* 来定位文件夹中的所有内容,但我不想,我希望它特定于文件类型。
I could also do this and specify each file type individually:
我也可以这样做并单独指定每个文件类型:
return gulp.src('./images/*.jpg', './images/*.png', './images/*.gif')
But it's a lot of repeating yourself and it seems that there should be an easier way.
但这是很多重复自己,似乎应该有一个更简单的方法。
I'm looking for something like this:
我正在寻找这样的东西:
return gulp.src('./images/*.{png, gif, jpg}')
But alas, the above doesn't work (or at least it only works for the first file type in the list)
但唉,以上不起作用(或者至少它只适用于列表中的第一个文件类型)
Anyone know how to do this?
有人知道怎么做吗?
Thanks
谢谢
回答by mildrenben
Take the spaces away
把空格拿走
return gulp.src('./images/*.{png,gif,jpg}')
回答by eightyfive
This globpattern also worked for me:
return gulp.src('./images/*.+(jpg|jpeg|gif|png)')
Note: Notice the +sign, it doesn't work without it.
注意:注意这个+标志,没有它就不能工作。
Found on minimatch documentation.
在minimatch 文档中找到。

