简体   繁体   English

如何为所有gulp任务按后缀/扩展名过滤?

[英]how can I filter by suffix/extension for all gulp tasks?

Lets' say I have 20 tasks, all grabbing different file types and performing different things. 假设我有20个任务,所有任务都捕获不同的文件类型并执行不同的操作。

Let's also say I have two environments, development and production. 还要说我有两个环境,开发和生产。

Basically, I want to have a directory structure that goes something like this: 基本上,我想拥有这样的目录结构:

/app
    /product
        product.main.ctrl.js
        product.add.development.ctrl.js

When running in standard development mode, I want the app to compile pretty much all javascript like it normally does. 在标准开发模式下运行时,我希望该应用程序像往常一样编译几乎所有的javascript。

But if I run gulp in production mode, I want to exclude ALL files that have the word development in them. 但是,如果我在生产模式下运行gulp,我想排除其中包含单词development所有文件。

I'm wondering if there's a way to extend ALL tasks at once, rather than just manually adding the exclusion to every single task: 我想知道是否有一种方法可以一次扩展所有任务,而不仅仅是手动将排除项添加到每个任务中:

// default task, I'd like to automatically extend this and exclude depending on evn.
gulp.task('scripts:main', function() {
    return gulp.src('/app/**/*.js', streamFunction);
});
// a working example of what I'd like to do
gulp.task('scripts:main', function() {
    return gulp.src(['/app/**/*.js', '!/app/**/*.development.js'], streamFunction);
});

So above has the default scenario, which I'd like to extend and just by default, else where I exclude dev files, Scenario 2 is something that will work, however I don't want to have to add that into every single task. 因此,以上是默认情况,我想对其进行扩展,并且默认情况下是默认情况,否则,在不包含开发文件的情况下,情况2是可以使用的,但是我不想将其添加到每个任务中。

Is this possible? 这可能吗?

generally you should use config setup to be used in all your tasks 通常,您应该在所有任务中使用配置设置

var config = {
  jsProd : ['/app/**/*.js', '!/app/**/*.development.js'],
  jsDev : ['/app/**/*.js']
}

this makes paths's more reusable... 这使得路径更可重用...

and in your tasks, just use the config variables 在您的任务中,只需使用config变量

gulp.task('scripts:main', function() {
    return gulp.src(config.jsProd, streamFunction);
});

this is as per john papa's style guide 这是根据约翰·帕帕(John papa)的风格指南

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM