@col0ring/vite-plugin-copy
v1.0.2
Published
A vite plugin for copying dirs or files after building.
Downloads
853
Readme
Vite-Plugin-Copy
A vite plugin for copying dirs or files after building.
Install
npm install @col0ring/vite-plugin-copy -D
# or
yarn add @col0ring/vite-plugin-copy -D
Usage
import { defineConfig } from 'vite'
import path from 'path'
import viteCopyPlugin from '@col0ring/vite-plugin-copy'
function resolve(relativePath: string) {
return path.resolve(__dirname, relativePath)
}
export default defineConfig({
plugins: [
// ...
viteCopyPlugin([
{
src: resolve('./dist/index.html'),
target: resolve('./dist/index2.html')
}
])
]
})
The src
and target
options can accept arrays:
import { defineConfig } from 'vite'
import path from 'path'
import viteCopyPlugin from '@col0ring/vite-plugin-copy'
function resolve(relativePath: string) {
return path.resolve(__dirname, relativePath)
}
export default defineConfig({
plugins: [
// ...
viteCopyPlugin([
{
src: resolve('./dist/index.html'),
target: [resolve('./dist/index2.html'), resolve('./dist/index3.html')]
}
])
]
})
import { defineConfig } from 'vite'
import path from 'path'
import viteCopyPlugin from '@col0ring/vite-plugin-copy'
function resolve(relativePath: string) {
return path.resolve(__dirname, relativePath)
}
export default defineConfig({
plugins: [
// ...
viteCopyPlugin([
{
src: [resolve('./dist/index.html'), resolve('./dist/assets')],
target: [resolve('./dist/dist2'), resolve('./dist/dist3')]
}
])
]
})
The disk path supports glob
:
import { defineConfig } from 'vite'
import path from 'path'
import viteCopyPlugin from '@col0ring/vite-plugin-copy'
function resolve(relativePath: string) {
return path.resolve(__dirname, relativePath)
}
export default defineConfig({
plugins: [
// ...
viteCopyPlugin([
{
// move all files in the src directory to the target directory
src: resolve('./dist/assets/**/*'),
target: resolve('./dist/assets2')
}
])
]
})
Usually, the plugin will automatically recognize whether the copy is a directory or a file, but you can still specify it manually:
import { defineConfig } from 'vite'
import path from 'path'
import viteCopyPlugin from '@col0ring/vite-plugin-copy'
function resolve(relativePath: string) {
return path.resolve(__dirname, relativePath)
}
export default defineConfig({
plugins: [
// ...
viteCopyPlugin([
{
// this is a file
src: resolve('./dist/file'),
target: {
isDir: false,
path: resolve('./dist/file2')
}
}
])
]
})
Delare
function vitePluginCopy(
options: CopyOptions[],
globOptions?: glob.IOptions
): Plugin
CopyOptions
src
- Type:
string | string[]
Resource file or directory.
target
- Type:
string | string[] | TargetObject | TargetObject[]
Target file or directory.
interface TargetObject {
isDir?: boolean
path: string
}
glob.IOptions
Custom glob configuration.