A Vite plugin that transforms images at compile time using import directives, powered by sharp. Current stable version is 10.0.0, released with regular patch updates. Key differentiators include URL-based query directives for resizing, format conversion, metadata removal, and srcset generation, all optimized for Vite's build pipeline. It ships TypeScript types and requires Node >=22.0.0 and Vite >=7.0.0 as peer dependencies.
npm install vite-imagetoolsVerified import paths — ran on the pinned version, not inferred.
Configures the imagetools plugin with default directives, include/exclude patterns, and metadata removal. Shows how to import images with query parameters.
Upgrade Node to >=22 and Vite to >=7.
Use import syntax instead of require().
Use URLSearchParams or (url: URL) => URLSearchParams.
Override exclude option if you need to transform images in public/.
Ensure sharp is installed and your platform is supported (Windows/Linux/macOS with Node >=22).
Use vite-imagetools for both Vite and Rollup (same plugin works with both).
Run: npm install --save-dev vite-imagetools
Then use import { imagetools } from 'vite-imagetools'Change to: import { imagetools } from 'vite-imagetools'Reinstall sharp: npm install sharp If platform not supported, consider using a Docker image or alternative.
Use: import Image from 'example.jpg?w=400' (note the '?').