Optimized image loading with automatic dimensions and blur placeholders using the ?imagedata import suffix.
One provides a built-in way to import images with their metadata at build time using the ?imagedata suffix. This gives you automatic width, height, and blur placeholder data without any runtime cost.
Setup
Install sharp to enable image processing:
yarn
npm
bun
pnpm
npm install sharp
If sharp is not installed, imports will still work but return 0 for dimensions and an empty blur placeholder. A console warning will be shown during build to remind you to install it.
Usage
Import any image with the ?imagedata suffix:
import heroImage from'/hero.jpg?imagedata'
// heroImage = {
// src: '/hero.jpg',
// width: 1920,
// height: 1080,
// blurDataURL: 'data:image/jpeg;base64,...'
// }
The returned object can be spread directly onto any image component: