52 lines
903 B
TypeScript
52 lines
903 B
TypeScript
|
|
import { ViteImageOptimizer } from 'vite-plugin-image-optimizer'
|
||
|
|
|
||
|
|
export function setupImageOptimizer() {
|
||
|
|
return ViteImageOptimizer({
|
||
|
|
logStats: true,
|
||
|
|
|
||
|
|
// SVG 优化配置
|
||
|
|
svg: {
|
||
|
|
multipass: true,
|
||
|
|
plugins: [
|
||
|
|
{
|
||
|
|
name: 'preset-default',
|
||
|
|
params: {
|
||
|
|
overrides: {
|
||
|
|
removeViewBox: false,
|
||
|
|
cleanupIds: false,
|
||
|
|
},
|
||
|
|
},
|
||
|
|
},
|
||
|
|
'sortAttrs',
|
||
|
|
],
|
||
|
|
},
|
||
|
|
|
||
|
|
// PNG 高质量压缩
|
||
|
|
png: {
|
||
|
|
quality: 90,
|
||
|
|
compressionLevel: 9,
|
||
|
|
},
|
||
|
|
|
||
|
|
// JPEG 优化
|
||
|
|
jpeg: {
|
||
|
|
quality: 85,
|
||
|
|
mozjpeg: true,
|
||
|
|
},
|
||
|
|
jpg: {
|
||
|
|
quality: 85,
|
||
|
|
mozjpeg: true,
|
||
|
|
},
|
||
|
|
|
||
|
|
// WebP 转换
|
||
|
|
webp: {
|
||
|
|
quality: 80,
|
||
|
|
lossless: false,
|
||
|
|
force: true,
|
||
|
|
},
|
||
|
|
|
||
|
|
includePublic: true,
|
||
|
|
cache: true,
|
||
|
|
cacheLocation: 'node_modules/.cache/image-optimizer',
|
||
|
|
})
|
||
|
|
}
|