Gulp图像优化器(Gulp imagemin)未完全优化
我正在使用gulp来编译我的作品,最近我正在使用gulp imagemin插件来优化图像,它可以工作,但仍然没有完全优化。在Google PageSpeed Insights上显示图像没有完全优化。如何完全优化我的图像?请帮忙。 这是我在gulpfile.js上使用的函数,它可以减少大约2-5%的图像大小,但没有完全优化Gulp图像优化器(Gulp imagemin)未完全优化,gulp,gulp-imagemin,Gulp,Gulp Imagemin,我正在使用gulp来编译我的作品,最近我正在使用gulp imagemin插件来优化图像,它可以工作,但仍然没有完全优化。在Google PageSpeed Insights上显示图像没有完全优化。如何完全优化我的图像?请帮忙。 这是我在gulpfile.js上使用的函数,它可以减少大约2-5%的图像大小,但没有完全优化 gulp.task('imgs', function () { gulp .src(paths.assets.images) .pipe
gulp.task('imgs', function () {
gulp
.src(paths.assets.images)
.pipe(imagemin({
progressive: true,
interlaced: true,
pngquant: true
}))
.pipe(flatten())
.pipe(gulp.dest(paths.build + "/img"));
});
这是谷歌PageSpeed Insights显示图像未优化的屏幕截图。
这个工作得好多了
gulp.task('imgs', function () {
gulp
.src(paths.assets.images)
.pipe(cache(imagemin({ optimizationLevel: 3, progressive: true, interlaced: true })))
.pipe(flatten())
.pipe(gulp.dest(paths.build + "/images"));
});
我刚刚遇到了同样的问题,我决定从默认的imageminjpegtran转到imageminMozjpeg插件 首先,您需要安装imagemin mozjpeg:
npm安装--保存imagemin-mozjpeg
然后将此行添加到gulpfile.js中:
var-imageminMozjpeg=require('imagemin-mozjpeg')代码>
并稍微更改通过管道传输imagemin工具的代码
.pipe(imagemin(
[imageminMozjpeg()],
{verbose: true} // Enabling this will log info on every image passed to gulp-imagemin
))
它还删除图像元数据。结果是惊人的:
将gulp图像与imagemin JPEG重新压缩插件一起使用。它的效果要好得多。文件大小减少70%以上。您只需注意错误处理,因为有时命令会失败。“优化以下图像”链接有何建议?我知道PageSpeed经常建议使用WebP,在这种情况下,gulpImageMin
对您没有帮助。