-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathelectron.vite.config.ts
More file actions
100 lines (93 loc) · 2.59 KB
/
electron.vite.config.ts
File metadata and controls
100 lines (93 loc) · 2.59 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
import { resolve } from 'path'
import { readFileSync, existsSync } from 'fs'
import { defineConfig, externalizeDepsPlugin } from 'electron-vite'
import react from '@vitejs/plugin-react'
/**
* Load environment variables from .env.local
* These will be injected at build time via `define`
*/
function loadEnvLocal(): Record<string, string> {
const envPath = resolve(__dirname, '.env.local')
const env: Record<string, string> = {}
if (existsSync(envPath)) {
const content = readFileSync(envPath, 'utf-8')
for (const line of content.split('\n')) {
const trimmed = line.trim()
// Skip empty lines and comments
if (!trimmed || trimmed.startsWith('#')) continue
const eqIndex = trimmed.indexOf('=')
if (eqIndex > 0) {
const key = trimmed.slice(0, eqIndex).trim()
let value = trimmed.slice(eqIndex + 1).trim()
// Remove surrounding quotes if present
if ((value.startsWith('"') && value.endsWith('"')) ||
(value.startsWith("'") && value.endsWith("'"))) {
value = value.slice(1, -1)
}
env[key] = value
}
}
}
return env
}
const envLocal = loadEnvLocal()
/**
* Build-time injected analytics config
* In open-source builds without .env.local, these will be empty strings (analytics disabled)
*/
const analyticsDefine = {
'__HALO_GA_MEASUREMENT_ID__': JSON.stringify(envLocal.HALO_GA_MEASUREMENT_ID || ''),
'__HALO_GA_API_SECRET__': JSON.stringify(envLocal.HALO_GA_API_SECRET || ''),
'__HALO_BAIDU_SITE_ID__': JSON.stringify(envLocal.HALO_BAIDU_SITE_ID || ''),
}
export default defineConfig({
main: {
plugins: [
externalizeDepsPlugin()
],
define: analyticsDefine,
build: {
sourcemap: true,
rollupOptions: {
input: {
index: resolve(__dirname, 'src/main/index.ts')
},
output: {
format: 'es',
entryFileNames: '[name].mjs'
}
}
}
},
preload: {
plugins: [externalizeDepsPlugin()],
build: {
rollupOptions: {
input: {
index: resolve(__dirname, 'src/preload/index.ts')
},
output: {
format: 'es',
entryFileNames: '[name].mjs'
}
}
}
},
renderer: {
root: resolve(__dirname, 'src/renderer'),
build: {
rollupOptions: {
input: {
index: resolve(__dirname, 'src/renderer/index.html'),
overlay: resolve(__dirname, 'src/renderer/overlay.html')
}
}
},
plugins: [react()],
resolve: {
alias: {
'@': resolve(__dirname, 'src/renderer')
}
}
}
})