-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.temp.ts
40 lines (35 loc) · 1.05 KB
/
vite.config.temp.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
39
40
import { defineConfig } from 'vite'
import ViteDTS from 'vite-plugin-dts'
import fs from 'fs'
import path from 'path'
const srcPath = path.join(__dirname, './src/')
const readdirSyncDeep = (dirPath: string, partentName = '') => {
const allFileNames: string[] = []
const fileNames = fs.readdirSync(dirPath)
fileNames.map(fileName => {
const filePath = path.join(dirPath, fileName)
const isDir = fs.statSync(filePath).isDirectory()
if (isDir) allFileNames.push(...readdirSyncDeep(filePath, fileName + '/'))
else allFileNames.push(partentName + fileName)
})
return allFileNames
}
const files = readdirSyncDeep(srcPath).filter(fileName => !fileName.startsWith('types/'))
const entry = files.reduce((entry, item) => {
entry[item.replace(/(\.ts)$/, '')] = './src/' + item
return entry
}, {})
// https://vitejs.dev/config/
export default defineConfig({
plugins: [ViteDTS()],
resolve: {
alias: [{ find: '@', replacement: '/src' }]
},
build: {
lib: {
entry,
formats: ['cjs', 'es']
},
emptyOutDir: false
}
})