How to pass parameters in gulp dependencies

I would like to prepare different versions of the software by passing special parameters in the gulp task.

I created tasks for css, js, etc. and made one to run everything:

gulp.task('compile', ['css', 'twig', 'js', ....]);

How to pass a parameter that will also be passed to subtasks? Is there any way to do this?

I would like to run, for example: gulp compile --mode A as well as gulp compile --mode B

Thanks in advance.

+5
source share
2 answers

For this I use yargs module

in gulpfile use:

 var mode = require("yargs").argv.mode; 

complete the task with

 gulp compile -mode A 

For your tasks [css / twig / etc] use:

 gulp.task("css", function(){ var cssSRC = "./src/" + mode + "/*.css"; gulp.src(cssSRC) ... ... }) 
+1
source

I just found a solution.

If I run gulp compile --mode A , the parameters automatically go to the dependencies! So, in the js task, I can run require("yargs").argv.mode , as described above.

-2
source

All Articles