Search code examples
gulpgulp-task

Issue in running gulp.series()


I have task to minify the JS files when it's in production

function scriptsToMinify() {
 if(require('yargs').argv.production)
 {
  return gulp.src(src.JSFile)
  .pipe(sourcemaps.init())
  .pipe(ngAnnotate(
    {
      remove: true,
      add: true,
      single_quotes: true
    }))
  .pipe(concat('app.min.js'))
  .pipe(uglify())
  .on('error', function (err) { gutil.log(gutil.colors.red('[Error]'), err.toString()); })
  .pipe(sourcemaps.write())
  .pipe(gulp.dest('public'));
 }
}

When i run locally its not running the depend tasks

gulp.task('inject-scripts', gulp.series(scriptsToMinify, function() {

  var thridPartyScripts = gulp.src(src.thirdPartyJS, { read: false })      
  var scripts = gulp.src([src.app_js, src.directiveJS], { read: false })

  return gulp.src('views/index.html')
.pipe(inject(series(thridPartyScripts, scripts))) // Inject files in an order to run the application without any dependency error.
.pipe(cachebust({ // Add the timestamp to the injected files to avoid cache issue
  type: 'timestamp'
}))
.pipe(gulp.dest('views'));
});

The above task is throwing me below error.

 The following tasks did not complete: default, inject-scripts, scriptsToMinify
 Did you forget to signal async completion?

Solution

  • Change your scriptsToMinify task into

    function scriptsToMinify(done) {
     if(require('yargs').argv.production)
     {
      return gulp.src(src.JSFile)
      .pipe(sourcemaps.init())
      .pipe(ngAnnotate(
        {
          remove: true,
          add: true,
          single_quotes: true
        }))
      .pipe(concat('app.min.js'))
      .pipe(uglify())
      .on('error', function (err) { gutil.log(gutil.colors.red('[Error]'), err.toString()); })
      .pipe(sourcemaps.write())
      .pipe(gulp.dest('public'));
     }
    else{
      done();
    }
    }
    

    You have to return signal when task is finished, so you have to pass callback.