-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathelectron.vite.config.ts
More file actions
98 lines (97 loc) · 3.24 KB
/
Copy pathelectron.vite.config.ts
File metadata and controls
98 lines (97 loc) · 3.24 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
import { resolve } from 'node:path'
import { defineConfig, externalizeDepsPlugin } from 'electron-vite'
import react from '@vitejs/plugin-react'
import tailwindcss from '@tailwindcss/vite'
export default defineConfig({
main: {
plugins: [externalizeDepsPlugin()],
resolve: {
alias: {
'@main': resolve('src/main'),
'@shared': resolve('src/shared'),
},
},
build: {
outDir: 'out/main',
rollupOptions: {
input: resolve('src/main/index.ts'),
output: {
// electron 37 实测 ESM named export 不可用(仅 default export)→ 主进程用 CJS 保住 named import
format: 'cjs',
entryFileNames: 'index.cjs',
},
},
},
},
preload: {
plugins: [externalizeDepsPlugin()],
resolve: {
alias: {
'@preload': resolve('src/preload'),
'@shared': resolve('src/shared'),
},
},
build: {
outDir: 'out/preload',
// sandbox:true 下 preload 必须是 CJS(Electron sandbox 无 ESM loader)
rollupOptions: {
input: resolve('src/preload/index.ts'),
output: {
format: 'cjs',
entryFileNames: 'index.cjs',
},
},
},
},
renderer: {
root: resolve('src/renderer'),
publicDir: resolve('src/renderer/public'),
resolve: {
alias: {
'@renderer': resolve('src/renderer/src'),
'@shared': resolve('src/shared'),
},
},
plugins: [react(), tailwindcss()],
build: {
outDir: resolve('out/renderer'),
rollupOptions: {
input: resolve('src/renderer/index.html'),
output: {
// 手动分包(冷启动减负):大依赖拆出首包,配合路由懒加载按需拉取。
// 顺序敏感:katex 须在 markdown 链之前判断(rehype-katex 含 'rehype')。
manualChunks(id: string): string | undefined {
if (!id.includes('node_modules')) return undefined
if (/[\\/]node_modules[\\/](@xyflow|d3-)/.test(id)) return 'reactflow'
if (/[\\/]node_modules[\\/]katex[\\/]/.test(id)) return 'katex'
if (
/[\\/]node_modules[\\/](react-markdown|remark-|rehype-|micromark|mdast-|hast-|unist-|unified|vfile|highlight\.js|lowlight|property-information|space-separated-tokens|comma-separated-tokens|decode-named-character-reference|character-entities|trim-lines|bail|trough|devlop|estree-util|mdurl|html-url-attributes)/.test(
id,
)
) {
return 'markdown'
}
if (/[\\/]node_modules[\\/](framer-motion|motion-dom|motion-utils|tslib)/.test(id)) {
return 'motion'
}
if (
/[\\/]node_modules[\\/](@radix-ui|lucide-react|aria-hidden|react-remove-scroll|detect-node-es|get-nonce)/.test(
id,
)
) {
return 'ui'
}
if (
/[\\/]node_modules[\\/](react|react-dom|scheduler|react-router|@tanstack|zustand|i18next|clsx|tailwind-merge|class-variance-authority|zod)[\\/]/.test(
id,
)
) {
return 'vendor'
}
return undefined
},
},
},
},
},
})