为什么 gulp.src 不喜欢将完整路径数组传递给文件? [英] Why does gulp.src not like being passed an array of complete paths to files?
问题描述
我正在尝试向 gulp.src 传递我希望它处理的文件数组.这是当前的数组.
I'm attempting to pass gulp.src an array of files that I want it to deal with. This is the array as it stands.
['bower_components/jquery/jquery.js',
'bower_components/superscrollorama/js/greensock/TweenMax.min.js',
'bower_components/superscrollorama/jquery.superscrollorama.js' ]
我发现 gulp.src 似乎不喜欢这样,并且第三个元素没有进入最终目的地.
I'm finding though that gulp.src doesn't seem to like that and the third element doesn't make it through into the end destination.
我发现当我像这样引入一些通配符时一切正常:
I've found that everything works fine when I introduce some wildcard characters like this:
['bower_components/**/jquery.js',
'bower_components/**/js/greensock/TweenMax.min.js',
'bower_components/**/jquery.superscrollorama.js' ]
但是为什么呢?与通配的工作方式有关吗?我用谷歌搜索过,但找不到.
But why? Something to do with the way globbing works? I've googled but can't find out.
也许这不是 globbing 的预期目的,但它应该以这种方式工作对我来说没有意义.有人能解释一下吗?
Maybe this isn't the intended purpose of globbing but it doesn't make sense to me that it should work this way. Can anyone shed some light?
推荐答案
当你传入一个完整路径数组时,每个文件都是独立处理的.globbing 不知道路径的根在哪里(实际上,它根据第一个 glob 进行猜测).因此,每个文件都以它包含的文件夹为根,相对路径为空.
When you pass in an array of full paths, each file is processed independently. The globbing doesn't know where the root of the path is (in fact, it guesses based on the first glob). Therefore, each file is rooted in the folder it contains, and the relative path is empty.
但是,有一个简单的解决方案.将一个带有 base
键的对象作为第二个参数传递给 gulp.src
,一切都会有正确的相对路径:
However, there is an easy solution. Pass an object with the key base
as the second argument to gulp.src
, and everything will have the correct relative path:
return gulp.src(['bower_components/jquery/jquery.js',
'bower_components/superscrollorama/js/greensock/TweenMax.min.js',
'bower_components/superscrollorama/jquery.superscrollorama.js' ],
{base: 'bower_components/'})
.pipe(...);
这篇关于为什么 gulp.src 不喜欢将完整路径数组传递给文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!