[英]How to pass parameters in gulp dependencies
I'd like to prepare a different versions of a software by passing a special parameters in gulp task. 我想通过在gulp任务中传递一个特殊参数来准备不同版本的软件。
I've created tasks for css, js, etc. and made one to run then all: 我已经为css,js等创建了任务,然后运行一个然后运行:
gulp.task('compile', ['css', 'twig', 'js', ....]);
How to pass a parameter which will be passed also to the subtasks? 如何传递一个也将传递给子任务的参数? Is there any way to do that? 有没有办法做到这一点?
I'd like to run eg: gulp compile --mode A
and gulp compile --mode B
我想运行eg: gulp compile --mode A
和gulp compile --mode B
Thank you in advance. 先感谢您。
For this, I'm use yargs module 为此,我使用yargs模块
in gulpfile use: 在gulpfile中使用:
var mode = require("yargs").argv.mode;
run task with: 运行任务:
gulp compile -mode A
In your [css/twig/etc] tasks use: 在[css / twig / etc]任务中使用:
gulp.task("css", function(){
var cssSRC = "./src/" + mode + "/*.css";
gulp.src(cssSRC)
...
...
})
I've just found a solution. 我刚刚找到了解决方案。
If I run gulp compile --mode A
, the parameters are pass to dependencies automatically! 如果我运行gulp compile --mode A
,参数会自动传递给依赖项! So, in task js
, I can run require("yargs").argv.mode
as it was written above. 因此,在任务js
,我可以运行require("yargs").argv.mode
,如上所述。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.