-1

I'd like to set up my default task to run with watch task if environment is set production. I can't find solution to make my gulp-if conditional work in a tasks stack. Here's my code:

gulp.task('default', ['styles', 'scripts', 'video' ], function() {
    gulpif(isProduction, gulp.task('watch'));
});
Malyo
  • 1,990
  • 7
  • 28
  • 51

1 Answers1

1

Instead of gulp.task('watch') use gulp.start('watch') although you usually don't want to call a task from another task. A better way would be for you to create a function and call the function instead.

Also note: the gulp.start() method will no longer work with gulp4


Update:

Here is an example of how to use functions within gulp:

 var someFile = require('./someFile.js'); 

 gulp.task('my-custom-task', function () {
   someFile.doSomething('foo', 'bar');
 });

If your function does something asynchronously, it should call a callback at the end, so gulp is able to know when it’s done:

 var someFile = require('./someFile.js'); 

 gulp.task('my-custom-task', function (callback) {
   someFile.doSomething('foo', 'bar', callback);
 });
CriCri
  • 191
  • 1
  • 10
  • Thanks! How do i call specific function in gulp then? – Malyo Oct 28 '16 at 14:29
  • 1
    If by function you mean gulp task the above way would be the way to do so. Otherwise you can create a regular js function and call it how you would usually call a function. Going off of that, to create a function that mimics a gulp task you can just create a js function and use gulp functions within it to maintain functionality. Overall that is the "standard" so you will be easily be able to transition to gulp 4, plus makes separating the gulpfile.js easier. I'll update my answer with more detail once I get on a computer – CriCri Oct 28 '16 at 14:36