@bdocs/plugin-image-optimizer
v0.2.1
Published
Image optimization plugin for Boltdocs using Sharp.js and SVGO
Downloads
329
Readme
@bdocs/plugin-image-optimizer
Optimize images at build time with Sharp.js and SVGO. Plugin for Vite/Boltdocs.
Features
- Parallel processing via worker threads (up to CPU count - 1)
- Persistent caching with Boltdocs'
AssetCache - DUI-powered stats table with per-file savings
- Zero-copy buffer transfer between threads
- Backpressure fallback when queue exceeds 500 tasks
Installation
pnpm add @bdocs/plugin-image-optimizersharp and svgo are peer dependencies — install only what you need:
pnpm add sharp svgo --save-devUsage
import { ViteImageOptimizer } from '@bdocs/plugin-image-optimizer'
import { defineConfig } from 'vite'
export default defineConfig({
plugins: [ViteImageOptimizer()],
})Options
| Option | Type | Default | Description |
|--------|------|---------|-------------|
| test | RegExp | /\.(jpe?g\|png\|gif\|tiff\|webp\|svg\|avif)$/i | Match files to process |
| include | RegExp \| string \| string[] | — | Overrides test/exclude |
| exclude | RegExp \| string \| string[] | — | Files to skip |
| includePublic | boolean | true | Optimize files in publicDir |
| logStats | boolean | true | Print optimization table after build |
| svg | SVGOConfig | preset-default (lossless) | SVGO config |
| png | PngOptions | { quality: 85 } | Sharp PNG |
| jpeg | JpegOptions | { quality: 85 } | Sharp JPEG |
| jpg | JpegOptions | { quality: 85 } | Alias for jpeg |
| tiff | TiffOptions | { quality: 85 } | Sharp TIFF |
| gif | GifOptions | {} | Sharp GIF |
| webp | WebpOptions | { quality: 85 } | Sharp WebP |
| avif | AvifOptions | { quality: 80 } | Sharp AVIF |
License
MIT
