-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.ts
84 lines (78 loc) · 2.63 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
import { rmSync } from 'node:fs'
import { defineConfig, type LogLevel, type ViteDevServer, type PluginOption } from 'vite'
import electron from 'vite-plugin-electron/simple'
import react from '@vitejs/plugin-react'
import { join } from 'path'
const entryHtml = '/src/renderer/index.html'
const resolveMainPage: () => PluginOption = () => ({
name: 'redirect-main-page',
configureServer(server: ViteDevServer) {
server.middlewares.use((req, _res, next) => {
if (req.originalUrl === '/' || req.originalUrl === '/index.html') req.url = entryHtml
next()
})
}
})
export default defineConfig(({ command }) => {
const isBuild = command === 'build'
const debug = !!process.env.DEBUG
const debug_sourcemaps = !!process.env.DEBUG_SOURCEMAPS
const logLevel: LogLevel = 'warn'
const outDir = 'dist-electron'
const entryMain = 'src/main/main.ts'
const inputPreload = 'src/main/preload.ts'
const publicDir = 'src/public'
rmSync(outDir, { recursive: true, force: true })
return {
publicDir,
logLevel,
plugins: [
resolveMainPage(),
react(),
electron({
main: {
entry: entryMain,
vite: {
logLevel,
build: {
sourcemap: debug_sourcemaps,
minify: isBuild,
outDir
}
},
onstart({ startup }) {
const args = [
'.',
'--no-sandbox'
]
if (debug) {
args.push('--inspect=5858')
args.push('--remote-debugging-port=9229')
}
if (debug_sourcemaps) args.push('--sourcemap')
void startup(args)
}
},
preload: {
input: inputPreload,
vite: {
logLevel,
build: {
sourcemap: debug_sourcemaps ? 'inline' : undefined,
minify: isBuild,
outDir
}
}
},
renderer: {},
}),
],
build: {
rollupOptions: {
input: {
main: join(__dirname, entryHtml)
}
}
}
}
})