-
Notifications
You must be signed in to change notification settings - Fork 16
/
vite.config.components.ts
38 lines (36 loc) · 1.13 KB
/
vite.config.components.ts
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
import { readdirSync } from 'fs'
import { join as pathJoin } from 'pathe'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import { IconsResolverCustom } from './vite.config.icons'
/* CONFIGURATION FOR COMPONENTS AUTO-IMPORT */
export const ComponentsBuilder = () => Components({
dts: './dts/components.d.ts',
dirs: [
'./src/components',
...buildViewsComponents()
],
resolvers: [
ElementPlusResolver({ importStyle: false }),
IconsResolverCustom()
]
})
function buildViewsComponents () {
const componentsDirs: string[] = []
function getComponentsDirs (dirName: string) {
try {
const dirs = readdirSync(dirName, { withFileTypes: true }).filter(dirent => dirent.isDirectory())
dirs.forEach((dir) => {
const dirPath = pathJoin(dirName, dir.name)
if (dirPath.includes('/components')) {
componentsDirs.push(dirPath)
}
getComponentsDirs((dirPath))
})
} catch {
console.warn(`No such file or directory, ${dirName}`)
}
}
getComponentsDirs('./src/views')
return componentsDirs
}