简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM