🔧工具(deps): add unplugin-imagemin

unplugin-imagemin +
vite-plugin-imagemin -
This commit is contained in:
2024-03-21 13:18:46 +08:00
parent 3e0dba1b56
commit c0ea4c40b0
15 changed files with 1569 additions and 2461 deletions

View File

@@ -16,7 +16,7 @@ import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'
import autoprefixer from 'autoprefixer'
import viteCompression from 'vite-plugin-compression'
import viteImagemin from 'vite-plugin-imagemin'
import imagemin from 'unplugin-imagemin/vite'
export default defineConfig(({ mode, command }) => {
const env = loadEnv(mode, process.cwd())
@@ -45,33 +45,30 @@ export default defineConfig(({ mode, command }) => {
},
plugins: [
vue(),
viteImagemin({
gifsicle: { // gif图片压缩
optimizationLevel: 3, // 选择1到3之间的优化级别
interlaced: false // 隔行扫描gif进行渐进式渲染
// colors: 2 // 将每个输出GIF中不同颜色的数量减少到num或更少。数字必须介于2和256之间。
imagemin({
// Default mode sharp. support squoosh and sharp
mode: 'sharp',
beforeBundle: true,
// Default configuration options for compressing different pictures
compress: {
jpg: {
quality: 10
},
jpeg: {
quality: 10
},
png: {
quality: 10
},
webp: {
quality: 10
}
},
optipng: { // png
optimizationLevel: 7 // 选择0到7之间的优化级别
},
mozjpeg: {// jpeg
quality: 20 // 压缩质量范围从0(最差)到100(最佳)。
},
pngquant: {// png
quality: [0.8, 0.9], // Min和max是介于0(最差)到1(最佳)之间的数字类似于JPEG。达到或超过最高质量所需的最少量的颜色。如果转换导致质量低于最低质量图像将不会被保存。
speed: 4 // 压缩速度1(强力)到11(最快)
},
svgo: { // svg压缩
plugins: [
{
name: 'removeViewBox'
},
{
name: 'removeEmptyAttrs',
active: false
}
]
}
conversion: [
{ from: 'jpeg', to: 'webp' },
{ from: 'png', to: 'webp' },
{ from: 'JPG', to: 'jpeg' }
]
}),
viteCompression({
verbose: true, // 是否在控制台中输出压缩结果