Rollup and Vite plugin for optimizing images (JPEG, PNG, WebP, AVIF) using napi-rs/Image, a native Rust-based image processing library. Version 0.6.1 released in 2025. It supports both lossy (with configurable quality) and lossless modes, and allows conversion to modern formats (e.g., WebP to AVIF) via a custom function. Unlike imagemin-based plugins, it avoids node-gyp and provides faster performance via N-API. Compatible with Rollup and Vite, with TypeScript types included. Good for build-time image optimization in modern bundler setups.
npm install rollup-plugin-napi-imageVerified import paths — ran on the pinned version, not inferred.
Rollup config with napiImage plugin: lossy compression at quality 75, excluding sprite.png, and converting WebP to AVIF.
Pin version if stable: "rollup-plugin-napi-image": "0.6.1"
Ensure production build runs image optimization separately or use manual rebuild.
Restrict return type to supported extensions.
Update import to { napiImage } from 'rollup-plugin-napi-image'Upgrade Node.js to version 16 or higher, or use an older version of the plugin that supports Node 14.
Only set quality when mode is 'lossy'.
Use include/exclude patterns to filter out unsupported types.
Run: npm install rollup-plugin-napi-image --save-dev
Use: import { napiImage } from 'rollup-plugin-napi-image'Remove SVG files from the rollup pipeline or set include to only supported extensions.
Add mode: 'lossy' or 'lossless' to plugin options.
Ensure include patterns match only files, not directories.
No dependency data recorded yet.