Gulp JS file automation

Asked

Viewed 19 times

0

My question is the following, I have a file . js in my code that contains a lot of variables that only changes their value.

Example:

var teste = "http://desenvolvimento.com.br";
var teste = "http://producao.com.br";

After running the Gulp I would like to pass some parameter.

Example:

gulp producao
//var teste = "http://desenvolvimento.com.br";
var teste = "http://producao.com.br";

Basically when running the parameter Gulp production or Gulp development he automatically commented on the variables that have the different production notes.

1 answer

0

There is a global that is available inside the file .js that is process. This global has a key process.argv that contains the arguments used to start the command. An example would be:

To gulp producao the process.argv will be ['node', 'caminho/para/gulp.js', 'producao'], if you pass more arguments they will appear in this array.

Thus, in the specific case of the position of producao would be process.argv[2], and what you want will therefore be:

const teste = process.argv[2] === 'producao' ? 'http://producao.com.br' : 'http://desenvolvimento.com.br';

Browser other questions tagged

You are not signed in. Login or sign up in order to post.