-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathelectron.vite.config.mjs
More file actions
121 lines (117 loc) · 3.72 KB
/
Copy pathelectron.vite.config.mjs
File metadata and controls
121 lines (117 loc) · 3.72 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
import { resolve } from 'path'
import { defineConfig, externalizeDepsPlugin } from 'electron-vite'
import vue from '@vitejs/plugin-vue'
import AutoImport from 'unplugin-auto-import/vite'
import IconsResolver from 'unplugin-icons/resolver'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import tailwindcss from '@tailwindcss/vite'
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'
import path from 'path'
import obfuscatorPlugin from 'vite-plugin-javascript-obfuscator'
export default defineConfig({
main: {
resolve: {
alias: {
'@main': resolve('src/main'),
'@preload': resolve('src/preload'),
'@shared': resolve('src/shared')
}
},
plugins: [externalizeDepsPlugin()],
build: {
minify: 'esbuild',
esbuild: {
// 保留错误级别的日志,移除debug和info级别
drop: process.env.NODE_ENV === 'production' ? ['debugger'] : [],
// 在生产环境中保留console.error和console.warn
pure:
process.env.NODE_ENV === 'production'
? ['console.log', 'console.debug', 'console.info']
: []
}
}
},
preload: {
resolve: {
alias: {
'@main': resolve('src/main'),
'@preload': resolve('src/preload'),
'@shared': resolve('src/shared')
}
},
plugins: [externalizeDepsPlugin(), obfuscatorPlugin()], // 移除bytecodePlugin,避免对preload脚本进行字节码处理
build: {
minify: false, // 完全禁用preload脚本的压缩
rollupOptions: {
external: [], // 确保没有外部化关键依赖
output: {
format: 'cjs', // 明确指定输出格式
inlineDynamicImports: true // 内联动态导入
}
}
}
},
renderer: {
resolve: {
alias: {
'@renderer': resolve('src/renderer/src'),
'@preload': resolve('src/preload'),
'@main': resolve('src/main'),
'@shared': resolve('src/shared')
}
},
plugins: [
vue(),
tailwindcss(),
AutoImport({
// Auto import functions from Vue, e.g. ref, reactive, toRef...
// 自动导入 Vue 相关函数,如:ref, reactive, toRef 等
imports: ['vue'],
// Auto import functions from Element Plus, e.g. ElMessage, ElMessageBox... (with style)
// 自动导入 Element Plus 相关函数,如:ElMessage, ElMessageBox... (带样式)
resolvers: [
ElementPlusResolver(),
// Auto import icon components
// 自动导入图标组件
IconsResolver({
prefix: 'Icon'
})
]
}),
Components({
dirs: ['src/renderer/src/components'],
resolvers: [
// 自动注册图标组件
IconsResolver({
enabledCollections: ['ep']
}),
// 自动注册 Element Plus 组件
ElementPlusResolver()
]
}),
createSvgIconsPlugin({
// Specify the icon folder to be cached
iconDirs: [path.resolve(process.cwd(), 'src/renderer/src/icons')],
// Specify symbolId format
symbolId: 'icon-[dir]-[name]'
})
],
build: {
sourcemap: false,
rollupOptions: {
output: {
manualChunks(id) {
if (id.includes('node_modules')) {
if (id.includes('element-plus')) return 'vendor-element-plus'
if (id.includes('vue')) return 'vendor-vue'
return 'vendor'
}
if (id.includes('/src/renderer/src/views/')) return 'views'
if (id.includes('/src/renderer/src/components/')) return 'components'
}
}
}
}
}
})