Registry / devops / rollup-plugin-img

rollup-plugin-img

JSON →
library1.1.0jsnpmunverified

Rollup plugin to import image files (PNG, JPG, GIF, SVG) as base64 data URIs or copied files, similar to Webpack's file-loader/url-loader. Current stable version 1.1.0. A single release exists; no updates since 2018. Differentiators: simple configuration, supports hash filenames, custom output path, and file size limit for base64 inlining. Alternative to rollup-plugin-image or rollup-plugin-url.

npm install rollup-plugin-img
INSTALL
IMPORT
SIG · ROLLUP-PLUGIN-IMG
R
rollup-plugin-img
devopsjavascriptv1.1.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
✓ import image from 'rollup-plugin-img'
✗ const image = require('rollup-plugin-img').default
Plugin is ESM-only; use import syntax.
image
✓ import image from 'rollup-plugin-img'
✗ import { image } from 'rollup-plugin-img'
Default export, not named.

Shows how to configure rollup-plugin-img with options for output directory, size limit, and hash filenames.

// rollup.config.js import image from 'rollup-plugin-img'; export default { input: 'src/index.js', output: { file: 'dist/bundle.js', format: 'cjs' }, plugins: [ image({ output: 'dist/images', limit: 10000, hash: true }) ] };
Debug
Known issues
gotchaThe `output` option is described as 'Required' in README but not enforced; missing it may cause files to be copied to the current working directory.
fix
Always specify `output` option to control where copied files land.
affects: >=1.0.0
gotchaWhen `hash: true`, hash is appended to the filename but the extension remains; no collision detection if two identical images are imported.
fix
Use a more robust plugin like rollup-plugin-url or rollup-plugin-file for production.
affects: >=1.0.0
gotchaPlugin ignores SVGs by default if extensions override does not include them; default regex only matches PNG, JPG, JPEG, GIF, SVG.
fix
If using custom extensions, include SVG if needed: /.(png|jpg|jpeg|gif|svg)$/
affects: >=1.0.0
gotchaFiles exceeding `limit` are copied to the output directory; the plugin does not emit them as assets properly for Rollup's asset handling.
fix
Use rollup-plugin-copy or the official Rollup asset mechanism for copying files.
affects: >=1.0.0
deprecatedPackage last updated in 2018; uses deprecated Rollup plugin API (e.g., `options` hook).
fix
Consider migrating to rollup-plugin-url (for base64) or @rollup/plugin-image for better maintenance.
affects: >=1.0.0
Errors
Common errors & fixes
Error: Invalid plugin hook: options
Plugin uses deprecated options hook which may not be supported in newer Rollup versions.
fix
Upgrade to Rollup 2.x with compatible plugin; or use rollup-plugin-url which supports modern API.
TypeError: image is not a function
Incorrect import: using named import instead of default import.
fix
Use `import image from 'rollup-plugin-img'` (no curly braces).
Could not resolve 'path/image.png' from 'src/index.js'
Plugin not configured to handle image files; order of plugins matters.
fix
Ensure `image()` plugin is included in the plugins array and image extensions are covered.
Upgrade
Version history
1.1.0latest on npm
Audit
Dependencies
rolluprequiredPeer dependency required for plugin execution.
Agent activity
4 hits · last 30 days
node
4
Resources
rollup-plugin-img — npm install rollup-plugin-img · libregistry