A zero-config Vite plugin for compressing images at build time using sharp (JPEG/PNG/WebP/AVIF/TIFF/GIF) and SVGO (SVG). Active, stable v1.6.3 with support for Vite 4+. Works on both bundle-asset and public/ directory images. Outperforms imagemin-based alternatives by 4-5x due to libvips native bindings. Features include content-hash caching, include/exclude filters, min-ratio/size thresholds, resize without enlargement, configurable concurrency, and per-format compression settings. Transparent terminal output showing before/after sizes per file. Ships TypeScript types.
npm install vite-plugin-sharpNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Shows full configuration: custom quality, cache disabled, size/ratio thresholds, resize, concurrency, include/exclude filters.
Image compression is intentionally build-only; use other tools for dev-time optimization.
Set a custom cache path outside node_modules: viteSharp({ cache: '.cache/sharp.json' })Explicitly set compress options if you rely on previous quality values.
Use viteSharp({ compress: { svg: { multipass: true, plugins: ['preset-default'] } } })Set resize.withoutEnlargement to false if upscaling is desired (not recommended).
Exclude TIFF files via exclude option if not needed: viteSharp({ exclude: '\.tiff$' })npm install vite-plugin-sharp -D
Use import syntax: import viteSharp from 'vite-plugin-sharp', or rename vite.config.js to vite.config.mjs
Reduce image size or set sharp.limitInputPixels: sharp({ limitInputPixels: false }) via compress options.Upgrade Vite to >=4.0.0, or import from 'vite/dist/node' (not recommended).