Registry / devops / rollup-plugin-import-assets

rollup-plugin-import-assets

JSON →
library1.1.1jsnpmunverified

A Rollup plugin (version 1.1.1) that allows importing image and other asset files directly in JavaScript, returning the public URL or path. It copies assets to the output directory, supports hashing for cache busting, and works with Rollup >=1.9.0. Unlike similar plugins, it is lightweight and focuses on basic asset import and emission without complex transformations.

npm install rollup-plugin-import-assets
INSTALL
IMPORT
SIG · ROLLUP-PLUGIN-IMPO
R
rollup-plugin-import-assets
devopsjavascriptv1.1.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18223 runs
build_error
glibc
node 18223 runs
build_error
Code
Verified usage

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

default
import importAssets from 'rollup-plugin-import-assets'
const importAssets = require('rollup-plugin-import-assets')
ESM default import; CommonJS require will fail because the package is ESM-only.
importAssets
import { default as importAssets } from 'rollup-plugin-import-assets'
import { importAssets } from 'rollup-plugin-import-assets'
This package only exports a default function, not a named export. Named import will result in undefined.
config object
importAssets({ include: [/.../], emitAssets: true })
importAssets({ include: '...', emitAssets: 'true' })
include must be an array of RegExp, emitAssets is boolean, not string.

Shows basic setup: install, config with asset inclusion, emission to output dir, and usage in code.

// Install: npm install --save-dev rollup rollup-plugin-import-assets // rollup.config.js import importAssets from 'rollup-plugin-import-assets'; export default { input: 'src/main.js', output: { dir: 'public', format: 'esm' }, plugins: [ importAssets({ include: [/\.(gif|jpg|png|svg)$/i], emitAssets: true, fileNames: 'assets/[name]-[hash].[ext]', publicPath: '/static/' }) ] }; // src/main.js import logo from './img/logo.png'; const img = `<img src="${logo}" />`;
Debug
Known issues
breakingPlugin is ESM-only and cannot be used with require() in CommonJS projects.
fix
Use ES module syntax (import) or switch to a plugin that supports CJS.
affects: >=1.0.0
gotchaInclude patterns must be RegExp objects, not strings or globs.
fix
Use RegExp literals or RegExp objects, e.g., [/\.jpg$/i]
affects: >=1.0.0
gotchaIf emitAssets is false, the imported asset will only return a path string but the file won't be copied.
fix
Set emitAssets: true if you need the file in the output directory.
affects: >=1.0.0
gotchaFile hashing uses the asset content, but hash algorithm is not configurable; may cause collisions for identical files.
fix
Use a different plugin if custom hashing or content addressing is needed.
affects: >=1.0.0
Errors
Common errors & fixes
Cannot find module 'rollup-plugin-import-assets'
Package not installed or mismatched Node.js version (requires ESM support).
fix
Run 'npm install rollup-plugin-import-assets' and ensure package.json has 'type': 'module' or use .mjs extension for config.
TypeError: importAssets is not a function
Incorrect import: using named import { importAssets } instead of default import.
fix
Use 'import importAssets from 'rollup-plugin-import-assets'' or 'import { default as importAssets } from 'rollup-plugin-import-assets''.
The plugin 'importAssets' assigned a different code path to an asset.
Asset matched multiple include patterns? Actually, this error appears when including the same file via multiple expressions; not typical.
fix
Ensure each asset matches exactly one include pattern or use exclude to avoid duplicates.
Upgrade
Version history
1.1.1latest on npm
Audit
Dependencies
rolluprequiredpeer dependency required to function as a Rollup plugin
Agent activity
6 hits · last 30 days
node
5
Resources
rollup-plugin-import-assets — npm install rollup-plugin-import-assets · libregistry