copy-webpack-plugin

raw JSON →
14.0.0 verified Sat Apr 25 auth: no javascript

Copy individual files or entire directories to the webpack build output directory. Useful for static assets that are not processed by webpack loaders. Latest stable version is 14.0.0 (March 2026), requiring Node.js >= 20.9.0 and webpack ^5.1.0. Developed under the webpack organization, it supports patterns with globs, transform functions, filtering, and concurrency control. Ships TypeScript types. Replaced globby/fast-glob with tinyglobby in v13, and serialization library for security fixes in v14.

error Error: Cannot find module 'copy-webpack-plugin'
cause Plugin is not installed, or installed as a devDependency but not available in the production environment.
fix
Run 'npm install copy-webpack-plugin --save-dev' and ensure it's in your package.json.
error TypeError: CopyPlugin is not a constructor
cause Using import { CopyPlugin } from 'copy-webpack-plugin' instead of default import.
fix
Use 'const CopyPlugin = require("copy-webpack-plugin");' or 'import CopyPlugin from "copy-webpack-plugin";'
error ValidationError: Invalid options object. CopyPlugin has been initialized using an options object that does not match the API schema.
cause Passing 'from' and 'to' directly to the plugin instead of inside a 'patterns' array.
fix
Wrap your configuration in a 'patterns' array: new CopyPlugin({ patterns: [{ from: '...', to: '...' }] })
error Error: No matching files found for pattern '...'.
cause Glob pattern does not match any files, or the 'context' is incorrect.
fix
Check your glob pattern and context directory. Ensure the path is relative to the context (defaults to webpack's context).
breaking Minimum Node.js version increased to 20.9.0 in v14.0.0
fix Upgrade Node.js to version 20.9.0 or higher.
breaking Switched from globby and fast-glob to tinyglobby in v13.0.0 - glob patterns may behave differently
fix Review tinyglobby documentation for pattern syntax changes. Patterns that worked with globby/fast-glob might need adjustment.
breaking Minimum Node.js version raised to 18.12.0 in v12.0.0
fix Upgrade Node.js to version 18.12.0 or higher, or stay on v11.x if Node 14 is required.
breaking Minimum Node.js version increased to 14.15.0 in v11.0.0
fix Upgrade Node.js to version 14.15.0 or higher.
deprecated The 'transform' function receives different arguments in v13+ (using tinyglobby) vs older versions
fix Check the transform function's arguments in the documentation; the file path and source may be passed differently.
gotcha Using backslashes in 'from' glob patterns breaks on Unix systems
fix Always use forward slashes (/) in glob patterns. Use path.posix.join for absolute globs.
gotcha plugin does not copy files generated during build; only copies existing files from source tree
fix Use webpack's own asset handling or write-to-disk plugins for files output by loaders/plugins.
npm install copy-webpack-plugin
yarn add copy-webpack-plugin
pnpm add copy-webpack-plugin

Basic webpack config using copy-webpack-plugin to copy static files, a single vendor library, and HTML files with glob options.

const CopyPlugin = require('copy-webpack-plugin');
const path = require('path');

module.exports = {
  mode: 'production',
  entry: './src/index.js',
  output: {
    path: path.resolve(__dirname, 'dist'),
    filename: 'bundle.js',
  },
  plugins: [
    new CopyPlugin({
      patterns: [
        { from: 'static', to: 'assets' },
        { from: 'node_modules/some-lib/dist/some.min.js', to: 'lib.js' },
        { from: '*.html', context: 'src', globOptions: { ignore: ['**/ignored/**'] } },
      ],
      options: { concurrency: 50 },
    }),
  ],
};