在gulp流中显示进度条

时间:2016-04-26 19:12:06

标签: javascript npm gulp

复制某些文件时是否有方法在gulp中显示进度条?

gulp.task('release:step-2', function() {
    return gulp.src(config.copy_src, { dot: true })
        .pipe(gulp.dest(config.path.dest.app));
});

1 个答案:

答案 0 :(得分:0)

以下是使用Gulp {/ 3}}的示例。

var fs = require('fs');
var gulp = require('gulp');
var progress = require('progress-stream');

var filePath = config.copy_src;
var fileSize = fs.statSync(filePath).size;

var progressStream = progress({
  length: fileSize,
  time: 100,
  objectMode: true
});

progressStream.on('progress', function (stats) {
  console.log(Math.round(stats.percentage) + '%');
});

gulp.task('release:step-2', function () {
  return gulp.src(config.copy_surc, { dot: true })
    .pipe(progressStream)
    .pipe(gulp.dest(config.path.dest.app));
});