Registry / devops / vite-plugin-copy2

vite-plugin-copy2

JSON →
library1.1.0jsnpmunverified

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.

npm install vite-plugin-copy2
INSTALL
IMPORT
SIG · VITE-PLUGIN-COPY2
V
vite-plugin-copy2
devopsjavascriptv1.1.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
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 18223 runs
build_error
glibc
node 18223 runs
build_error
Code
Verified usage

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

VitePluginCopy
import { VitePluginCopy } from 'vite-plugin-copy2'
const VitePluginCopy = require('vite-plugin-copy2')
The package is ESM-only; CommonJS require is not supported. Must use ES import.
default import
import { VitePluginCopy } from 'vite-plugin-copy2'
import VitePluginCopy from 'vite-plugin-copy2'
The package does not have a default export; only named export VitePluginCopy is available.
TypeScript
import { VitePluginCopy } from 'vite-plugin-copy2'
TypeScript types are included. No separate @types package needed.

Shows how to configure the plugin in a Vite config file to copy multiple files and folders during the build.

// vite.config.ts import { defineConfig } from 'vite' import vue from '@vitejs/plugin-vue' import { VitePluginCopy } from 'vite-plugin-copy2' export default defineConfig({ plugins: [ vue(), VitePluginCopy([ { src: ['demo/a.js', 'demo/b.js'], dest: 'dist/' }, { src: 'demo/c.js', dest: 'dist/static/' }, { src: 'node_modules', dest: 'dist/node_modules' } ]) ] })
Debug
Known issues
breakingThe plugin only works with Vite's build pipeline; it does not function during dev server. Source files are copied only at build time.
affects: >=1.0.0
deprecated
affects: >=1.0.0
gotchaIf a source file does not exist, the plugin may throw an error and fail the build. Ensure all source paths are correct.
affects: >=1.0.0
gotchaThe dest path must be relative to the project root. Absolute paths may not work as expected.
affects: >=1.0.0
gotchaWhen copying a folder, the entire directory structure is preserved; use the 'rename' option to flatten if needed.
affects: >=1.0.0
Errors
Common errors & fixes
Error: Cannot find module 'vite-plugin-copy2'
Package not installed or not listed in devDependencies.
fix
Run 'npm install vite-plugin-copy2 -D' or 'yarn add vite-plugin-copy2 -D'.
TypeError: VitePluginCopy is not a function
Using default import instead of named import.
fix
Use 'import { VitePluginCopy } from 'vite-plugin-copy2'' instead of 'import VitePluginCopy from ...'.
Error: The plugin only works in build mode. Skipping during dev.
Expected behavior: plugin is only active during build.
fix
This is not an error; if you need file copying during dev, use a different approach or configure separate dev copy logic.
Error: ENOENT: no such file or directory, stat 'path/to/source'
The source file or folder specified in the config does not exist.
fix
Verify that all source paths are correct and exist. Use absolute or correct relative paths.
Error: The 'dest' option must be a string
dest field missing or not a string in one of the copy entries.
fix
Ensure each copy entry has a 'dest' property that is a string.
Upgrade
Version history
1.1.0latest on npm
Audit
Dependencies
viterequiredThe plugin is designed to be used as a Vite plugin and requires Vite as a peer dependency.
Agent activity
10 hits · last 30 days
node
8
OpenAI (training)
2
Resources
vite-plugin-copy2 — npm install vite-plugin-copy2 · libregistry