vite-oss-plugin
v1.0.1
Published
vite打包上传到OSS
Downloads
16
Readme
安装
pnpm i -D vite-oss-plugin
或者
yarn add -D vite-oss-plugin
或者
npm i -D vite-oss-plugin
基本配置
| options | description | type | default |
| ---- | ---- |--------------| ---- |
| region | 阿里云 oss 地域 | string | |
| accessKeyId | 阿里云 oss 访问ID | string | |
| accessKeySecret | 阿里云 oss 访问秘钥 | string | |
| bucket | 阿里云 oss 存储空间名称 | string | |
| overwrite | 如果文件存在,是否覆盖 | booean | |
| ignore | 文件忽略规则。如果你使用空字符串 '' ,将不会忽略任何文件 | string | '' |
| headers | 请求头设置,详细信息见 https://help.aliyun.com/document_detail/31955.html | object | {} |
| enabled | 是否启用本插件 | boolean | true |
| ... | 其它初始化的参数,详细信息请见 https://help.aliyun.com/document_detail/64097.html | any | |
使用方法
1、在 vite.config.js 中注册本插件
2、设置 base 开发或生产环境服务的公共基础 URL 路径
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vitePluginAliOss from 'vite-plugin-ali-oss'
const options = {
region: '<Your Region>'
accessKeyId: '<Your Access Key ID>',
accessKeySecret: '<Your Access Key Secret>',
bucket: '<Your Bucket>'
}
const prod = process.env.NODE_ENV === 'production'
// https://vitejs.dev/config/
export default defineConfig({
base: prod ? 'https://foo.com/' : '/', // 打包时必须是 URL
plugins: [vue(), vitePluginAliOss(options)]
})
上传到 oss 特定目录下,只要直接设置 base:
base: prod ? 'https://foo.com/yourpath/etc/' : '/'
3、打包发布生产代码
yarn build