如果没有包含文件,则不会导致不能按照描述工作 [英] Gulp globbing excluding files then unexcluding not working as described

查看:134
本文介绍了如果没有包含文件,则不会导致不能按照描述工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有文件

client/
  a.js
  bob.js
  bad.js

还有一口气任务

And the gulp task

gulp.task('copy', function() {
  return gulp.src(['client/*.js', '!client/b*.js', 'client/bad.js'])
             .pipe(gulp.dest('public'));
});

然后根据 documentation ,我们应该复制 a.js bad.js 。然而,当我用gulp v3.9.1来运行它时,它只会拷贝 a.js

then according to the documentation we should copy a.js and bad.js. However, when I run this with gulp v3.9.1, it only copies a.js.

这是a已知的错误?有没有办法做到这一点?

Is this a known bug? Is there a way to do this?

推荐答案

这不是一个错误,文档是错误的。最新版本的gulp是 gulp@3.9.1 ,它使用 vinyl-fs@0.3.14 。直到您所指的行为 > vinyl-fs@1.0.0 。

It's not a bug, the documentation is just wrong. The newest version of gulp is gulp@3.9.1 which uses vinyl-fs@0.3.14. The behavior you're referring to wasn't introduced until vinyl-fs@1.0.0.

事实上,在其他地方,gulp文档明确指出该glob命令将成为 gulp@4.0中的一项新功能。 0

In fact, elsewhere the gulp docs explicitly state that glob ordering will be a new feature in gulp@4.0.0:


传递给gulp.src的球将按顺序进行评估,这意味着这是可能的 gulp.src(['*。js','!b * .js','bad.js'])(排除每个以<$ c $开头的JS文件c> b 除了bad.js)

globs passed to gulp.src will be evaluated in order, which means this is possible gulp.src(['*.js', '!b*.js', 'bad.js']) (exclude every JS file that starts with a b except bad.js)

这意味着您可以简单地使用当前的开发版本gulp( gulpjs / gulp#4.0 )并利用新功能。但请注意,gulp 4.x与与gulp 3.x完全不同它涉及到定义任务。

That means you could simply use to the current development version of gulp (gulpjs/gulp#4.0) and take advantage of the new feature. Note however that gulp 4.x is radically different from gulp 3.x when it comes to defining tasks.

一种解决方法是继续使用gulp 3.x作为任务定义,但使用最新版本的 vinyl- fs 创建乙烯流:

One workaround would be to keep using gulp 3.x for tasks definitions, but use the newest version of vinyl-fs to create vinyl streams:

var vinylFs = require('vinyl-fs');

gulp.task('copy', function() {
  return vinylFs.src(['client/*.js', '!client/b*.js', 'client/bad.js'])
    .pipe(vinylFs.dest('public'));
});

如果你不想这样做,你可以使用 merge-stream 将多个数据流组合成一个数据流: p>

And if you don't want to do that you can always use merge-stream to combine multiple streams into one stream:

var merge = require('merge-stream');

gulp.task('copy', function() {
  return merge(gulp.src(['client/*.js', '!client/b*.js']),
               gulp.src(['client/bad.js']))
    .pipe(gulp.dest('public'));
});

这篇关于如果没有包含文件,则不会导致不能按照描述工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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