为什么 gulp.src 不喜欢传递文件的完整路径数组? [英] Why does gulp.src not like being passed an array of complete paths to files?

查看:42
本文介绍了为什么 gulp.src 不喜欢传递文件的完整路径数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试向 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.

也许这不是通配符的预期目的,但它应该以这种方式工作对我来说没有意义.任何人都可以透露一些信息吗?

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆