rollup-plugin-copy-merge

raw JSON →
1.0.3 verified Mon Apr 27 auth: no javascript

A Rollup plugin that copies files and folders with glob support and adds file merging capability on top of rollup-plugin-copy. Current version 1.0.3, stable, maintained. Key differentiator: allows merging multiple source files into a single destination file via the 'file' target property, unlike its predecessor. Requires Node >=14, ships TypeScript types, and relies on fs-extra, globby, and colorette as peer dependencies.

error Error: Cannot find module 'rollup-plugin-copy-merge'
cause Package not installed or missing from node_modules.
fix
Run: npm install rollup-plugin-copy-merge --save-dev
error TypeError: copy is not a function
cause Using CommonJS require without .default.
fix
Change to: const copy = require('rollup-plugin-copy-merge').default
error Error: ENOENT: no such file or directory, copyfile '...' -> '...'
cause Source path does not exist or glob matches nothing.
fix
Check src paths and ensure files exist; use absolute paths or adjust relative to project root.
breaking Plugin requires Rollup 2.x or later
fix Update Rollup to v2+ or use an older version of the plugin.
gotcha The 'file' target property only works for UTF-8 encoded files. Binary files merged into one will produce corrupt output.
fix Use 'file' only for text files; for binary assets, use 'dest' instead.
gotcha When using flatten: false, the directory structure from src is preserved in dest. This may cause unintended nested directories.
fix Set flatten: true (default) to ignore src directory structure.
deprecated The 'rename' option as a string renames only the last part of the path; for full control use a function.
fix Provide a function as rename: (name, ext, srcPath) => ...
breaking Globby ^11.1.0 requires Node >=10; older Node versions may fail.
fix Ensure Node >=14 as specified in engine requirement.
npm install rollup-plugin-copy-merge
yarn add rollup-plugin-copy-merge
pnpm add rollup-plugin-copy-merge

Shows basic plugin usage in rollup.config.js, including copying single files, merging globs into a single file, and using glob patterns.

// rollup.config.js
import copy from 'rollup-plugin-copy-merge'

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/js/*.js', file: 'dist/public/scripts.js' },
        { src: 'assets/images/**/*', dest: 'dist/public/images' }
      ]
    })
  ]
}