{"id":21968,"library":"rollup-plugin-copy","title":"rollup-plugin-copy","description":"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.","status":"active","version":"3.5.0","language":"javascript","source_language":"en","source_url":"https://github.com/vladshcherbin/rollup-plugin-copy","tags":["javascript","rollup","rollup-plugin","copy","cp","asset","assets","file","files","typescript"],"install":[{"cmd":"npm install rollup-plugin-copy","lang":"bash","label":"npm"},{"cmd":"yarn add rollup-plugin-copy","lang":"bash","label":"yarn"},{"cmd":"pnpm add rollup-plugin-copy","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Used for glob pattern matching in file selection.","package":"globby","optional":false},{"reason":"Peer dependency; required for plugin to function.","package":"rollup","optional":false}],"imports":[{"note":"Default export; the function returns a plugin object. CommonJS require works but this package is ESM-first.","wrong":"const copy = require('rollup-plugin-copy')","symbol":"copy","correct":"import copy from 'rollup-plugin-copy'"},{"note":"TypeScript type for plugin options. Only available in TypeScript projects.","wrong":"","symbol":"CopyOptions","correct":"import type { CopyOptions } from 'rollup-plugin-copy'"},{"note":"TypeScript type for target objects. Using a value import will fail as it's only a type.","wrong":"import { Target } from 'rollup-plugin-copy'","symbol":"Target","correct":"import type { Target } from 'rollup-plugin-copy'"}],"quickstart":{"code":"// rollup.config.js\nimport copy from 'rollup-plugin-copy'\n\nexport default {\n  input: 'src/index.js',\n  output: {\n    file: 'dist/app.js',\n    format: 'cjs'\n  },\n  plugins: [\n    copy({\n      targets: [\n        { src: 'src/index.html', dest: 'dist/public' },\n        { src: 'assets/images/**/*', dest: 'dist/public/images' }\n      ],\n      verbose: true\n    })\n  ]\n}","lang":"typescript","description":"Minimal rollup config to copy an HTML file and images using glob patterns with verbosity."},"warnings":[{"fix":"Upgrade target format: use targets: [{ src: 'file', dest: 'folder' }] instead of targets: ['file'] + outputFolder.","message":"v3.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.","severity":"breaking","affected_versions":"<3.0.0"},{"fix":"If using an array of targets, provide an outputFolder option. If using generateBundle, set hook: 'generateBundle' explicitly.","message":"v2.0.0: The outputFolder option became required when targets is an array. The hook changed from generateBundle to buildEnd.","severity":"breaking","affected_versions":"<2.0.0"},{"fix":"Replace const copy = require('rollup-plugin-copy') with import copy from 'rollup-plugin-copy'.","message":"CommonJS require() is deprecated; package is ESM-only from v3. Use import instead.","severity":"deprecated","affected_versions":">=3.0.0"},{"fix":"Set flatten: false in options to preserve folder structure.","message":"By default, flatten is true, which removes directory structure. Files are copied flat into dest.","severity":"gotcha","affected_versions":">=3.0.0"},{"fix":"Use copyOnce only when rolling with --watch to avoid duplicate copies.","message":"The copyOnce option only works in watch mode; if not in watch mode, files are always copied.","severity":"gotcha","affected_versions":">=3.0.0"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Ensure targets is an array of objects: [{ src: 'path', dest: 'path' }].","cause":"Using old string-based targets or missing dest property.","error":"Error: The 'targets' option must be an array of objects with 'src' and 'dest' properties"},{"fix":"Use import copy from 'rollup-plugin-copy' (ESM) or const { default: copy } = require('rollup-plugin-copy') (CommonJS).","cause":"Attempting to use default import with CommonJS require() in ESM context or vice versa.","error":"TypeError: copy is not a function"},{"fix":"Run npm install rollup-plugin-copy --save-dev or yarn add rollup-plugin-copy --dev.","cause":"Package not installed or installed as dev dependency but not resolved.","error":"Error: Cannot find module 'rollup-plugin-copy'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}