rollup-plugin-copy-assets

raw JSON →
2.0.3 verified Mon Apr 27 auth: no javascript maintenance

Rollup plugin to copy additional files and directories into the output directory of your Rollup bundle. The latest version 2.0.3 works with Rollup >=1.1.2. It maintains the relative directory hierarchy of copied assets. Key differentiators: simple API (just provide an array of paths), supports both files and directories, and works with chunked builds since v2.0.0. The plugin hooks into the generateBundle hook to copy assets. It has no other dependencies besides Rollup.

error Error: Cannot find module 'rollup-plugin-copy-assets'
cause Package not installed or devDependencies not installed.
fix
Run npm install --save-dev rollup-plugin-copy-assets or yarn add --dev rollup-plugin-copy-assets.
error TypeError: copy is not a function
cause Incorrect import: using a named import instead of default import.
fix
Use import copy from 'rollup-plugin-copy-assets' instead of import { copy } from 'rollup-plugin-copy-assets'.
error Error: The 'assets' option must be an array.
cause Passing a single string or non-array value for the assets option.
fix
Wrap the string in an array: { assets: ['src/assets'] }.
breaking v2.0.0 changed behavior: assets now overwrite existing files in output directory.
fix Update to v2.0.0+ if you want overwrite behavior; if you relied on old behavior (no overwrite), you may need to use a different plugin.
gotcha The `assets` option does not support glob patterns or relative paths outside the project root (e.g., '../foo').
fix Use absolute paths or paths relative to the project root. For glob patterns, consider rollup-plugin-copy (by rollup/plugins).
gotcha Plugin only copies at bundle generation (generateBundle hook), not during watch rebuilds of individual chunks?
fix No fix needed; understand that assets are copied once per build, not per watch rebuild if only chunks change. Use rollup-plugin-copy for more granular control.
deprecated The package is in maintenance mode with no recent updates; last release was 2.0.3 on 2019-08-19.
fix Consider using @rollup/plugin-copy from the official rollup/plugins monorepo, which is actively maintained.
npm install rollup-plugin-copy-assets
yarn add rollup-plugin-copy-assets
pnpm add rollup-plugin-copy-assets

Configures Rollup with the copy-assets plugin to copy a directory and a file to the output directory, preserving the relative structure.

// rollup.config.js
import copy from 'rollup-plugin-copy-assets';

export default {
  input: 'src/index.js',
  output: {
    dir: 'dist',
    format: 'cjs'
  },
  plugins: [
    copy({
      assets: [
        'src/assets',
        'src/external/buffer.bin'
      ]
    })
  ]
};