Answer the question
In order to leave comments, you need to log in
Which gulp plugin can accept variable values from the console?
For example, we write in the console like this:
win/linux/[email protected]$ gulp taskname a=100 b=hello
And in the gulpfile.js task, we were able to fill the corresponding variables with these values. Thank you!
Thanks for the replies, the solution is:
gulpfile.js:
gulp.task('arg', function ()
{
var args = require('yargs').argv;
if(args.a) {
console.log('a = %d ', args.a);
}
else {
console.log('variable "a" not found');
}
})
console:
gulp arg -a=111
[17:35:00] Using gulpfile D:\gulp\gulpfile .js
[17:35:00] Starting 'arg'...
a = 111
[17:35:00] Finished 'arg' after 111 ms
-------------------------------------------------- ---------------------------------
It was also noticed that when using the gulp-load plugin -plugins
nothing works:
var gulp = require('gulp'), glp = require('gulp-load-plugins'), $ = glp();
gulp.task('arg', function ()
{
var args = $.yargs.argv;
if(args.a)
{
console.log('a = %d', args.a);
}
else
{
console.log ('variable "a" not found');
}
});
> gulp arg -a=111
[17:38:48] Using gulpfile D:\gulp\gulpfile.js
[17:38:48] Starting 'arg'...
[17:38:48] 'arg' errored after 788µs
[17:38:48] TypeError: Cannot read property 'argv' of undefined
Answer the question
In order to leave comments, you need to log in
With Yargs . A similar question was once discussed on StackOverflow
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question