简体   繁体   中英

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.

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.

But if I run gulp in production mode, I want to exclude ALL files that have the word development in them.

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.

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

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

this is as per john papa's style guide

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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