简体   繁体   English

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

[英]How to execute notify after Gulp copy task is completed?

I have a copy task in my gulpfile.js , and I want notify ( gulp-notify ) after copy is complete, now, when I execute copy task, notify function is called many times. 我的gulpfile.js有一个copy任务,我想在复制完成后通知( gulpfile.js gulp-notify ),现在,当我执行copy任务时, 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!'));
}

In my terminal: 在我的终端中:

[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.

How to can I fix this, to execute only time, after gulp.dest is completed? gulp.dest完成后,如何解决此问题,仅执行时间?

You can use the onLast option : 您可以使用onLast选项

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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