unplugin-copy
v1.0.1
Published
Copy files and folders, with glob support.
Downloads
20
Maintainers
Readme
unplugin-copy
Replace variables in code with other values or expressions. Supports Vite, Rollup, Webpack, Rspack and more.
NOTE
The original intention of this plugin is to provide compatibility for lower-level plugins. You should give priority to using the copy
that comes with the build tool.
Features
- Support Vite, Webpack, Vue CLI, Rollup, esbuild and more, powered by unplugin.
- In the Vite development environment, path mapping is used instead of real copying.
Install
npm i unplugin-copy -D
pnpm i unplugin-copy -D
yarn i unplugin-copy -D
Install
// vite.config.ts
import unpluginCopy from 'unplugin-copy/vite'
export default defineConfig({
plugins: [
unpluginCopy({
targets: [
// http://localhost:5173/vue/index.js => node_modules/vue/index.js
{
src: 'node_modules/vue/**',
dest: 'vue',
},
],
}),
],
})
// rollup.config.js
import unpluginCopy from 'unplugin-copy/rollup'
export default {
plugins: [
unpluginCopy({
targets: [
// http://localhost:5173/vue/index.js => node_modules/vue/index.js
{
src: 'node_modules/vue/**',
dest: 'vue',
},
],
}),
],
}
// webpack.config.js
module.exports = {
/* ... */
plugins: [
unpluginCopy({
targets: [
// http://localhost:5173/vue/index.js => node_modules/vue/index.js
{
src: 'node_modules/vue/**',
dest: 'vue',
},
],
}),
]
}
// nuxt.config.js
export default {
buildModules: [
['unplugin-copy/nuxt', {
targets: [
// http://localhost:5173/vue/index.js => node_modules/vue/index.js
{
src: 'node_modules/vue/**',
dest: 'vue',
},
],
}],
],
}
This module works for both Nuxt 2 and Nuxt Vite
// vue.config.js
module.exports = {
configureWebpack: {
plugins: [
require('unplugin-copy/webpack')({
targets: [
// http://localhost:5173/vue/index.js => node_modules/vue/index.js
{
src: 'node_modules/vue/**',
dest: 'vue',
},
],
}),
],
},
}
// esbuild.config.js
import { build } from 'esbuild'
import unpluginCopy from 'unplugin-copy/esbuild'
build({
plugins: [
unpluginCopy({
targets: [
// http://localhost:5173/vue/index.js => node_modules/vue/index.js
{
src: 'node_modules/vue/**',
dest: 'vue',
},
],
}),
],
})
The code idea comes from vite-plugin-static-copy.