-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.ts
More file actions
77 lines (73 loc) · 2.29 KB
/
Copy pathvite.config.ts
File metadata and controls
77 lines (73 loc) · 2.29 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
import { defineConfig } from "vite";
import path from "node:path";
import electron from "vite-plugin-electron";
import renderer from "vite-plugin-electron-renderer";
import react from "@vitejs/plugin-react";
function readPort(value: string | undefined, fallback: number): number {
const port = Number(value);
return Number.isInteger(port) && port > 0 && port < 65536 ? port : fallback;
}
const DEV_SERVER_HOST = process.env.OVERCODE_DEV_HOST || "127.0.0.1";
const DEV_SERVER_PORT = readPort(process.env.OVERCODE_DEV_PORT, 5173);
// Single `electron()` call with an array of entries.
// Calling `electron()` twice (as the previous config did) spawns two
// separate Electron processes during dev, and the second exiting kills the
// shared esbuild service with `Error: The service was stopped`.
//
// Auto-startup behavior: by default the plugin launches Electron after the
// FIRST entry whose build finishes. We provide `onstart` on preload and the
// worker so only main.ts auto-launches Electron. preload's onstart triggers
// a renderer reload on change; the worker is forked from main via
// utilityProcess.fork, so it must be compiled but must not trigger a second
// Electron launch of its own.
export default defineConfig({
server: {
host: DEV_SERVER_HOST,
port: DEV_SERVER_PORT,
strictPort: false,
},
plugins: [
react(),
electron([
{
entry: "electron/main.ts",
vite: {
build: {
outDir: "dist-electron",
rollupOptions: {
external: ["electron"],
},
},
},
},
{
entry: path.join(__dirname, "electron/preload.ts"),
onstart({ reload }) {
reload();
},
vite: {
build: {
outDir: "dist-electron",
rollupOptions: {
external: ["electron"],
},
},
},
},
{
entry: "electron/workers/git-worker.ts",
// Build-only — do not start a second Electron instance.
onstart() {},
vite: {
build: {
outDir: "dist-electron/workers",
rollupOptions: {
external: ["electron"],
},
},
},
},
]),
process.env.NODE_ENV === "test" ? undefined : renderer({}),
],
});