Registry / devops / vite-plugin-cp

vite-plugin-cp

JSON →
library6.0.3jsnpmunverified

Vite plugin for copying files/directories during builds with advanced transformation and renaming. Supports glob patterns, flattening, rename functions, and transform buffers. Integrates with Vite's build pipeline. v6.0.3 requires Vite >=3.1.0 and Node >=14.18.0. Ships TypeScript types. Alternative to rollup-plugin-copy with Vite-native hooks and simpler API.

npm install vite-plugin-cp
INSTALL
IMPORT
SIG · VITE-PLUGIN-CP
V
vite-plugin-cp
devopsjavascriptv6.0.3
Install
—
Import
—
Disk
—
Pass rate
0/ 6
Env Coverage0 / 6
glibc
18–22
musl
18–22
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18–223 runs
build_error
glibc
node 18–223 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
✓ import cp from 'vite-plugin-cp'
✗ import { cp } from 'vite-plugin-cp'
The plugin is exported as default. Named export 'cp' does not exist.
PluginOptions
✓ import type { PluginOptions } from 'vite-plugin-cp'
✗ import { PluginOptions } from 'vite-plugin-cp'
Type import only. PluginOptions is a TypeScript interface.
require
✓ const cp = require('vite-plugin-cp')
✗ const { cp } = require('vite-plugin-cp')
CommonJS require returns the default export, not an object with cp property.

Configures vite-plugin-cp with three copy targets: a glob flatten copy, a single file rename, and a JSON transform that adds a build date.

import { defineConfig } from 'vite'; import cp from 'vite-plugin-cp'; export default defineConfig({ plugins: [ cp({ targets: [ { src: './node_modules/vite/dist/**/*', dest: 'dist/cp', flatten: true }, { src: './README.md', dest: 'dist/', rename: 'README_COPY.md' }, { src: './manifest.json', dest: 'dist/', transform(buf) { const manifest = JSON.parse(buf.toString()); manifest.buildDate = new Date().toISOString(); return JSON.stringify(manifest, null, 2); } } ] }) ] });
Debug
Known issues
breakingv6.0.0 dropped support for the 'copyDir' and 'copyFile' options; use 'targets' array instead.
fix
Migrate to targets array with src/dest pairs.
affects: <6.0.0
breakingv5.0.0 changed the export from named to default. Code using 'import { cp } from 'vite-plugin-cp'' will break.
fix
Use default import: import cp from 'vite-plugin-cp'.
affects: >=5.0.0
deprecatedThe 'watch' option is deprecated and will be removed in v7. Use Vite's built-in watch mode.
fix
Remove the 'watch' option from plugin config.
affects: >=6.0.0
gotchaTransform function must return a Buffer or string; returning null or undefined will cause silent failure.
fix
Ensure transform function always returns a Buffer or string.
affects: >=1.0.0
gotchaGlob patterns are relative to project root, not the src file location. Use absolute paths or './' for clarity.
fix
Prefix globs with './' and ensure they match from project root.
affects: >=1.0.0
gotchaWhen using 'flatten: true', if multiple source files have the same name, only the last one copied wins (overwrites).
fix
Use 'rename' to avoid conflicts or avoid flattening.
affects: >=1.0.0
Errors
Common errors & fixes
Error: Cannot find module 'vite-plugin-cp'
Package not installed or missing from devDependencies.
fix
Run 'npm install vite-plugin-cp --save-dev'.
TypeError: cp is not a function
Using named import 'cp' instead of default import.
fix
Change to 'import cp from 'vite-plugin-cp''
Error: "src" must be provided for each target
Missing 'src' property in a targets entry.
fix
Ensure each target object has both 'src' and 'dest' properties.
Error: [vite-plugin-cp] ENOENT: no such file or directory, lstat '...'
The source file or directory does not exist.
fix
Verify that the source path is correct and exists relative to project root.
Error: [vite-plugin-cp] Transform must return a Buffer or string
Transform function returned undefined or null.
fix
Ensure transform returns a Buffer or string, e.g., return Buffer.from('...').
Upgrade
Version history
6.0.3latest on npm
Audit
Dependencies
viterequiredPeer dependency required for plugin integration
Agent activity
6 hits · last 30 days
node
6
Resources