Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/michaeljier/easy-alioss
A plugin to upload assets to aliyun oss
https://github.com/michaeljier/easy-alioss
ali-oss alioss assets oss vite vite-plugin vite4 webpack webpack-plugin webpack5-plugin
Last synced: 5 days ago
JSON representation
A plugin to upload assets to aliyun oss
- Host: GitHub
- URL: https://github.com/michaeljier/easy-alioss
- Owner: MIchaelJier
- License: mit
- Created: 2020-10-20T08:29:58.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2023-10-17T01:58:51.000Z (about 1 year ago)
- Last Synced: 2024-09-12T11:12:16.523Z (2 months ago)
- Topics: ali-oss, alioss, assets, oss, vite, vite-plugin, vite4, webpack, webpack-plugin, webpack5-plugin
- Language: TypeScript
- Homepage: https://www.npmjs.com/search?q=%40easy-alioss
- Size: 1.12 MB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# easy-alioss
[![npm version](https://img.shields.io/npm/v/@easy-alioss/vite-plugin.svg?style=flat)]([https://www.npmjs.com/package/svga](https://www.npmjs.com/package/@easy-alioss/vite-plugin))
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://reactjs.org/docs/how-to-contribute.html#your-first-pull-request)
[![license](https://img.shields.io/badge/license-MIT-blue.svg)]([https://github.com/NetEase/tango/blob/main/LICENSE](https://github.com/MIchaelJier/easy-alioss/blob/main/LICENSE))A plugin to upload assets to aliyun oss
## 安装
```bash
# webpack
npm i @easy-alioss/webpack-plugin --save
# vite
npm i @easy-alioss/vite-plugin --save
```
## 参数# AliOSSConfig
| name | type | optional | default | description |
| - | - | - | - | - |
| accessKeyId | `string` | `false` | `n/a` | 阿里云 accessKeyId |
| accessKeySecret | `string` | `false` | `n/a` | 阿里云 accessKeySecret |
| region | `string` | `false` | `n/a` | 阿里云 region |
| bucket | `string` | `false` | `n/a` | 阿里云 bucket |
| prefix | `string \| undefined` | `true` | `''` | 自定义路径前缀,通常使用项目目录名,文件将存放在alioss的bucket/prefix目录下 |
| exclude | `RegExp \| RegExp[] \| undefined` | `true` | `[/.*\.html$/]` | 可传入正则,或正则组成的数组,来排除上传的文件 |
| deleteAll | `boolean \| undefined` | `true` | `n/a` | 是否删除bucket/prefix中所有文件。优先匹配format配置 |
| local | `boolean \| undefined` | `true` | `false` | 默认每次上传webpack构建流中文件,设为true可上传打包后webpack output指向目录里的文件 |
| output | `string \| undefined` | `true` | `''` | 读取本地目录的路径,如果local为true,output为空,默认为读取webpack输出目录 |
| limit | `number \| undefined` | `true` | `5` | 最多备份版本数量,会备份最近的版本,最小是3。配置了format才会生效 |
| format | `string \| undefined` | `true` | `getFormat('YYMMDD')` | 用时间戳来生成oss目录版本号,每次会保留最近的版本文件做零宕机发布,删除其他版本文件。可以通过插件自身提供的静态方法getFormat()获得,默认值为年月日 |## 使用
* 实例传参
```javascript
const WebpackAliOSSPlugin = require('@easy-alioss/webpack-plugin')new WebpackAliOSSPlugin({
accessKeyId: '2****************9',
accessKeySecret: 'z**************=',
region: 'oss-cn-hangzhou',
bucket: 'xxx',
prefix: 'test',
})
```
* 配置文件
```javascriptconst WebpackAliOSSPlugin = require('@easy-alioss/webpack-plugin')
const format = WebpackAliOSSPlugin.getFormat('YYYYMMDD') // 默认为getFormat('YYMMDD')
new WebpackAliOSSPlugin({
format
})// easy-alioss.config.json
{
accessKeyId: '2****************9',
accessKeySecret: 'z**************=',
region: 'oss-cn-hangzhou',
bucket: 'xxx',
prefix: 'test',
}
```
> 更多格式参考[cosmiconfig](https://github.com/cosmiconfig/cosmiconfig#readme)
> By default, Cosmiconfig will start where you tell it to start and search up the directory tree for the following:
> - a package.json property
> - a JSON or YAML, extensionless "rc file"
> - an "rc file" with the extensions .json, .yaml, .yml, .js, .ts, .mjs, or .cjs
> - any of the above two inside a .config subdirectory
> - a .config.js, .config.ts, .config.mjs, or .config.cjs file