Skip to content

Commit

Permalink
chore: add base vite config (#623)
Browse files Browse the repository at this point in the history
Co-authored-by: alexbarnsley <[email protected]>
  • Loading branch information
alexbarnsley and alexbarnsley authored Aug 27, 2024
1 parent 8346c5a commit b41d58a
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions resources/vite.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { loadEnv } from "vite";
import fs from "fs";
import { homedir } from "os";
import { resolve } from "path";

export function getValetHome() {
let valetPath = resolve(homedir(), ".config/valet");
if (fs.existsSync(valetPath)) {
return valetPath;
}

valetPath = resolve(homedir(), ".valet");
if (fs.existsSync(valetPath)) {
return valetPath;
}

return null;
}

// Variation of https://freek.dev/2276-making-vite-and-valet-play-nice-together
export function detectServerConfig(mode) {
const valetPath = getValetHome();
if (!valetPath) {
return;
}

const host = loadEnv(mode, process.cwd()).VITE_HOST ?? "localhost";
let keyPath = resolve(valetPath, `Certificates/${host}.key`);
let certificatePath = resolve(valetPath, `Certificates/${host}.crt`);

if (!fs.existsSync(keyPath)) {
return;
}

if (!fs.existsSync(certificatePath)) {
return;
}

return {
host,
port: 3000,
https: {
key: fs.readFileSync(keyPath),
cert: fs.readFileSync(certificatePath),
},
};
}

0 comments on commit b41d58a

Please sign in to comment.