2017-02-28 35 views
0

我正在使用gulp編譯我的工作,最近我使用gulp-imagemin插件來優化圖像,並且其工作仍未完全優化。在Google PageSpeed Insights中顯示圖像沒有完全優化。如何充分優化我的圖像?請幫忙。 這是我在我的gulpfile.js上使用的功能,它減少了約2-5%的圖像大小,但並未完全優化。gulp圖像優化器(gulp-imagemin)未完全優化

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")); 
}); 

下面是Google PageSpeed Insights顯示圖片未優化的截圖。 screenshot

+0

什麼是「優化以下圖像」鏈接推薦?我知道PageSpeed經常推薦使用WebP,在這種情況下'gulp-imagemin'不會幫助你。 –

回答

0

這一個工作更好..

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")); 
}); 
1

我剛剛面臨着同樣的麻煩,我決定從默認imagemin-jpegtranimageminMozjpeg插件移動。

首先,你需要安裝imagemin-mozjpeg:

npm install --save 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 working process log