{"id":22620,"library":"vite-plugin-copy2","title":"vite-plugin-copy2","description":"A Vite plugin for copying single or multiple files during the build process. Current stable version is 1.1.0. It is a lightweight alternative to rollup-plugin-copy, specifically designed for Vite's build pipeline. The plugin supports copying files and folders before or after the build, with glob patterns and renaming. It provides a simple API by passing an array of source-destination pairs. Unlike other copy plugins, it integrates seamlessly with Vite's plugin system and respects the build lifecycle.","status":"active","version":"1.1.0","language":"javascript","source_language":"en","source_url":"https://github.com/qinzhuguang/vite-plugin-copy2","tags":["javascript","vite","copy","vite-plugin","vite-copy","vite-plugin-copy","vite-plugin-copy2"],"install":[{"cmd":"npm install vite-plugin-copy2","lang":"bash","label":"npm"},{"cmd":"yarn add vite-plugin-copy2","lang":"bash","label":"yarn"},{"cmd":"pnpm add vite-plugin-copy2","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"The plugin is designed to be used as a Vite plugin and requires Vite as a peer dependency.","package":"vite","optional":false}],"imports":[{"note":"The package is ESM-only; CommonJS require is not supported. Must use ES import.","wrong":"const VitePluginCopy = require('vite-plugin-copy2')","symbol":"VitePluginCopy","correct":"import { VitePluginCopy } from 'vite-plugin-copy2'"},{"note":"The package does not have a default export; only named export VitePluginCopy is available.","wrong":"import VitePluginCopy from 'vite-plugin-copy2'","symbol":"default import","correct":"import { VitePluginCopy } from 'vite-plugin-copy2'"},{"note":"TypeScript types are included. No separate @types package needed.","wrong":"","symbol":"TypeScript","correct":"import { VitePluginCopy } from 'vite-plugin-copy2'"}],"quickstart":{"code":"// vite.config.ts\nimport { defineConfig } from 'vite'\nimport vue from '@vitejs/plugin-vue'\nimport { VitePluginCopy } from 'vite-plugin-copy2'\n\nexport default defineConfig({\n  plugins: [\n    vue(),\n    VitePluginCopy([\n      { src: ['demo/a.js', 'demo/b.js'], dest: 'dist/' },\n      { src: 'demo/c.js', dest: 'dist/static/' },\n      { src: 'node_modules', dest: 'dist/node_modules' }\n    ])\n  ]\n})","lang":"typescript","description":"Shows how to configure the plugin in a Vite config file to copy multiple files and folders during the build."},"warnings":[{"message":"The plugin only works with Vite's build pipeline; it does not function during dev server. Source files are copied only at build time.","severity":"breaking","affected_versions":">=1.0.0"},{"message":"","severity":"deprecated","affected_versions":">=1.0.0"},{"message":"If a source file does not exist, the plugin may throw an error and fail the build. Ensure all source paths are correct.","severity":"gotcha","affected_versions":">=1.0.0"},{"message":"The dest path must be relative to the project root. Absolute paths may not work as expected.","severity":"gotcha","affected_versions":">=1.0.0"},{"message":"When copying a folder, the entire directory structure is preserved; use the 'rename' option to flatten if needed.","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-copy2 -D' or 'yarn add vite-plugin-copy2 -D'.","cause":"Package not installed or not listed in devDependencies.","error":"Error: Cannot find module 'vite-plugin-copy2'"},{"fix":"Use 'import { VitePluginCopy } from 'vite-plugin-copy2'' instead of 'import VitePluginCopy from ...'.","cause":"Using default import instead of named import.","error":"TypeError: VitePluginCopy is not a function"},{"fix":"This is not an error; if you need file copying during dev, use a different approach or configure separate dev copy logic.","cause":"Expected behavior: plugin is only active during build.","error":"Error: The plugin only works in build mode. Skipping during dev."},{"fix":"Verify that all source paths are correct and exist. Use absolute or correct relative paths.","cause":"The source file or folder specified in the config does not exist.","error":"Error: ENOENT: no such file or directory, stat 'path/to/source'"},{"fix":"Ensure each copy entry has a 'dest' property that is a string.","cause":"dest field missing or not a string in one of the copy entries.","error":"Error: The 'dest' option must be a string"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}