{"id":22621,"library":"vite-plugin-cp","title":"vite-plugin-cp","description":"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.","status":"active","version":"6.0.3","language":"javascript","source_language":"en","source_url":"https://github.com/fengxinming/vite-plugins","tags":["javascript","vite","vite-plugin","vite-plugin-cp","typescript"],"install":[{"cmd":"npm install vite-plugin-cp","lang":"bash","label":"npm"},{"cmd":"yarn add vite-plugin-cp","lang":"bash","label":"yarn"},{"cmd":"pnpm add vite-plugin-cp","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency required for plugin integration","package":"vite","optional":false}],"imports":[{"note":"The plugin is exported as default. Named export 'cp' does not exist.","wrong":"import { cp } from 'vite-plugin-cp'","symbol":"default","correct":"import cp from 'vite-plugin-cp'"},{"note":"Type import only. PluginOptions is a TypeScript interface.","wrong":"import { PluginOptions } from 'vite-plugin-cp'","symbol":"PluginOptions","correct":"import type { PluginOptions } from 'vite-plugin-cp'"},{"note":"CommonJS require returns the default export, not an object with cp property.","wrong":"const { cp } = require('vite-plugin-cp')","symbol":"require","correct":"const cp = require('vite-plugin-cp')"}],"quickstart":{"code":"import { defineConfig } from 'vite';\nimport cp from 'vite-plugin-cp';\n\nexport default defineConfig({\n  plugins: [\n    cp({\n      targets: [\n        { src: './node_modules/vite/dist/**/*', dest: 'dist/cp', flatten: true },\n        { src: './README.md', dest: 'dist/', rename: 'README_COPY.md' },\n        {\n          src: './manifest.json',\n          dest: 'dist/',\n          transform(buf) {\n            const manifest = JSON.parse(buf.toString());\n            manifest.buildDate = new Date().toISOString();\n            return JSON.stringify(manifest, null, 2);\n          }\n        }\n      ]\n    })\n  ]\n});","lang":"typescript","description":"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."},"warnings":[{"fix":"Migrate to targets array with src/dest pairs.","message":"v6.0.0 dropped support for the 'copyDir' and 'copyFile' options; use 'targets' array instead.","severity":"breaking","affected_versions":"<6.0.0"},{"fix":"Use default import: import cp from 'vite-plugin-cp'.","message":"v5.0.0 changed the export from named to default. Code using 'import { cp } from 'vite-plugin-cp'' will break.","severity":"breaking","affected_versions":">=5.0.0"},{"fix":"Remove the 'watch' option from plugin config.","message":"The 'watch' option is deprecated and will be removed in v7. Use Vite's built-in watch mode.","severity":"deprecated","affected_versions":">=6.0.0"},{"fix":"Ensure transform function always returns a Buffer or string.","message":"Transform function must return a Buffer or string; returning null or undefined will cause silent failure.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Prefix globs with './' and ensure they match from project root.","message":"Glob patterns are relative to project root, not the src file location. Use absolute paths or './' for clarity.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use 'rename' to avoid conflicts or avoid flattening.","message":"When using 'flatten: true', if multiple source files have the same name, only the last one copied wins (overwrites).","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Run 'npm install vite-plugin-cp --save-dev'.","cause":"Package not installed or missing from devDependencies.","error":"Error: Cannot find module 'vite-plugin-cp'"},{"fix":"Change to 'import cp from 'vite-plugin-cp''","cause":"Using named import 'cp' instead of default import.","error":"TypeError: cp is not a function"},{"fix":"Ensure each target object has both 'src' and 'dest' properties.","cause":"Missing 'src' property in a targets entry.","error":"Error: \"src\" must be provided for each target"},{"fix":"Verify that the source path is correct and exists relative to project root.","cause":"The source file or directory does not exist.","error":"Error: [vite-plugin-cp] ENOENT: no such file or directory, lstat '...'"},{"fix":"Ensure transform returns a Buffer or string, e.g., return Buffer.from('...').","cause":"Transform function returned undefined or null.","error":"Error: [vite-plugin-cp] Transform must return a Buffer or string"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}