A Vite plugin that converts JPEG, PNG, GIF, and AVIF images to WebP format during the build process, using the sharp library for high-performance conversion. Version 1.1.3 is the latest stable release. It supports CSS background images (with a fallback class-based approach) and JS image imports with clip (dimension-based) transformations. Key differentiator: automatic inline conversion in CSS and JS without manual WebP management, plus image clipping via filename dimensions.
npm install vite-plugin-webpVerified import paths — ran on the pinned version, not inferred.
Basic configuration of vite-plugin-webp in vite.config.js, showing include, exclude, imageType, and sharpOptions.
Use 'exclude' option; if you copy from the README, correct the spelling.
Use 'sharpOptions' in your config.
Name your images with dimensions in the filename, e.g., 'image240x250.png'.
Set 'include' to a specific directory to limit conversion scope.
Run 'npm install sharp' to add sharp as a direct dependency.
Change import to 'import webp from 'vite-plugin-webp'' (without curly braces).
Use correct option name 'sharpOptions'.