Giter Club home page Giter Club logo

easy-alioss's Introduction

easy-alioss

npm version PRs Welcome license

A plugin to upload assets to aliyun oss

安装

# 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()获得,默认值为年月日

使用

  • 实例传参
const WebpackAliOSSPlugin = require('@easy-alioss/webpack-plugin')

new WebpackAliOSSPlugin({
  accessKeyId: '2****************9',
  accessKeySecret: 'z**************=',
  region: 'oss-cn-hangzhou',
  bucket: 'xxx',
  prefix: 'test',  
})
  • 配置文件
const 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 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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.