-
-
Notifications
You must be signed in to change notification settings - Fork 86
Expand file tree
/
Copy pathelectron.vite.config.mts
More file actions
95 lines (88 loc) · 2.88 KB
/
Copy pathelectron.vite.config.mts
File metadata and controls
95 lines (88 loc) · 2.88 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
import react from "@vitejs/plugin-react";
import { defineConfig } from "electron-vite";
import fs from "node:fs";
import path from "node:path";
const rootPath = import.meta.dirname;
const rendererPath = path.join(rootPath, "src", "renderer");
const distPath = path.join(rootPath, "release", "app", "dist");
const mainDistPath = path.join(distPath, "main");
const appPackage = JSON.parse(
fs.readFileSync(path.join(rootPath, "release", "app", "package.json"), "utf8")
) as { dependencies?: Record<string, string> };
// release/app owns runtime dependencies. Keeping them external lets Electron load
// native addons from release/app/node_modules after electron-builder rebuilds them.
const runtimeDependencies = Object.keys(appPackage.dependencies ?? {});
const aliases = {
main: path.join(rootPath, "src", "main"),
renderer: rendererPath,
shared: path.join(rootPath, "src", "shared"),
};
const defineEnvironment = {
"process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV ?? "production"),
"process.env.DEBUG_PROD": JSON.stringify(process.env.DEBUG_PROD ?? "false"),
};
const rendererPages = [
"index.html",
"launcher.html",
"oneclick-download-map.html",
"oneclick-download-playlist.html",
"oneclick-download-model.html",
"shortcut-launch.html",
];
export default defineConfig({
main: {
resolve: { alias: aliases },
define: defineEnvironment,
build: {
outDir: mainDistPath,
emptyOutDir: false,
externalizeDeps: false,
rollupOptions: {
input: {
main: path.join(rootPath, "src", "main", "main.ts"),
},
external: runtimeDependencies,
output: {
entryFileNames: "[name].js",
},
},
},
},
preload: {
resolve: { alias: aliases },
define: defineEnvironment,
build: {
outDir: mainDistPath,
emptyOutDir: false,
externalizeDeps: false,
rollupOptions: {
input: {
preload: path.join(rootPath, "src", "main", "preload.ts"),
},
output: {
entryFileNames: "[name].js",
},
},
},
},
renderer: {
root: rendererPath,
base: "./",
resolve: { alias: aliases },
define: defineEnvironment,
plugins: [react()],
server: {
port: Number(process.env.PORT) || 1212,
strictPort: true,
},
build: {
outDir: path.join(distPath, "renderer"),
emptyOutDir: false,
rollupOptions: {
input: Object.fromEntries(
rendererPages.map(page => [path.parse(page).name, path.join(rendererPath, page)])
),
},
},
},
});