在* one * gulp任务中使用yargs将它应用于* all *任务:为什么? 怎么修?

我有一个UI项目,基于generator-gulp-angular的自动化工作stream程。 我添加了gulp-ng-config ,以便根据环境variables执行不同的构build。 我使用包裹“yargs”来提取环境标志,并使其可用于该任务。 但是,即使这个任务应该被封装,我使用yargs来创build需求,现在在我的整个项目中,所有的gulp任务都是活跃的。

这里是ngconfig任务:

 var gulp = require('gulp'); var path = require('path'); var conf = require('./conf'); var gulpNgConfig = require('gulp-ng-config'); var argv = require('yargs') .usage('This `build` or `serve` task includes an ngConfig task, whose requirements have not been met via arguments. \n LONG USAGE: <command> --environment <"production" or "sit" or "local">.\n SHORT USAGE <command> -e <"production" or "sit" or "local">') .epilogue('For more information, see the iJoin client README.') .demand(['e']) .alias('e', 'environment') .argv; gulp.task('ngconfig', function() { // default config: var thisConfig = { environment: argv.environment, wrap: "(function () { \n 'use strict'; \n return <%= module %> \n })();" }; gulp.src('gulp/server-config.json') .pipe(gulpNgConfig('ijoin.apiConfig', thisConfig)) .pipe(gulp.dest(path.join(conf.paths.src, '/app/prebuild'))); }); 

这是作为build一部分调用,在这里:

 gulp.task('build', ['ngconfig', 'html', 'fonts', 'other']); 

当我们想用我们的环境variables执行一个构build时,我们执行

 gulp build -e local 

而且,这一切工作正常! 但它正在蔓延到我的其他任务。 例如,当我启动我的本地API模拟服务器,与:

 gulp stubby 

它抱怨我没有包括必要的参数:

 This `build` or `serve` task includes an ngConfig task, whose requirements have not been met via arguments. LONG USAGE: <command> --environment <"production" or "sit" or "local">. SHORT USAGE <command> -e <"production" or "sit" or "local"> Options: -e, --environment [required] For more information, see the iJoin client README. Missing required arguments: e 

但我的意图是,这些必要的参数只需要在ngconfig任务。 ( ngconfig绝对不是stubby的依赖。)那么,为什么这个溢出到其他任务,我该如何解决呢?

因为argvvariables是在ngconfig范围之外添加的,所以也会影响其他的执行。

请在ngconfig任务中移动它