vue2.x版本 和 vue4.x版本 关于图片压缩的配置是不同的
vue2.x版本的配置文件(vue.config.js:没有自行创建),如下
复制代码
1
2
3
4
5
6
7
8
9
10
11
12module.exports = { chainWebpack: config => { config.module .rule('min-image') .test(/.(png|jpe?g|gif)(?.*)?$/) .use('image-webpack-loader') .loader('image-webpack-loader') .options({ disable: process.env.NODE_ENV == 'development' ? true : false })//此处为ture的时 候不会启用压缩处理,目的是为了开发模式下调试速度更快,网上错误示例直接写为disable:true,如果不去查看文档肯定是要被坑的 .end() } }
vue4.x版本的配置文件(vue.config.js:没有自行创建),如下
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17webpackConfig => { webpackConfig.module .rule('images') .test(/.(png|jpe?g|gif|webp)(?.*)?$/) .use('url-loader') .loader(require.resolve('url-loader')) .options({ limit: 4096, fallback: { loader: require.resolve('file-loader'), options: { name: `static/img[name].[hash:8].[ext]` } } }) }
否则会报如下错误:Error: Cannot find module ‘gifsicle’
参考链接:https://www.jianshu.com/p/59a8ebe38255
参考链接:https://blog.csdn.net/qq_27009517/article/details/119248862
百度搜索:vue-cli4 配置 webpack 之用 image-webpack-loader图片压缩处理/优化
最后
以上就是留胡子白开水最近收集整理的关于vue 优化之图片压缩遇到的坑的全部内容,更多相关vue内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复