-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.ts
104 lines (103 loc) · 3.21 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
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
import vue from '@vitejs/plugin-vue'
import path from 'node:path'
import { defineConfig } from 'vite'
import electron from 'vite-plugin-electron/simple'
import renderer from 'vite-plugin-electron-renderer'
import { visualizer } from 'rollup-plugin-visualizer'
// https://vitejs.dev/config/
export default defineConfig(({ command, mode }) => {
return {
server: {
port: 8000,
},
plugins: [
vue(),
electron({
main: {
// Shortcut of `build.lib.entry`.
entry: 'electron/main.ts',
vite: {
build: {
rollupOptions: {
external: ['better-sqlite3'],
plugins: [
{
name: 'native-modules',
resolveId(source) {
if (source === 'better-sqlite3') {
return { id: 'better-sqlite3', external: true }
}
}
}
]
}
}
}
},
preload: {
// Shortcut of `build.rollupOptions.input`.
// Preload scripts may contain Web assets, so use the `build.rollupOptions.input` instead `build.lib.entry`.
input: path.join(__dirname, 'electron/preload.ts'),
},
// Ployfill the Electron and Node.js API for Renderer process.
// If you want use Node.js in Renderer process, the `nodeIntegration` needs to be enabled in the Main process.
// See 👉 https://github.com/electron-vite/vite-plugin-electron-renderer
renderer: process.env.NODE_ENV === 'test'
// https://github.com/electron-vite/vite-plugin-electron-renderer/issues/78#issuecomment-2053600808
? undefined
: {},
}),
renderer(),
// 添加分析插件,仅在analyze模式下启用
mode === 'analyze' && visualizer({
open: true,
filename: 'dist/stats.html',
gzipSize: true,
brotliSize: true,
}),
],
resolve: {
alias: {
'electron': 'electron',
},
},
define: {
__APP_VERSION__: JSON.stringify(process.env.npm_package_version)
},
build: {
// 启用源码映射以便调试
sourcemap: command === 'serve',
// 启用CSS代码分割
cssCodeSplit: true,
// 配置Rollup选项
rollupOptions: {
output: {
// 手动分块策略
manualChunks: {
'vue-vendor': ['vue'],
'db-related': ['better-sqlite3', 'bindings', 'file-uri-to-path'],
'utils': ['colord', 'electron-log'],
},
// 自定义chunk文件名格式
chunkFileNames: 'assets/js/[name]-[hash].js',
entryFileNames: 'assets/js/[name]-[hash].js',
assetFileNames: 'assets/[ext]/[name]-[hash].[ext]',
},
},
// 设置chunk大小警告阈值
chunkSizeWarningLimit: 600,
// 压缩选项
minify: 'terser',
terserOptions: {
compress: {
drop_console: true, // 生产环境下移除console
drop_debugger: true // 移除debugger语句
}
},
},
// 优化依赖预构建
optimizeDeps: {
include: ['vue'],
}
}
})