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

查看:464
本文介绍了为什么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' ]

但是,为什么?事做通配符的工作方式?我GOOGLE了,但无法找到答案。

But why? Something to do with the way globbing works? I've googled but can't find out.

很抱歉,如果这是一个真正的noob问题。也许这不是通配的预期目的,但它没有任何意义,我认为它应该以这种方式工作。任何人都可以提供一些线索?

Sorry if this is a real noob question. 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?

推荐答案

在你的完整路径的传递数组,每个文件被独立处理。该通配不知道的路径的根是(事实上,它的猜测基于第一水珠)。因此,每个文件植根它包含的文件夹中,相对路径是空的。

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.

不过,有一个简单的解决方案。传递一个对象与键作为第二个参数 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天全站免登陆