2

元のサイズ、縮小されたサイズ、および変数へのスペース節約の圧縮値を取得しようとしました。これまでのところ、私が見つけたプラグインだけが、このデータをコンソールでのみ表示しています。

ここに画像の説明を入力

コンソールに表示される同じデータを変数に取得する簡単な方法はありますか?

gulp-imagemin の私のコード:

    gulp.task("compress-images", () =>
    Promise.all([
      new Promise((resolve, reject) => {
        gulp
          .src("./uploads/*")
          .pipe(printSpaceSavings.init())
          .pipe(
            imagemin([
              imageminMozjpeg({ quality: 75 }),
              imagemin.svgo({
                plugins: [{ removeViewBox: true }, { cleanupIDs: false }]
              })
            ])
          )
          .pipe(
            tap(function(file) {
              file.contents = Buffer.from(
                yourFunction(file.contents.toString())
              );
              function yourFunction(input) {
                return input.toString(); // Possible to get this data to a variable?
              }
            })
          )
          .on("error", reject)
          .pipe(printSpaceSavings.print()) //consoleLog
          .pipe(gulp.dest("./compressed"))
          .on("end", resolve);
      })
    ])
  );
4

1 に答える 1