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.
Install sharp to enable image processing:
yarn
npm
bun
pnpm
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.
Import any image with the ?imagedata suffix:
The returned object can be spread directly onto any image component:
The plugin supports both public directory and relative imports:
Types are included automatically. The import returns an ImageData object:
The blur placeholder is a tiny (10px wide) base64-encoded JPEG that can be used as a low-quality image placeholder (LQIP) while the full image loads:
For one-off usage or build scripts, use the getImageData helper:
When using @vxrn/mdx, images in frontmatter are automatically processed with getMDX. If your MDX file has:
The frontmatter will include imageMeta with dimensions and blur placeholder:
The plugin uses sharp for image processing, which supports:
<img>, React Native <Image>, Tamagui, etc.)Edit this page on GitHub.