vue中使用image-webpack-loader

首先打开 webpack.base.confi.js 提示:在这里url-loader 和 image-webpack-loader 不能一起使用,否则会导致图片出不来 接着找到

module: {
          
   
    rules: [
      {
          
   }...
    ]
}

在这里写入,一定要先写 ‘file-loader’ 才能使用 image-webpack-loader’ 有各种配置,可以调整你要压缩后图片的质量 提示:如果使用了 webp 会大大减少体积,但是ios并不支持这个格式,会导致在ios上看不见图片

{
          
   
        test: /.(png|jpe?g|gif|svg)(?.*)?$/,
        use: [
          {
          
   
          loader: file-loader,
          options: {
          
   
              name: [name].[hash:7].[ext],
              outputPath: mobile/img
            }
          },
          {
          
   
            loader: image-webpack-loader,
            options: {
          
   
              mozjpeg: {
          
   
                progressive: true,
                quality: 50
              },
              // optipng.enabled: false will disable optipng
              optipng: {
          
   
                enabled: false,
              },
              pngquant: {
          
   
                quality: [0.5, 0.65],
                speed: 4
              },
              gifsicle: {
          
   
                interlaced: false,
              },
              //ios不支持
              // webp: {
          
   
              //   quality: 100
              // }
            }
          }
        ]
      },
经验分享 程序员 微信小程序 职场和发展