在 vue 项目中除了可以在 webpack.base.conf.js 中 url-loader 中设置 limit 大小来对图片处理,对小于 limit 的图片转化为 base64 格式,其余的不做操作。所以对有些较大的图片资源,在请求资源的时候,加载会很慢,我们可以用 image-webpack-loader来压缩图片:

(1)首先,安装 image-webpack-loader  :

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

(2)然后,在 webpack.base.conf.js  中进行配置:

{  test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,  use:[    {    loader: 'url-loader',    options: {      limit: 10000,      name: utils.assetsPath('img/[name].[hash:7].[ext]')      }    },    {      loader: 'image-webpack-loader',      options: {        bypassOnDebug: true,      }    }  ]}

相关文章:

  • 2022-01-17
  • 2021-05-01
  • 2022-12-23
  • 2021-11-23
  • 2021-08-02
  • 2021-07-19
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-12-22
  • 2021-11-02
  • 2021-09-28
  • 2022-01-13
  • 2022-02-11
  • 2023-03-09
  • 2021-10-19
相关资源
相似解决方案