-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.ts
42 lines (39 loc) · 1.01 KB
/
vite.config.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
41
42
import path from 'node:path'
import fs from 'node:fs'
import { defineConfig } from 'vite'
const modules = fs.readdirSync(path.join(__dirname, 'libs'))
export default defineConfig({
esbuild: {
drop: ['console', 'debugger'], // 移除 console 和 debugger 语句
},
build: {
minify: 'esbuild',
target: 'esnext',
outDir: 'dist',
sourcemap: true,
rollupOptions: {
external: ['vue', '@vue/reactivity'],
input: parseModules(),
output: {
minifyInternalExports: true,
dir: 'dist',
format: 'esm',
entryFileNames: '[name]/index.mjs',
},
},
lib: {
entry: '',
formats: ['es'],
},
},
})
function parseModules() {
return modules.reduce((acc, name) => {
const moduleDir = path.join(__dirname, 'libs', name)
if (!fs.statSync(moduleDir).isDirectory()) {
throw new Error(`libs/${moduleDir} is not a directory`)
}
acc[name] = path.resolve(moduleDir, 'index.ts')
return acc
}, {} as Record<string, string>)
}