webpack图片压缩

Install
$ npm install image-webpack-loader --save-dev

配置
在webpack.config.js文件中设置合理的压缩质量范围,避免过度失真

rules: [{
     
  test: /\.(gif|png|jpe?g|svg)$/i,
  use: [
    'file-loader',
    {
     
      loader: 'image-webpack-loader',
      options: {
     
        mozjpeg: {
     
          progressive: true,
          quality: 65
        },
        // optipng.enabled: false will disable optipng
        optipng: {
     
          enabled: false,
        },
        pngquant: {
     
          quality: [0.65, 0.90],
          speed: 4
        },
        gifsicle: {
     
          interlaced: false,
        },
        // the webp option will enable WEBP
        webp: {
     
          quality: 75
        }
      }
    },
  ],
}]

你可能感兴趣的:(webpack)