forked from luoxue-victor/workflow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
alias.js
33 lines (31 loc) · 874 Bytes
/
alias.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
// [别名配置]
module.exports = ({ config, options, resolve }) => {
const fs = require('fs')
const conf = options.alias
return () => {
// 生成默认别名
const dirs = fs.readdirSync(resolve('src'))
let aliasConfig = config.resolve
.extensions
.merge(['.mjs', '.js', '.jsx', '.vue', 'ts', '.json', '.wasm'])
.end()
.alias
dirs.forEach(v => {
const stat = fs.statSync(resolve(`src/${v}`))
if (stat.isDirectory()) {
aliasConfig = aliasConfig.set(`@${v}`, resolve(`src/${v}`))
}
})
// 用户配置别名
if (conf.alias) {
const keys = Object.keys(conf.alias)
keys.forEach(key => {
aliasConfig = aliasConfig.set(key, conf.alias[key])
})
}
// 自定义设置别名
aliasConfig
.set('@', resolve('src'))
.set('@src', resolve('src'))
}
}