forked from rhygg/yukino-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
electron-dev.js
45 lines (35 loc) · 1.15 KB
/
electron-dev.js
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
const path = require("path");
const spawn = require("cross-spawn");
const { createServer } = require("vite");
const addressToString = require("./utils/address-to-string");
const pkgJson = require("../package.json");
const PORT = process.env.PORT ? +process.env.PORT : 3000;
const start = async () => {
process.env.NODE_ENV = "development";
const server = await createServer({
root: path.resolve(__dirname, ".."),
server: {
port: PORT,
watch: true
}
});
await server.listen();
process.env.VITE_SERVE_URL = addressToString(
server.httpServer.address(),
server.config.server.https
);
const electronStart = "electron:start";
if (!pkgJson.scripts[electronStart])
throw new Error("Missing 'scripts.electron:start' in package.json");
const electronProcess = spawn(`yarn ${electronStart}`, {
stdio: "inherit"
});
electronProcess.on("error", err => {
console.error(err);
});
electronProcess.on("exit", code => {
console.warn(`Electron process exited with code ${code}! Exiting...`);
process.exit(code);
});
};
start();