forked from apollographql-education/summit-24-client-web
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.ts
44 lines (39 loc) · 975 Bytes
/
vite.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
import react from "@vitejs/plugin-react";
import fs from "node:fs";
import os from "node:os";
import path from "node:path";
import { defineConfig } from "vite";
const defaultCertFilePath = path.join(
os.homedir(),
".maintainx",
"localhost.pem",
);
const defaultKeyFilePath = path.join(
os.homedir(),
".maintainx",
"localhost-key.pem",
);
function getFile(...paths: string[]) {
for (const p of paths) {
if (p && fs.existsSync(p)) {
return fs.readFileSync(p);
}
}
return null;
}
const certFile = getFile(process.env.LOCALHOST_CERTFILE!, defaultCertFilePath);
const keyFile = getFile(process.env.LOCALHOST_KEYFILE!, defaultKeyFilePath);
// https://vitejs.dev/config/
export default defineConfig({
server: {
port: 2000,
https:
process.env.HTTP === "true" || certFile === null || keyFile === null
? undefined
: {
cert: certFile,
key: keyFile,
},
},
plugins: [react()],
});