rollup-plugin-copy 是一个用于打包构建工具的插件,用于将指定的文件或目录从一个位置复制到另一个位置,支持glob。
# yarn
yarn add rollup-plugin-copy -D
or
# npm
npm install rollup-plugin-copy -D
or
cnpm install rollup-plugin-copy -D
// vite.config.js
import vue from '@vitejs/plugin-vue'
import copy from 'rollup-plugin-copy'
export default {
//...
plugins: [
vue(),
// copy({Object})
copy({
targets: [
{ src: 'src/index.html', dest: 'dist/public' },
{ src: ['assets/fonts/arial.woff', 'assets/fonts/arial.woff2'], dest: 'dist/public/fonts' },
{ src: 'assets/images/**/*', dest: 'dist/public/images' }
]
})
]
}
Array
| Default: [Object]
Object.src (string)
: 要复制内容的路径Object.dest (string)
: 要复制到的目标路径Object.rename (string Function)
: 更改目标文件或文件夹的名称Object.transform (Function)
: 修改文件内容copy({
targets: [{
src: 'src/index.html',
dest: 'dist/public',
rename: (name, extension, fullPath) => `${name}-v1.${extension}`
transform: (contents, filename) => contents.toString().replace('__SCRIPT__', 'app.js')
}]
})
boolean
| Default: false
copy({
targets: [{ src: 'assets/*', dest: 'dist/public' }],
verbose: true
})
string
| Default: buildEnd
copy({
targets: [{ src: 'assets/*', dest: 'dist/public' }],
hook: 'generateBundle' // npm run build 的时候执行copy
})
boolean
| Default: false
copy({
targets: [{ src: 'assets/*', dest: 'dist/public' }],
copyOnce: true
})
boolean
| Default: true
copy({
targets: [{ src: 'assets/**/*', dest: 'dist/public' }],
flatten: false
})