为什么 Gulp.src 不喜欢被传递一个完整的文件路径数组?

我正在尝试传递 Gulp.src 一个文件数组,我希望它来处理这些文件。这是目前的数组。

['bower_components/jquery/jquery.js',
'bower_components/superscrollorama/js/greensock/TweenMax.min.js',
'bower_components/superscrollorama/jquery.superscrollorama.js' ]

我发现 Gulp.src 似乎不喜欢这样第三个元素没有到达最终目的地。

我发现,当我引入一些通配符时,一切都很正常:

['bower_components/**/jquery.js',
'bower_components/**/js/greensock/TweenMax.min.js',
'bower_components/**/jquery.superscrollorama.js' ]

但是为什么呢? 是因为地球仪的工作原理吗? 我谷歌过了,但是找不到答案。

也许这不是球状物的预期目的,但是对我来说,它应该以这种方式工作是没有意义的。有人能透露点什么吗?

55484 次浏览

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.

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(...);