Skip to content

Commit b41d58a

Browse files
authored
chore: add base vite config (#623)
Co-authored-by: alexbarnsley <[email protected]>
1 parent 8346c5a commit b41d58a

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

resources/vite.config.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { loadEnv } from "vite";
2+
import fs from "fs";
3+
import { homedir } from "os";
4+
import { resolve } from "path";
5+
6+
export function getValetHome() {
7+
let valetPath = resolve(homedir(), ".config/valet");
8+
if (fs.existsSync(valetPath)) {
9+
return valetPath;
10+
}
11+
12+
valetPath = resolve(homedir(), ".valet");
13+
if (fs.existsSync(valetPath)) {
14+
return valetPath;
15+
}
16+
17+
return null;
18+
}
19+
20+
// Variation of https://freek.dev/2276-making-vite-and-valet-play-nice-together
21+
export function detectServerConfig(mode) {
22+
const valetPath = getValetHome();
23+
if (!valetPath) {
24+
return;
25+
}
26+
27+
const host = loadEnv(mode, process.cwd()).VITE_HOST ?? "localhost";
28+
let keyPath = resolve(valetPath, `Certificates/${host}.key`);
29+
let certificatePath = resolve(valetPath, `Certificates/${host}.crt`);
30+
31+
if (!fs.existsSync(keyPath)) {
32+
return;
33+
}
34+
35+
if (!fs.existsSync(certificatePath)) {
36+
return;
37+
}
38+
39+
return {
40+
host,
41+
port: 3000,
42+
https: {
43+
key: fs.readFileSync(keyPath),
44+
cert: fs.readFileSync(certificatePath),
45+
},
46+
};
47+
}

0 commit comments

Comments
 (0)