A Vite plugin for optimizing image assets (PNG, JPEG, GIF, TIFF, WebP, AVIF, SVG) at build time using Sharp.js and SVGO. Version 2.0.3 requires Node >=18.17.0, Vite >=5, SVGO >=4, and Sharp >=0.34.0. Provides lossless compression by default, with caching, filtering by test/include/exclude, public directory support, and detailed optimization stats logging. Differentiates from alternatives by combining Sharp and SVGO in one plugin without requiring imagemin or squoosh (which are unmaintained).
npm install vite-plugin-image-optimizerNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Configures ViteImageOptimizer with custom quality settings for raster formats and SVGO plugins for SVG optimization.
Run 'npm install --save-dev sharp svgo' before using the plugin.
Update Node.js to >=18.17.0 or use an older version of the plugin (v1.x).
Update Vite to >=5 or use plugin v1.x (which supports Vite >=3).
Use Sharp for raster optimization instead.
If you need force compression, set 'cache: false' and ensure Sharp quality settings are lossy.
Enable caching by setting 'cache: true' in options, or delete cache directory manually.
Run 'npm install sharp --save-dev' or 'yarn add sharp --dev'
Run 'npm install svgo --save-dev' or 'yarn add svgo --dev'
Use 'import { ViteImageOptimizer } from 'vite-plugin-image-optimizer'' instead of default import.Upgrade Vite to ^5.0.0 or install plugin version 1.x ('npm install vite-plugin-image-optimizer@^1.0.0').