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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 02:32:02  来源:igfitidea点击:

Multiple file extensions within the same directory using Gulp

javascriptgulp

提问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:

这种glob模式也对我有用

return gulp.src('./images/*.+(jpg|jpeg|gif|png)')

Note: Notice the +sign, it doesn't work without it.

注意:注意这个+标志,没有它就不能工作。

Found on minimatch documentation.

minimatch 文档中找到。