-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathelectron.vite.config.ts
More file actions
169 lines (164 loc) · 5.78 KB
/
electron.vite.config.ts
File metadata and controls
169 lines (164 loc) · 5.78 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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
import { resolve } from 'path'
import { defineConfig, externalizeDepsPlugin } from 'electron-vite'
import vue from '@vitejs/plugin-vue'
const s = JSON.stringify
// Dev-only Vite plugin: injects a module script before the main entry that
// connects to the standalone Vue DevTools server (port 8098). The script runs
// before createApp() thanks to module execution order, ensuring the devtools
// hooks are in place. If the server isn't running, it skips silently.
function vueDevToolsPlugin () {
const virtualId = '\0vue-devtools-init'
return {
name: 'vue-devtools',
resolveId (id: string) {
if (id === '/@vue-devtools-init.js') return virtualId
},
load (id: string) {
if (id === virtualId) {
return [
'try {',
' await fetch("http://localhost:8098", { mode: "no-cors" })',
' const { devtools } = await import("@vue/devtools")',
' devtools.connect("localhost", 8098)',
' console.info("[Vue DevTools] Connected to standalone DevTools on port 8098.")',
'} catch {',
' console.info("[Vue DevTools] Standalone server not detected on port 8098. To enable Vue DevTools, run \\`npm run devtools\\` in a separate terminal before starting the app.")',
'}',
].join('\n')
}
},
transformIndexHtml () {
return [{
tag: 'script',
attrs: { type: 'module', src: '/@vue-devtools-init.js' },
injectTo: 'head-prepend' as const,
}]
},
}
}
function getDefine () {
return {
__DARWIN__: process.platform === 'darwin',
__WIN32__: process.platform === 'win32',
__LINUX__: process.platform === 'linux',
__DEV__: !!(process.env.IS_DEV) || false,
__LOGGER__: process.env.LOGGER !== 'false',
'process.platform': s(process.platform),
'process.env.NODE_ENV': s(process.env.NODE_ENV || 'development'),
'process.env.TEST_ENV': s(process.env.TEST_ENV),
__CRASH_URL__: s('https://71e593620d21420fb864d3fe667d8ce6@sentry.io/1476972'),
__ANALYTICS_ID__: s('UA-103701546-4')
}
}
function getStaticDefine () {
if (process.env.NODE_ENV !== 'production' || process.env.IS_DEV) {
return {
__static: s(resolve(__dirname, 'static'))
}
}
return {}
}
export default defineConfig({
main: {
plugins: [externalizeDepsPlugin()],
resolve: {
alias: {
'@lib': resolve('src/lib'),
'@main': resolve('src/main')
}
},
define: {
...getDefine(),
...getStaticDefine(),
__PROCESS_KIND__: s('main')
},
build: {
outDir: 'dist',
lib: {
entry: resolve(__dirname, 'src/main/index.ts')
},
rollupOptions: {
output: {
entryFileNames: 'main.js'
}
}
}
},
preload: {
plugins: [externalizeDepsPlugin()],
resolve: {
alias: {
'@lib': resolve('src/lib')
}
},
define: {
...getDefine(),
__PROCESS_KIND__: s('preload')
},
build: {
outDir: 'dist',
emptyOutDir: false,
lib: {
entry: resolve(__dirname, 'src/preload/index.ts')
},
rollupOptions: {
output: {
entryFileNames: 'preload.js'
}
}
}
},
renderer: {
root: resolve('src/renderer'),
resolve: {
alias: {
'@': resolve('src/renderer'),
'@lib': resolve('src/lib'),
'@main': resolve('src/main'),
'path': 'path-browserify',
'node:path': 'path-browserify',
// Patch Primer CSS images not being included in the package.
'/images/spinners/octocat-spinner-16px.gif': resolve('src/styles/images/error.png'),
'/images/modules/ajax/success.png': resolve('src/styles/images/error@2x.png'),
'/images/modules/ajax/error.png': resolve('src/styles/images/octocat-spinner-16px.gif'),
'/images/spinners/octocat-spinner-32.gif': resolve('src/styles/images/octocat-spinner-32-EAF2F5.gif'),
'/images/modules/ajax/success@2x.png': resolve('src/styles/images/octocat-spinner-32.gif'),
'/images/modules/ajax/error@2x.png': resolve('src/styles/images/success.png'),
'/images/spinners/octocat-spinner-32-EAF2F5.gif': resolve('src/styles/images/success@2x.png')
}
},
define: {
...getDefine(),
...getStaticDefine(),
__PROCESS_KIND__: s('renderer'),
__VUE_OPTIONS_API__: true,
__VUE_PROD_DEVTOOLS__: false
},
plugins: [
vue(),
process.env.IS_DEV ? vueDevToolsPlugin() : null,
].filter(Boolean),
publicDir: resolve('static'),
css: {
preprocessorOptions: {
scss: {
silenceDeprecations: ['import', 'global-builtin', 'if-function'],
loadPaths: [resolve(__dirname)]
}
}
},
optimizeDeps: {
include: process.env.IS_DEV ? ['@vue/devtools'] : [],
},
server: {
port: 9080
},
build: {
outDir: resolve('dist'),
emptyOutDir: false,
rollupOptions: {
input: resolve('src/renderer/index.html')
}
}
}
})