# vite-oss-plugin **Repository Path**: mrhy/vite-oss-plugin ## Basic Information - **Project Name**: vite-oss-plugin - **Description**: vite打包上传OSS托管 - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2022-08-26 - **Last Updated**: 2023-08-15 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 安装 ```shell pnpm i -D vite-oss-plugin ``` 或者 ```shell yarn add -D vite-oss-plugin ``` 或者 ```shell 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 路径 ```javascript import { defineConfig } from 'vite' import vue from '@vitejs/plugin-vue' import viteOssPlugin from 'vite-oss-plugin' const options = { region: '' accessKeyId: '', accessKeySecret: '', bucket: '' } const prod = process.env.NODE_ENV === 'production' // https://vitejs.dev/config/ export default defineConfig({ base: prod ? 'https://foo.com/' : '/', // 打包时必须是 URL plugins: [vue(), viteOssPlugin(options)] }) ``` 上传到 oss 特定目录下,只要直接设置 base: ```javascript base: prod ? 'https://foo.com/yourpath/etc/' : '/' ``` 3、打包发布生产代码 ```shell yarn build ```