-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
aliases.config.js
77 lines (71 loc) · 1.81 KB
/
aliases.config.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// From vue-enterprise-template
// See repo: https://github.com/chrisvfritz/vue-enterprise-boilerplate
const path = require('path')
const fs = require('fs')
const prettier = require('prettier')
const aliases = {
'@': 'src',
'@assets': 'src/assets',
'@locales': 'src/locales',
'@pages': 'src/pages',
'@router': 'src/router',
'@styles': 'src/styles',
'@store': 'src/store',
'@use': 'src/use',
// Core access
'@theme': 'src/core/components/theme',
'@constants': 'src/core/constants',
'@layouts': 'src/core/layouts',
'@middleware': 'src/core/middleware',
'@mixins': 'src/core/mixins',
'@plugins': 'src/core/plugins',
'@apis': 'src/core/apis',
'@utils': 'src/core/utils',
}
module.exports = {
webpack: {},
jsconfig: {},
}
for (const alias in aliases) {
const aliasTo = aliases[alias]
module.exports.webpack[alias] = resolveSrc(aliasTo)
module.exports.jsconfig[alias + '/*'] = [aliasTo + '/*']
module.exports.jsconfig[alias] = aliasTo.includes('/index.')
? [aliasTo]
: [
aliasTo + '/index.js',
aliasTo + '/index.json',
aliasTo + '/index.vue',
aliasTo + '/index.scss',
aliasTo + '/index.css',
]
}
const jsconfigTemplate = require('./jsconfig.template') || {}
const jsconfigPath = path.resolve(__dirname, 'jsconfig.json')
fs.writeFile(
jsconfigPath,
prettier.format(
JSON.stringify({
...jsconfigTemplate,
compilerOptions: {
...(jsconfigTemplate.compilerOptions || {}),
paths: module.exports.jsconfig,
},
}),
{
...require('./.prettierrc'),
parser: 'json',
}
),
(error) => {
if (error) {
console.error(
'Error while creating jsconfig.json from aliases.config.js.'
)
throw error
}
}
)
function resolveSrc(_path) {
return path.resolve(__dirname, _path)
}