vue-cli-plugin-ali-oss
Advanced tools
Comparing version
{ | ||
"name": "vue-cli-plugin-ali-oss", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"private": false, | ||
@@ -14,3 +14,3 @@ "description": "upload ali oss for webpack or vue", | ||
"serve": "vue-cli-service serve", | ||
"build": "rm -rf dist && vue-cli-service build", | ||
"build": "vue-cli-service build", | ||
"test:unit": "vue-cli-service test:unit", | ||
@@ -27,3 +27,4 @@ "test:e2e": "vue-cli-service test:e2e", | ||
"chalk": "^4.1.0", | ||
"consola": "^2.15.0" | ||
"consola": "^2.15.0", | ||
"webpack-sources": "^3.2.3" | ||
}, | ||
@@ -76,4 +77,7 @@ "devDependencies": { | ||
"plugin", | ||
"assets" | ||
"alioss", | ||
"upload", | ||
"project", | ||
"deploy" | ||
] | ||
} |
@@ -8,3 +8,3 @@ /* | ||
* @LastEditors: lax | ||
* @LastEditTime: 2021-01-03 18:59:39 | ||
* @LastEditTime: 2022-06-05 11:42:17 | ||
*/ | ||
@@ -14,7 +14,10 @@ const path = require("path"); | ||
const options = require(path.join(__dirname, "./options.js")); | ||
const PLUGIN_NAME = "aliOssPlugin"; | ||
const Oss = require("ali-oss"); | ||
const { RawSource } = require("webpack-sources"); | ||
let client; | ||
const MSG = require(path.join(__dirname, "./message.js")); | ||
const getPrefix = require(path.join(__dirname, "./getPrefix")); | ||
const DEFAULT_REG = /\.(png|jpe?g|bmp|gif|mp4|webm)/i; | ||
const DEFAULT_REG = /\.(png|jpe?g|bmp|gif|mp4|webm|mp3|js|css|json|ico|txt)/; | ||
class AliOss { | ||
@@ -27,4 +30,6 @@ constructor(p = {}) { | ||
this.use = p.use !== undefined ? p.use : true; | ||
// ali oss config | ||
this.config = p.config || {}; | ||
// plugin name | ||
this.name = "TaoAliOssPlugin"; | ||
this.name = PLUGIN_NAME; | ||
} | ||
@@ -42,11 +47,6 @@ apply(compiler) { | ||
compiler.hooks.afterEmit.tapAsync(this.name, (compilation, callback) => { | ||
// get all assets | ||
const baseAssets = compilation.getAssets(); | ||
// assets list by reg | ||
baseAssets.map((obj) => { | ||
console.log(obj.name); | ||
}); | ||
const assets = baseAssets.filter((asset) => this.REG.test(asset.name)); | ||
const assets = this.getAssets(compilation); | ||
// skip it when can`t find assets | ||
if (!assets.length) callback(); | ||
// img promise | ||
@@ -67,3 +67,3 @@ const promises = assets.map(async (asset) => { | ||
try { | ||
await client.put(fullName, asset.source._value); | ||
await client.put(fullName, Buffer.from(asset.source.source())); | ||
MSG.EACH_MSG(asset.name, true); | ||
@@ -74,2 +74,15 @@ } catch (error) { | ||
} | ||
getAssets(compilation) { | ||
// get all assets | ||
const _assets = compilation.getAssets(); | ||
// img list by reg | ||
const assets = _assets.filter( | ||
(asset) => | ||
this.REG.test(asset.name) && | ||
(asset.source instanceof RawSource | ||
? asset.source._value !== undefined | ||
: true) | ||
); | ||
return assets; | ||
} | ||
_getPackage(comp) { | ||
@@ -85,3 +98,3 @@ const json = require(path.join(comp.context, "./package.json")); | ||
// new (options) | ||
this.p, | ||
this.p.config, | ||
// file options | ||
@@ -99,3 +112,3 @@ this._getOptionsFromFile(comp) | ||
MSG.FILE_ERROR_MSG(); | ||
throw error; | ||
// throw error; | ||
} | ||
@@ -143,2 +156,4 @@ return options; | ||
} | ||
AliOss.getPrefix = getPrefix; | ||
module.exports = AliOss; |
@@ -7,3 +7,3 @@ /* | ||
* @LastEditors: lax | ||
* @LastEditTime: 2021-01-03 17:24:44 | ||
* @LastEditTime: 2022-06-05 11:44:20 | ||
* @FilePath: \vue-cli-plugin-ali-oss\packages\message.js | ||
@@ -34,6 +34,5 @@ */ | ||
log(""); | ||
log(Chalk.redBright("############################################")); | ||
log(Chalk.redBright("can`t find options in oss.js")); | ||
log(Chalk.redBright("skip this plugin...")); | ||
log(Chalk.redBright("############################################")); | ||
log(Chalk.yellowBright("############################################")); | ||
log(Chalk.yellowBright("can`t find options or oss.js not exist, skip..")); | ||
log(Chalk.yellowBright("############################################")); | ||
}, | ||
@@ -40,0 +39,0 @@ CLIENT_ERROR_MSG() { |
@@ -7,7 +7,7 @@ <!-- | ||
* @LastEditors: lax | ||
* @LastEditTime: 2021-01-03 18:40:26 | ||
* @LastEditTime: 2022-06-05 11:50:22 | ||
--> | ||
# 简介 | ||
实现阿里云oss打包后自动上传 | ||
* 实现web项目打包后自动上传阿里云oss | ||
* 搭配自动tinypng图片压缩插件[vue-tinypng-plugin](https://www.npmjs.com/package/vue-tinypng-plugin)效果更佳 | ||
# 使用说明 | ||
@@ -33,9 +33,12 @@ | ||
2.或者在插件初始化写入配置(优先级中) | ||
* 注意!!! 1.0.3版本之后需要包含在config里 | ||
``` | ||
new tinypngPlugin({ | ||
accessKeyId: "xxx", | ||
accessKeySecret: "xxx", | ||
bucket: "bucket", | ||
prefix: "prefix", | ||
projectName: true, | ||
config:{ | ||
accessKeyId: "xxx", | ||
accessKeySecret: "xxx", | ||
bucket: "bucket", | ||
prefix: "prefix", | ||
projectName: true, | ||
} | ||
}) | ||
@@ -54,2 +57,6 @@ ``` | ||
``` | ||
# 路径顺序 | ||
``` | ||
https://${bucket}.${region}.aliyuncs.com/${prefix}/${projectName}/XXXX | ||
``` | ||
@@ -115,3 +122,3 @@ # 配置属性 | ||
可识别的正则 | ||
默认: /\.(png|jpe?g|bmp|gif|mp4|webm)/i | ||
默认: /\.(png|jpe?g|bmp|gif|mp4|webm|mp3)/i | ||
``` | ||
@@ -118,0 +125,0 @@ reg: XXXX |
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
10053
7.95%228
5.56%126
5.88%4
33.33%6
20%+ Added
+ Added