@lx-frontend/oss-upload
v2.0.1
Published
ali oss upload static files
Downloads
16
Readme
@lx-frontend/oss-upload
阿里云 oss 上传 gulp 插件,方便前端资源上传到阿里云 oss
Usage
const gulp = require('gulp')
const { ossUpload } = require('@lx-frontend/oss-upload')
const argv = require('yargs').argv
// 上传cdn文件
function oss() {
const ACCESSKEYID = process.env.ACCESSKEYID
const ACCESSKEYSECRET = process.env.ACCESSKEYSECRET
// 缓存时间,默认一年
const maxAge = 3600 * 24 * 365
const options = {
prefix: argv.prefix,
ossCreateOptions: {
accessKeyId: ACCESSKEYID,
accessKeySecret: ACCESSKEYSECRET,
region: 'xxx', // 修改成对应项目的
bucket: 'xx' // 修改成对应项目的
},
ossPutOptions: { // 可选
headers: {
'Cache-Control': 'max-age=' + maxAge // 默认缓存一年
}
}
}
return gulp.src(['www/**/*.*', '!www/**/*.html']).pipe(ossUpload(options))
}
// gulp 3+ 与 node 12 不再兼容,采用 gulp 4+ 方式创建 task 任务
exports.oss = oss
TODO
- [ ] 补充测试 case ,难点需要找个临时 bucket 来测试。