gpt4 book ai didi

javascript - gulp-imagemin 如何将压缩值获取到变量

转载 作者:太空宇宙 更新时间:2023-11-03 22:23:38 24 4
gpt4 key购买 nike

我试图获取以下压缩值:原始大小、缩小后的大小和节省的空间到变量中。到目前为止,我发现的只有插件仅在控制台中显示此数据。

enter image description here

是否有任何简单的方法可以将控制台中显示的相同数据获取到变量?

我的 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);
})
])
);

最佳答案

我不确定 gulp 任务完成后变量的范围是否会保留(因为我不知道你的代码是如何构造的),所以我可以给你的一个建议是将值写入文件并从中检索它以在前端显示。

关于javascript - gulp-imagemin 如何将压缩值获取到变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50209056/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com