-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathvite.config.ts
More file actions
82 lines (78 loc) · 2.17 KB
/
vite.config.ts
File metadata and controls
82 lines (78 loc) · 2.17 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
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import electron from 'vite-plugin-electron'
import renderer from 'vite-plugin-electron-renderer'
import { resolve } from 'path'
// Windows 构建时禁用 WebLLM(通过环境变量 DISABLE_WEBLLM=true)
const DISABLE_WEBLLM = process.env.DISABLE_WEBLLM === 'true'
export default defineConfig({
define: {
'import.meta.env.DISABLE_WEBLLM': JSON.stringify(DISABLE_WEBLLM)
},
plugins: [
react(),
electron([
{
entry: 'electron/main.ts',
onstart(args) {
// 启动 Electron
args.startup()
},
vite: {
build: {
outDir: 'dist-electron',
rollupOptions: {
external: ['electron']
}
}
}
},
{
entry: 'electron/preload.ts',
onstart(options) {
options.reload()
},
vite: {
build: {
outDir: 'dist-electron'
}
}
}
]),
renderer()
],
resolve: {
alias: {
'@': resolve(__dirname, 'src')
}
},
// Web Worker 配置
worker: {
format: 'es'
},
build: {
rollupOptions: {
input: {
main: resolve(__dirname, 'index.html')
},
output: {
manualChunks: {
'docx-viewer': ['mammoth']
}
}
}
},
// 优化 WebLLM 的大文件加载(Windows 构建时不需要此优化)
optimizeDeps: {
exclude: DISABLE_WEBLLM ? [] : ['@mlc-ai/web-llm']
},
server: {
port: 5173,
strictPort: true,
// WebLLM 需要 SharedArrayBuffer,这需要 COOP 和 COEP 响应头
headers: {
'Cross-Origin-Opener-Policy': 'same-origin',
'Cross-Origin-Embedder-Policy': 'require-corp'
}
}
})