-
Notifications
You must be signed in to change notification settings - Fork 52
Expand file tree
/
Copy pathvite.config.ts
More file actions
150 lines (147 loc) · 4.29 KB
/
Copy pathvite.config.ts
File metadata and controls
150 lines (147 loc) · 4.29 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
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
import fs from 'node:fs'
import path from 'node:path'
import { defineConfig, loadEnv } from 'vite'
import tailwindcss from '@tailwindcss/vite'
import vue from '@vitejs/plugin-vue'
import electron from 'vite-plugin-electron/simple'
import { viteStaticCopy } from 'vite-plugin-static-copy'
import pkg from './package.json'
import { vadStaticCopyTargets } from './build/vadAssets'
export default defineConfig(({ mode, command }) => {
fs.rmSync('dist-electron', { recursive: true, force: true })
const isServe = command === 'serve'
const isBuild = command === 'build'
const sourcemap = isServe || !!process.env.VSCODE_DEBUG
const env = loadEnv(mode, process.cwd(), '')
const QB_BASE_URL = env.VITE_QB_URL
return {
resolve: {
// vad-web imports this subpath with CommonJS `require()`. Resolve it to
// ORT's ESM build so Vite does not embed the CommonJS wrapper (which
// otherwise turns ORT's dynamic WASM import into a broken .vite URL).
alias: {
'onnxruntime-web/wasm': path.resolve(
process.cwd(),
'node_modules/onnxruntime-web/dist/ort.wasm.min.mjs'
),
},
},
// The VAD package is CommonJS and imports the WASM entrypoint through a
// require() call. Force both packages through Vite's ESM pre-bundler so
// the renderer never evaluates that CommonJS require at runtime.
optimizeDeps: {
include: ['@ricky0123/vad-web', 'onnxruntime-web/wasm'],
},
plugins: [
vue(),
tailwindcss(),
viteStaticCopy({
targets: [...vadStaticCopyTargets],
}),
electron({
main: {
entry: 'electron/main/index.ts',
onstart({ startup }) {
if (process.env.VSCODE_DEBUG) {
console.log('[startup] Electron App')
} else {
console.log('[Vite] Starting Electron main process...')
// Add a small delay to prevent race conditions
setTimeout(() => {
startup()
}, 100)
}
},
vite: {
build: {
sourcemap,
minify: isBuild,
outDir: 'dist-electron/main',
rollupOptions: {
external: Object.keys(
'dependencies' in pkg ? pkg.dependencies : {}
),
input: {
index: 'electron/main/index.ts',
'workers/pdfParserWorker':
'electron/main/workers/pdfParserWorker.ts',
},
},
},
},
},
preload: {
input: 'electron/preload/index.ts',
vite: {
build: {
sourcemap: sourcemap ? 'inline' : undefined,
minify: isBuild,
outDir: 'dist-electron/preload',
rollupOptions: {
external: Object.keys(
'dependencies' in pkg ? pkg.dependencies : {}
),
},
},
},
},
renderer: {},
}),
],
css: {
postcss: {
plugins: [],
},
},
server: (() => {
if (process.env.VSCODE_DEBUG) {
const url = new URL(pkg.debug.env.VITE_DEV_SERVER_URL)
return {
watch: {
ignored: ['**/user-customization/**'],
},
host: url.hostname,
port: +url.port,
proxy: {
'/api/v2': {
target: QB_BASE_URL,
changeOrigin: true,
secure: false,
},
},
}
} else {
return {
watch: {
ignored: ['**/user-customization/**'],
},
proxy: {
'/api/v2': {
target: QB_BASE_URL,
changeOrigin: true,
secure: false,
},
},
}
}
})(),
clearScreen: false,
build: {
chunkSizeWarningLimit: 1000,
rollupOptions: {
output: {
manualChunks: {
vue: ['vue'],
openai: ['openai'],
vendor: ['pinia'],
},
},
},
},
define: {
global: {},
__APP_MODE__: JSON.stringify(process.env.ELECTRON ? 'electron' : 'web'),
'import.meta.env.VITE_APP_VERSION': JSON.stringify(pkg.version),
},
}
})