1、npm install imagemin-webpack-plugin
2、const ImageminPlugin = require('imagemin-webpack-plugin').default
3、在webpack.base.conf使用
module.exports = {
plugins: [
// Make sure that the plugin is after any plugins that add images new ImageminPlugin
({
disable: process.env.NODE_ENV !== 'production',
pngquant: {
quality: '95-100'
}
})
] }
参考链接: