optimize.ts
1.18 KB
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
import * as fs from 'node:fs'
import path from 'path'
const rootPath = path.resolve(__dirname, '../')
function optimizeAntdComponents(moduleName: string): string[] {
const moduleESPath = `${moduleName}/es`
const nodeModulePath = `./node_modules/${moduleESPath}`
const includes: string[] = [moduleESPath]
const folders = fs.readdirSync(
path.resolve(rootPath, nodeModulePath)
)
folders.map(name => {
const folderName = path.resolve(
rootPath,
nodeModulePath,
name
)
let stat = fs.lstatSync(folderName)
if (stat.isDirectory()) {
let styleFolder = path.resolve(folderName, 'style')
if (fs.existsSync((styleFolder))) {
let _stat = fs.lstatSync(styleFolder)
if (_stat.isDirectory()) {
includes.push(`${moduleESPath}/${name}/style`)
}
}
}
})
return includes
}
export function optimizeDeps() {
return {
name: "optimizeDeps",
configResolved: async (config) => {
const components = [
...optimizeAntdComponents('ant-design-vue'),
]
let concat = config.optimizeDeps.include.concat(components)
config.optimizeDeps.include = Array.from(new Set(concat))
}
}
}