如何在Gulp复制任务完成后执行通知?

时间:2016-05-04 16:26:31

标签: javascript gulp

我的copy中有一个gulpfile.js任务,我希望在复制完成后通知(gulp-notify),现在,当我执行copy任务时,{{ 1}}函数被多次调用。

notify

在我的终端:

const notify = require('gulp-notify')
    , gulp = require('gulp')
    ;

gulp.task('copy', copyTask);

function copyTask() {
    return gulp.src('src/**/*')
        .pipe(gulp.dest('dest'))
        .pipe(notify('Copy task is completed!'));
}

如何解决这个问题,在[13:23:40] Starting 'copy'... [13:23:40] gulp-notify: [Gulp notification] Copy task is completed. [13:23:40] gulp-notify: [Gulp notification] Copy task is completed. [13:23:40] gulp-notify: [Gulp notification] Copy task is completed. [13:23:40] gulp-notify: [Gulp notification] Copy task is completed. [13:23:40] gulp-notify: [Gulp notification] Copy task is completed. [13:23:40] gulp-notify: [Gulp notification] Copy task is completed. [13:23:40] gulp-notify: [Gulp notification] Copy task is completed. [13:23:40] gulp-notify: [Gulp notification] Copy task is completed. [13:23:40] gulp-notify: [Gulp notification] Copy task is completed. [13:23:40] gulp-notify: [Gulp notification] Copy task is completed. [13:23:40] gulp-notify: [Gulp notification] Copy task is completed. [13:23:40] gulp-notify: [Gulp notification] Copy task is completed. [13:23:40] gulp-notify: [Gulp notification] Copy task is completed. [13:23:40] gulp-notify: [Gulp notification] Copy task is completed. [13:23:40] gulp-notify: [Gulp notification] Copy task is completed. [13:23:40] gulp-notify: [Gulp notification] Copy task is completed. 完成后只执行时间?

1 个答案:

答案 0 :(得分:2)

您可以使用onLast option

function copyTask() {
  return gulp.src('src/**/*')
    .pipe(gulp.dest('dest'))
    .pipe(notify({
      message: 'Copy task is completed!',
      onLast: true
    }));
}