Registry / devops / rollup-plugin-import-file

rollup-plugin-import-file

JSON →
library1.0.1jsnpmunverified

A Rollup plugin that copies imported files of specified extensions (e.g., .wav, .doc) to an output directory and optionally adds a content hash to the filename, enabling import of non-JS assets in Rollup bundles. Version 1.0.1 is the latest stable release. It requires an explicit extension pattern and output path, making it suitable for projects that need to bundle static assets alongside JavaScript. Unlike similar plugins (e.g., @rollup/plugin-image, rollup-plugin-copy), it focuses on generic file copying with hashing and is minimal in configuration.

npm install rollup-plugin-import-file
INSTALL
IMPORT
SIG · ROLLUP-PLUGIN-IMPO
R
rollup-plugin-import-file
devopsjavascriptv1.0.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 (files)
import files from 'rollup-plugin-import-file'
const files = require('rollup-plugin-import-file')
The package is ESM-only; CommonJS require will fail unless using dynamic import.
files
import files from 'rollup-plugin-import-file'
import { files } from 'rollup-plugin-import-file'
The plugin is exported as default, not as a named export. Named import will be undefined.
PluginOptions
import type { PluginOptions } from 'rollup-plugin-import-file'
import { PluginOptions } from 'rollup-plugin-import-file'
Type imports are available for TypeScript users but are not runtime values.

Configures Rollup to copy image imports to 'dist/assets' with content hashing, and demonstrates importing a PNG file.

// rollup.config.js import files from 'rollup-plugin-import-file'; export default { input: 'src/index.js', output: { file: 'dist/bundle.js', format: 'iife', name: 'MyBundle', }, plugins: [ files({ output: 'dist/assets', extensions: /\.(png|jpg|gif|svg)$/i, hash: true, }), ], }; // src/index.js import logo from './logo.png'; console.log(logo); // Outputs: 'assets/logo-a1b2c3d4.png'
Debug
Known issues
gotchaTrying to import a file without specifying its extension in the `extensions` option will cause the plugin to ignore it, resulting in a module not found error.
fix
Ensure all imported file types are included in the `extensions` regex pattern, e.g., /.(wav|doc|png)$/.
affects: >=1.0.0
gotchaThe plugin only works with Rollup's JavaScript API. Using it with other bundlers like Webpack or esbuild will cause errors.
fix
Use the plugin exclusively in Rollup configuration.
affects: >=1.0.0
gotchaThe `output` option must be a relative path from the Rollup output directory. Absolute paths or paths outside the output directory may cause unexpected behavior.
fix
Specify a relative path like 'assets/files' or use path.resolve to ensure it is within the output directory.
affects: >=1.0.0
Errors
Common errors & fixes
Error: Cannot find module 'rollup-plugin-import-file'
The package is not installed or is installed as a dev dependency but not in node_modules.
fix
Run `npm install --save-dev rollup-plugin-import-file` or `yarn add --dev rollup-plugin-import-file`.
TypeError: files is not a function
Using named import instead of default import: `import { files } from 'rollup-plugin-import-file'`.
fix
Use default import: `import files from 'rollup-plugin-import-file'`.
The requested module 'rollup-plugin-import-file' does not provide an export named 'files'
Named import used but the package only provides a default export.
fix
Use `import files from 'rollup-plugin-import-file'` instead.
Upgrade
Version history
1.0.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
5 hits · last 30 days
node
4
Resources
rollup-plugin-import-file — npm install rollup-plugin-import-file · libregistry