rollup-plugin-copy2
raw JSON → 0.4.0 verified Mon Apr 27 auth: no javascript
A Rollup plugin to copy additional assets to the build directory, version 0.4.0. Unlike typical copy plugins, it does not copy by default but emits files into the Rollup bundle, making them accessible to other plugins (e.g., rollup-plugin-zip). Actual copying is handled by Rollup itself. It supports glob patterns, source-destination pairs, and an optional outputDirectory for direct disk writes. Requires Rollup >=3.20.0. Minimalistic, ESM-only, with TypeScript support.
Common errors
error The requested module 'rollup-plugin-copy2' does not provide an export named 'default' ↓
cause Attempting default import instead of named import.
fix
Change import copy from 'rollup-plugin-copy2' to import { copy } from 'rollup-plugin-copy2'.
error Error: rollup-plugin-copy2 requires Rollup >=3.20.0 ↓
cause Installed rollup version is too old.
fix
Upgrade rollup to ^3.20.0 or later: npm install rollup@latest --save-dev.
error TypeError: copy is not a function ↓
cause Importing the wrong export (e.g., import * as copy from '...' then using copy()).
fix
Use named import: import { copy } from 'rollup-plugin-copy2'.
Warnings
gotcha Files are not physically copied by default; they are emitted into Rollup's bundle. Use outputDirectory option to write them to disk. ↓
fix Set outputDirectory to a path if you need files on disk, or use another plugin like rollup-plugin-copy (note different package).
gotcha Glob patterns only work when source is a single string, not in [source, dest] tuples. Tuples expect exact file paths. ↓
fix Use single string glob for multiple files; for renaming, use [exactPath, destPath].
deprecated The plugin is ESM-only and does not support require(). Using require() will throw an error. ↓
fix Use import or dynamic import() in an ESM context. Set type: 'module' in package.json or use .mjs extension.
gotcha Files emitted by this plugin are not automatically included in the output unless downstream plugins handle them. If you only use copy without zip, you may see no output files. ↓
fix Either set outputDirectory to copy to disk, or add another plugin that consumes emitted assets (e.g., rollup-plugin-zip).
Install
npm install rollup-plugin-copy2 yarn add rollup-plugin-copy2 pnpm add rollup-plugin-copy2 Imports
- copy wrong
import copy from 'rollup-plugin-copy2'correctimport { copy } from 'rollup-plugin-copy2' - copy wrong
const { copy } = require('rollup-plugin-copy2')correctconst { copy } = await import('rollup-plugin-copy2') - CopyOptions
import type { CopyOptions } from 'rollup-plugin-copy2'
Quickstart
// rollup.config.js
import { copy } from 'rollup-plugin-copy2'
export default {
input: 'src/index.js',
output: {
dir: 'dist',
format: 'es',
},
plugins: [
copy({
assets: [
'README.md',
['src/data.txt', 'assets/data.txt'],
'node_modules/some-lib/*.css',
],
notEmitFiles: false,
outputDirectory: 'additional',
}),
],
}