-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathvite.electron.config.ts
More file actions
59 lines (57 loc) · 1.42 KB
/
Copy pathvite.electron.config.ts
File metadata and controls
59 lines (57 loc) · 1.42 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
import { defineConfig, loadEnv } from "vite";
import path from "path";
// Vite config for compiling the Electron main process and preload script.
// Outputs CJS to dist-electron/ — no app plugins, no PWA, no React.
export default defineConfig(({ mode }) => {
const env = loadEnv(mode, process.cwd(), "VITE_");
// main.ts targets "module": "commonjs" (see electron/tsconfig.json), which
// can't use import.meta.env like the renderer does — resolve the same
// VITE_SQL_API_URL var here instead and inject it as a literal via `define`.
const sqlApiOrigin = (() => {
try {
return new URL(env.VITE_SQL_API_URL ?? "http://localhost:4001/api").origin;
} catch {
return "http://localhost:4001";
}
})();
return {
define: {
__SQL_API_ORIGIN__: JSON.stringify(sqlApiOrigin),
},
build: {
outDir: "dist-electron",
emptyOutDir: true,
lib: {
entry: {
main: path.resolve(__dirname, "electron/main.ts"),
preload: path.resolve(__dirname, "electron/preload.ts"),
},
formats: ["cjs"],
fileName: (_format, entryName) => `${entryName}.cjs`,
},
rollupOptions: {
external: [
"electron",
"electron-updater",
"path",
"url",
"fs",
"fs/promises",
"os",
"crypto",
"stream",
"net",
"tls",
"http",
"https",
],
output: {
format: "cjs",
},
},
target: "node18",
minify: false,
sourcemap: false,
},
};
});