-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvite.config.ts
More file actions
108 lines (105 loc) · 3.14 KB
/
Copy pathvite.config.ts
File metadata and controls
108 lines (105 loc) · 3.14 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
import { execSync } from 'node:child_process'
import { join, resolve } from 'node:path'
import vue from '@vitejs/plugin-vue'
import { transformerDirectives } from 'unocss'
import unocss from 'unocss/vite'
import autoImport from 'unplugin-auto-import/vite'
import { Vuetify3Resolver } from 'unplugin-vue-components/resolvers'
import IconsResolver from 'unplugin-icons/resolver'
import Icons from 'unplugin-icons/vite'
import component from 'unplugin-vue-components/vite'
import { defineConfig } from 'vite'
import electronSimple from 'vite-plugin-electron/simple'
import vueDevTools from 'vite-plugin-vue-devtools'
const envDir = resolve(import.meta.dirname, 'env')
const currentCommitHash = execSync('git rev-parse HEAD').toString().substring(0, 8)
// https://vitejs.dev/config/
export default defineConfig({
define: {
__COMIT_HASH__: JSON.stringify(currentCommitHash),
},
envDir,
base: '/',
plugins: [
vue(),
electronSimple({
main: {
// NOTE: 如果使用 --no-sandbox 启动,则 @electron/devtron 无法安装
onstart({ startup }) {
startup(['.', '--trace-warnings'])
},
entry: 'electron/main.ts',
vite: {
resolve: {
alias: {
'@main': resolve(import.meta.dirname, 'electron'),
'@common': resolve(import.meta.dirname, 'common'),
},
},
build: {
sourcemap: true,
rolldownOptions: {
external: ['skia-canvas'],
},
},
},
},
preload: {
input: join(import.meta.dirname, 'electron/preload.ts'),
},
renderer:
process.env.NODE_ENV === 'test'
? // https://github.com/electron-vite/vite-plugin-electron-renderer/issues/78#issuecomment-2053600808
undefined
: {},
}),
autoImport({
imports: ['vue', 'vue-router', 'pinia', '@vueuse/core'],
eslintrc: {
enabled: true,
},
}),
Icons(),
component({
resolvers: [Vuetify3Resolver(), IconsResolver()],
}),
unocss({
transformers: [
transformerDirectives({
applyVariable: ['--at-apply', '--uno-apply', '--uno'],
}),
],
}),
vueDevTools(),
],
resolve: {
alias: {
'@': resolve(import.meta.dirname, 'src'),
'@main': resolve(import.meta.dirname, 'electron'),
'@common': resolve(import.meta.dirname, 'common'),
},
},
build: {
sourcemap: true,
rolldownOptions: {
input: {
home: resolve(import.meta.dirname, 'home.html'),
login: resolve(import.meta.dirname, 'login.html'),
setting: resolve(import.meta.dirname, 'setting.html'),
sign: resolve(import.meta.dirname, 'sign.html'),
about: resolve(import.meta.dirname, 'about.html'),
},
},
},
server: {
// 由于 jm 的接口以 cookie 形式来验证用户登录,所以这里我们在开发下只能做一层转发
// 生产下不受影响,由 electron 侧提供服务器来供访问
proxy: {
'^/api': {
target: 'http://localhost:6174',
changeOrigin: true,
secure: false,
},
},
},
})