K
K
KG2019-10-16 01:14:31
gulp.js
KG, 2019-10-16 01:14:31

How to make a dynamic gulp task?

Good afternoon, I can’t solve the following problem with the assembly of the gulp project in any way.
There is a gallp task that takes the desired file from the folder by name. The name is already in the variable.
For example, like this:

var siteName = 'site-name';
gulp.task('config-js', function() {
  return gulp.src('./configs/'+siteName+'.js')
  .pipe(gp.concat('config.js'))
  .pipe(gulp.dest(distDir + '/js/'))
});

Everything works okay, you just need to go around to edit the variable with your hands so that the gallp takes the desired file. There was an idea to make some dynamic task. You write, for example, gulp:site-name and gulp does all the tasks as usual, and it somehow throws the name after : site-name into the config-js task in place of the variable. That is, I write gulp:site2 and the config-js task looks for the site2.js file and then the rest of the tasks are launched. Is it really possible to implement this at all?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey delphinpro, 2019-10-16
@pwnography

Of course you can. Everything is possible.

gulp.task('demo', function(cb){
  console.log(process.argv.splice(3));
  cb();
});

D:\dev\demo>gulp demo --file2
[02:22:08] Using gulpfile D:\dev\demo\gulpfile.js
[02:22:08] Starting 'demo'...
[ '--file2' ]
[02:22:08] Finished 'demo' after 13 ms

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question