rollup-plugin-emit-files
raw JSON → 2.0.0 verified Mon Apr 27 auth: no javascript
A Rollup plugin that emits files into the output bundle, useful for copying static assets like images, fonts, or data files during the build process. Current stable version is 2.0.0. It requires Rollup ^3.2.5 and ships TypeScript types. Compared to alternatives like `rollup-plugin-copy`, it integrates directly with Rollup's emit mechanism, ensuring assets appear in the bundle output without separate copy tasks. The plugin supports glob patterns for include/exclude filtering and a destination path relative to the output directory. It is actively maintained with a simple API.
Common errors
error Error: The emitFiles plugin must be used with Rollup 3 or higher ↓
cause rollup-plugin-emit-files v2 has a peer dependency on rollup ^3.2.5, but an older Rollup version is installed.
fix
Upgrade Rollup to version ^3.2.5 using npm install rollup@^3.2.5
error TypeError: emitFiles is not a function ↓
cause Using a named import instead of default import: import { emitFiles } from '...'
fix
Change to default import: import emitFiles from 'rollup-plugin-emit-files'
error Cannot find module 'rollup-plugin-emit-files' ↓
cause The package is not installed or is installed as a devDependency but the build environment doesn't have access.
fix
Run npm install --save-dev rollup-plugin-emit-files
Warnings
breaking Version 2.0.0 requires Rollup ^3.2.5. It is incompatible with Rollup 2.x. ↓
fix Use rollup-plugin-emit-files@1.x for Rollup 2.x, or upgrade to Rollup 3+.
gotcha The src directory must exist and contain files; otherwise the plugin emits silently without warning. ↓
fix Ensure the src path is correct and contains at least one file matching the include pattern.
gotcha The dest path is relative to the output directory—not from the project root. Misconfiguration can cause files to be placed in unexpected locations. ↓
fix Use dest: '.' for flat output or e.g. dest: 'assets' to place files inside an assets subfolder within the output directory.
deprecated Older versions (v1.x) used a different export pattern; upgrading to v2.0.0 may break CommonJS usage. ↓
fix Switch from require() to import, or use the ESM-compatible configuration.
Install
npm install rollup-plugin-emit-files yarn add rollup-plugin-emit-files pnpm add rollup-plugin-emit-files Imports
- emitFiles wrong
const emitFiles = require('rollup-plugin-emit-files')correctimport emitFiles from 'rollup-plugin-emit-files' - rollup-plugin-emit-files (types)
import type { Options } from 'rollup-plugin-emit-files' - emitFiles (default export) wrong
import { emitFiles } from 'rollup-plugin-emit-files'correctimport emitFiles from 'rollup-plugin-emit-files'
Quickstart
// rollup.config.js
import emitFiles from 'rollup-plugin-emit-files';
export default {
input: 'src/index.js',
output: {
dir: 'dist',
format: 'esm'
},
plugins: [
emitFiles({
src: 'static',
dest: '.',
include: ['**/*'],
exclude: []
})
]
};