unplugin-image is a versatile bundler plugin built on the unplugin standard, enabling seamless importing of various image formats including JPG, PNG, GIF, SVG, and WebP across different build tools. Its current stable version is `0.2.1`. The package has seen recent, frequent updates, indicating active development and a rapid release cadence for bug fixes and new features, though it remains in a `0.x.x` semantic versioning range. A key differentiator is its 'universal' nature, allowing developers to write a single plugin configuration that adapts to Vite, Rollup, Webpack, Nuxt, and esbuild, significantly reducing setup complexity for projects targeting multiple build environments. It also leverages the robust options and capabilities of the well-established `@rollup/plugin-image` under the hood.
npm install unplugin-imageVerified import paths — ran on the pinned version, not inferred.
This Vite configuration demonstrates how to integrate `unplugin-image` to process and optimize image assets, including inlining small images and specifying output paths, ensuring it runs correctly with `enforce: 'pre'`.
Ensure your Vite plugin configuration includes `{ ...UnpluginImage(...), enforce: 'pre' }`.Always use the correct subpath import for your bundler: `import UnpluginImage from 'unplugin-image/<bundler>'` or `require('unplugin-image/webpack')`.Refer to the `@rollup/plugin-image` documentation for a complete list of valid options and their behavior.
Pin to exact versions (`"unplugin-image": "0.2.1"`) or use caution when updating minor versions in production environments. Review changelogs for each update.
Configure in `nuxt.config.js/ts` as `modules: [['unplugin-image/nuxt', { /* options */ }]]`.Change the import path to include your bundler, e.g., `import UnpluginImage from 'unplugin-image/vite'`.
Either remove `outputFileName` if you intend to inline all assets or adjust `limit` to prevent inlining for images that should be separate files. Alternatively, disable `dom` or `inline` if not desired.
Add `enforce: 'pre'` to the `unplugin-image` configuration in `vite.config.ts`, e.g., `{ ...UnpluginImage(), enforce: 'pre' }`.