-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
58 lines (50 loc) · 1.32 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
const _ = require('lodash')
const QiniuPlugin = require('./qiniu')
// 默认配置
const defaultOptions = {
isDisable: false,
batch: 20,
path: '[hash]',
exclude: /index\.html$/ // 排除特定的文件
}
/**
*
* vayne qiniu 七牛云上传插件
* @param {any} config vayne 配置
* @param {any} log vayne log
* @param {any} utils vayne 工具库
* @returns webpack qiniu plugins
*/
class VaynePluginQiniu {
constructor(config, log, utils) {
log.debug('开始解析 vayne qiniu 插件')
let qiniu = config.qiniu || {}
let opts = _.assign(defaultOptions, qiniu)
opts.log = log
log.debug(opts)
this.name = 'VaynePluginQiniu'
if (opts.isDisable) {
log.warn('VaynePluginQiniu 插件以被禁用 可设置isDisable 未false 开启 ')
return {}
}
// 校验必填的列
const vaildField = ['accessKey', 'secretKey', 'bucket', 'path']
vaildField.forEach(field => {
let val = opts[field]
if (_.isUndefined(val)) {
log.fatal(`VaynePluginQiniu 插件 参数${field} 必须填写`)
}
})
const qiniuPlugin = new QiniuPlugin(opts)
let result = {
}
// 生产环境 才会具有此插件
if (utils.isProduction()) {
result.afterPlugins = [
qiniuPlugin
]
}
return result
}
}
module.exports = VaynePluginQiniu