-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathelectron.config.ts
48 lines (45 loc) · 1.26 KB
/
electron.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
import electron from 'vite-plugin-electron';
import { loadEnv, Plugin } from 'vite';
// Load .env
const loadEnvPlugin = (): Plugin => {
return {
name: 'vite-plugin-load-env',
config(config, env) {
const root = config.root ?? process.cwd();
const result = loadEnv(env.mode, root);
// Remove the vite-plugin-electron injected env.
delete result.VITE_DEV_SERVER_URL;
config.esbuild ??= {};
config.esbuild.define = {
...config.esbuild.define,
...Object.fromEntries(
Object.entries(result).map(([key, val]) => [
`process.env.${key}`,
JSON.stringify(val),
])
),
};
},
};
};
const config = electron([
{
entry: 'electron/main.ts',
vite: {
plugins: [loadEnvPlugin()],
},
},
{
entry: 'electron/preload.ts',
onstart(options) {
// Notify the Renderer-Process to reload the page when the Preload-Scripts build is complete,
// instead of restarting the entire Electron App.
options.reload();
},
},
{
// Enables use of Node.js API in the Electron-Renderer
// https://github.com/electron-vite/vite-plugin-electron/tree/main/packages/electron-renderer#electron-renderervite-serve
},
]);
export default config;