{"id":22075,"library":"rollup-plugin-import-file","title":"rollup-plugin-import-file","description":"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.","status":"active","version":"1.0.1","language":"javascript","source_language":"en","source_url":"https://github.com/jlocoding/rollup-plugin-import-file","tags":["javascript","rollup","rollup-plugin","files"],"install":[{"cmd":"npm install rollup-plugin-import-file","lang":"bash","label":"npm"},{"cmd":"yarn add rollup-plugin-import-file","lang":"bash","label":"yarn"},{"cmd":"pnpm add rollup-plugin-import-file","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The package is ESM-only; CommonJS require will fail unless using dynamic import.","wrong":"const files = require('rollup-plugin-import-file')","symbol":"default (files)","correct":"import files from 'rollup-plugin-import-file'"},{"note":"The plugin is exported as default, not as a named export. Named import will be undefined.","wrong":"import { files } from 'rollup-plugin-import-file'","symbol":"files","correct":"import files from 'rollup-plugin-import-file'"},{"note":"Type imports are available for TypeScript users but are not runtime values.","wrong":"import { PluginOptions } from 'rollup-plugin-import-file'","symbol":"PluginOptions","correct":"import type { PluginOptions } from 'rollup-plugin-import-file'"}],"quickstart":{"code":"// rollup.config.js\nimport files from 'rollup-plugin-import-file';\n\nexport default {\n  input: 'src/index.js',\n  output: {\n    file: 'dist/bundle.js',\n    format: 'iife',\n    name: 'MyBundle',\n  },\n  plugins: [\n    files({\n      output: 'dist/assets',\n      extensions: /\\.(png|jpg|gif|svg)$/i,\n      hash: true,\n    }),\n  ],\n};\n\n// src/index.js\nimport logo from './logo.png';\nconsole.log(logo); // Outputs: 'assets/logo-a1b2c3d4.png'","lang":"javascript","description":"Configures Rollup to copy image imports to 'dist/assets' with content hashing, and demonstrates importing a PNG file."},"warnings":[{"fix":"Ensure all imported file types are included in the `extensions` regex pattern, e.g., /.(wav|doc|png)$/.","message":"Trying 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.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use the plugin exclusively in Rollup configuration.","message":"The plugin only works with Rollup's JavaScript API. Using it with other bundlers like Webpack or esbuild will cause errors.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Specify a relative path like 'assets/files' or use path.resolve to ensure it is within the output directory.","message":"The `output` option must be a relative path from the Rollup output directory. Absolute paths or paths outside the output directory may cause unexpected behavior.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Run `npm install --save-dev rollup-plugin-import-file` or `yarn add --dev rollup-plugin-import-file`.","cause":"The package is not installed or is installed as a dev dependency but not in node_modules.","error":"Error: Cannot find module 'rollup-plugin-import-file'"},{"fix":"Use default import: `import files from 'rollup-plugin-import-file'`.","cause":"Using named import instead of default import: `import { files } from 'rollup-plugin-import-file'`.","error":"TypeError: files is not a function"},{"fix":"Use `import files from 'rollup-plugin-import-file'` instead.","cause":"Named import used but the package only provides a default export.","error":"The requested module 'rollup-plugin-import-file' does not provide an export named 'files'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}