今天小编给大家分享一下vue cli3配置image-webpack-loader报错怎么解决的相关知识点,内容详细,逻辑清晰,相信大部分人都还太了解这方面的知识,所以分享这篇文章给大家参考一下,希望大家阅读完这篇文章后有所收获,下面我们一起来了解一下吧。
vue cli3配置image-webpack-loader
vue cli3配置image-webpack-loader对图片进行压缩优化
安装
npm install image-webpack-loader --save-dev
配置vue.config.js
chainWebpack: config => {
config.plugins.delete('prefetch')
config.plugin('provide').use(webpack.ProvidePlugin, [{
$: 'jquery',
jquery: 'jquery',
jQuery: 'jquery',
'window.jQuery': 'jquery'
}])
config.module.rule('images')
.test(/\.(png|jpe?g|gif|svg)(\?.*)?$/)
.use('image-webpack-loader')
.loader('image-webpack-loader')
.options({ bypassOnDebug: true })
}重启项目打包 ok
使用image-webpack-loader压缩图片报错
安装:请一定使用淘宝镜像cnpm安装,否则安装的包是不完整的
如果之前使用了npm安装,请先卸载再重新安装
$ cnpm install image-webpack-loader --save-dev
配置:vue.config.js
chainWebpack: config => {
const imagesRule = config.module.rule('images')
imagesRule
.use('image-webpack-loader')
.loader('image-webpack-loader')
.options({
bypassOnDebug: true
})
.end()
},
报了莫名其妙的错:
Error: ‘[项目目录]\node_modules\pngquant-bin\vendor\pngquant.exe’ �����ڲ����ⲿ���Ҳ���ǿ����еij���
解决方法:
卸载了再重新安装image-webpack-loader
以上就是“vue cli3配置image-webpack-loader报错怎么解决”这篇文章的所有内容,感谢各位的阅读!相信大家阅读完这篇文章都有很大的收获,小编每天都会为大家更新不同的知识,如果还想学习更多的知识,请关注天达云行业资讯频道。