A Vite plugin (v0.1.1, latest) that automatically generates srcset attributes for responsive images by importing images with the ?srcset query. It expects images with @2x and @3x suffixes in the same directory, outputs an object with `src` and `srcSet` properties for 1x/2x/3x pixel densities. Supports PNG and JPG formats. Requires Vite 5+, 6+, or 7+. Ships TypeScript declarations. Minimal alternative to heavier image optimization plugins.
npm install vite-plugin-image-srcsetVerified import paths — ran on the pinned version, not inferred.
Configures the plugin in Vite and demonstrates importing an image with ?srcset query to generate src and srcSet props for responsive images.
Ensure all three variants exist: icon.png, icon@2x.png, icon@3x.png.
Convert images to .png or .jpg, or check plugin configuration for future format support.
Append ?srcset to the import path: import img from './image.png?srcset'
Add "types": ["vite-plugin-image-srcset/client"] in tsconfig.json or add /// <reference types="vite-plugin-image-srcset/client" /> in a .d.ts file.
Use import img from './file.png?srcset' instead of import img from './file.png'
Change to: import { srcSetPlugin } from 'vite-plugin-image-srcset'