copy-vite-plugin

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

A Vite plugin for copying files and directories during build, designed as a drop-in replacement for copy-webpack-plugin for projects migrating from webpack to Vite. Current version 1.0.1 (stable). It offers a simple API similar to copy-webpack-plugin, supporting glob patterns and multiple source destinations. Unlike alternatives like vite-plugin-static-copy, it aims for minimal configuration and direct compatibility with webpack's pattern syntax.

error TypeError: copy is not a function
cause Importing using default import instead of named import.
fix
Use 'import { copy } from 'copy-vite-plugin' instead of 'import copy from 'copy-vite-plugin'.
error Pattern is not iterable
cause Options object has 'patterns' key instead of 'pattern'.
fix
Rename 'patterns' to 'pattern' in the plugin options.
error ENOENT: no such file or directory, copyfile '...' -> '...'
cause The source file or directory does not exist, or path is relative and resolved incorrectly.
fix
Ensure paths are relative to project root or use absolute paths.
gotcha The 'pattern' key is singular; using 'patterns' (as in copy-webpack-plugin) will silently be ignored.
fix Use 'pattern' instead of 'patterns' in the options object.
gotcha Relative paths in 'from' and 'to' are resolved relative to the project root (process.cwd()), not the config file location.
fix Use absolute paths or paths relative to project root.
gotcha Plugin only runs during build (not dev server) by default; files copied are not watched.
fix Use 'vite-plugin-static-copy' if you need copy during dev with HMR.
deprecated The 'context' option from copy-webpack-plugin is not supported; use absolute paths instead.
fix Use full paths or rely on root-relative paths.
gotcha Glob patterns in 'from' are not supported; use exact file or directory paths.
fix Specify exact paths or use another plugin like 'vite-plugin-static-copy' that supports globs.
npm install copy-vite-plugin
yarn add copy-vite-plugin
pnpm add copy-vite-plugin

Basic setup: copies a directory and a file from source to output during build.

import { defineConfig } from 'vite';
import { copy } from 'copy-vite-plugin';

export default defineConfig({
  plugins: [
    copy({
      pattern: [
        { from: 'src/images', to: 'images' },
        { from: 'public/favicon.ico', to: 'favicon.ico' },
      ],
    }),
  ],
});