rollup-plugin-copy-glob
raw JSON → 0.4.1 verified Mon Apr 27 auth: no javascript
Rollup plugin that copies files and folders during build with glob pattern support and optional renaming. Current stable version is 0.4.1, released with infrequent updates. It is a lightweight alternative to rollup-plugin-copy, offering glob patterns and rename support out of the box, with minimal configuration. It supports Node >=12 and integrates with Rollup's watch mode for file copying on rebuild.
Common errors
error TypeError: copy is not a function ↓
cause Importing the plugin incorrectly (e.g., using named import instead of default).
fix
Use
import copy from 'rollup-plugin-copy-glob' (default import). error Error: No files matched with pattern: src/**/*.txt ↓
cause Glob pattern does not match any existing files.
fix
Verify the path and pattern; check if files exist relative to project root.
error Error: ENOENT: no such file or directory, copyfile 'source' -> 'dest' ↓
cause The destination directory does not exist.
fix
Create the destination directory before running Rollup, or use a plugin that auto-creates directories.
Warnings
gotcha The plugin only copies files at build start or during watch mode; it does not clean the destination before copying, so outdated files may remain. ↓
fix Use a separate cleanup plugin like rollup-plugin-delete or manually clean dist before build.
deprecated Option 'watch' is deprecated; use Rollup's built-in watch mode instead. ↓
fix Remove the 'watch' option; rely on Rollup's --watch flag.
breaking In version 0.1.0, the API changed from copy(files, dest) to copy([...], options). ↓
fix Update your plugin config to use array of objects with 'files' and 'dest' properties.
gotcha When using rename, ensure the destination directory exists; the plugin does not create nested directories automatically. ↓
fix Create the destination directory manually or use a separate mkdirp step.
Install
npm install rollup-plugin-copy-glob yarn add rollup-plugin-copy-glob pnpm add rollup-plugin-copy-glob Imports
- copy wrong
const copy = require('rollup-plugin-copy-glob')correctimport copy from 'rollup-plugin-copy-glob' - CopyOptions
import type { CopyOptions } from 'rollup-plugin-copy-glob' - CopyTarget
import type { CopyTarget } from 'rollup-plugin-copy-glob'
Quickstart
import copy from 'rollup-plugin-copy-glob';
export default {
input: 'src/index.js',
output: {
file: 'dist/bundle.js',
format: 'iife',
name: 'app'
},
plugins: [
copy([
{ files: 'src/*.{html,css}', dest: 'dist' },
{ files: 'src/config.template', dest: 'dist', rename: 'config.json' },
{ files: 'dev/images/**/*.*', dest: 'dist/images' }
], { verbose: true, watch: true })
]
};