A Vite plugin that compresses static images (jpg, png, gif, webp) after each build using sharp.js. Version 1.9.1 is the latest stable. Ideal for Vite projects needing automated image optimization without manual tooling. It works with Vite 2.6 to 5, handles public folder images, and offers per-format options. The plugin differs from others by being Vite-native, supporting exclude/include patterns for public assets, and allowing resizing and metadata preservation.
npm install vite-plugin-vsharpVerified import paths — ran on the pinned version, not inferred.
Demonstrates setting up VSharp with custom options: per-format quality, exclusions, resizing, and metadata preservation.
Downgrade Vite to <=5 or switch to an alternative plugin that supports newer Vite.
Replace 'publicDir' with 'excludePublic' and 'outDir' with 'includePublic'.
Use patterns like 'public/images/*' without leading slash.
Use either scale or width/height, not both.
Run 'npm install sharp' or ensure sharp is installed in your project.
Provide an array of strings: excludePublic: ['public/*']
Use ES module import: import vsharp from 'vite-plugin-vsharp'