Registry / devops / rollup-plugin-copy

rollup-plugin-copy

JSON →
library3.5.0jsnpmunverified

Rollup plugin to copy files and folders during the build process, with glob support. Current stable version is 3.5.0. The plugin runs on the buildEnd hook by default, supports rename and transform of file contents, and can copy once in watch mode. It is actively maintained with regular releases. Key differentiators include synchronous copy option, flatten option to preserve directory structure, and TypeScript type definitions.

npm install rollup-plugin-copy
INSTALL
IMPORT
SIG · ROLLUP-PLUGIN-COPY
R
rollup-plugin-copy
devopsjavascriptv3.5.0
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.

copy
import copy from 'rollup-plugin-copy'
const copy = require('rollup-plugin-copy')
Default export; the function returns a plugin object. CommonJS require works but this package is ESM-first.
CopyOptions
import type { CopyOptions } from 'rollup-plugin-copy'
TypeScript type for plugin options. Only available in TypeScript projects.
Target
import type { Target } from 'rollup-plugin-copy'
import { Target } from 'rollup-plugin-copy'
TypeScript type for target objects. Using a value import will fail as it's only a type.

Minimal rollup config to copy an HTML file and images using glob patterns with verbosity.

// rollup.config.js import copy from 'rollup-plugin-copy' export default { input: 'src/index.js', output: { file: 'dist/app.js', format: 'cjs' }, plugins: [ copy({ targets: [ { src: 'src/index.html', dest: 'dist/public' }, { src: 'assets/images/**/*', dest: 'dist/public/images' } ], verbose: true }) ] }
Debug
Known issues
breakingv3.0.0: The targets option is now an array of objects with src/dest properties. The old outputFolder option and string-based targets are removed.
fix
Upgrade target format: use targets: [{ src: 'file', dest: 'folder' }] instead of targets: ['file'] + outputFolder.
affects: <3.0.0
breakingv2.0.0: The outputFolder option became required when targets is an array. The hook changed from generateBundle to buildEnd.
fix
If using an array of targets, provide an outputFolder option. If using generateBundle, set hook: 'generateBundle' explicitly.
affects: <2.0.0
deprecatedCommonJS require() is deprecated; package is ESM-only from v3. Use import instead.
fix
Replace const copy = require('rollup-plugin-copy') with import copy from 'rollup-plugin-copy'.
affects: >=3.0.0
gotchaBy default, flatten is true, which removes directory structure. Files are copied flat into dest.
fix
Set flatten: false in options to preserve folder structure.
affects: >=3.0.0
gotchaThe copyOnce option only works in watch mode; if not in watch mode, files are always copied.
fix
Use copyOnce only when rolling with --watch to avoid duplicate copies.
affects: >=3.0.0
Errors
Common errors & fixes
Error: The 'targets' option must be an array of objects with 'src' and 'dest' properties
Using old string-based targets or missing dest property.
fix
Ensure targets is an array of objects: [{ src: 'path', dest: 'path' }].
TypeError: copy is not a function
Attempting to use default import with CommonJS require() in ESM context or vice versa.
fix
Use import copy from 'rollup-plugin-copy' (ESM) or const { default: copy } = require('rollup-plugin-copy') (CommonJS).
Error: Cannot find module 'rollup-plugin-copy'
Package not installed or installed as dev dependency but not resolved.
fix
Run npm install rollup-plugin-copy --save-dev or yarn add rollup-plugin-copy --dev.
Upgrade
Version history
3.5.0latest on npm
Audit
Dependencies
globbyrequiredUsed for glob pattern matching in file selection.
rolluprequiredPeer dependency; required for plugin to function.
Agent activity
7 hits · last 30 days
node
6
Resources
rollup-plugin-copy — npm install rollup-plugin-copy · libregistry