Skip to content

Commit

Permalink
chore: add base vite config
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbarnsley committed Aug 5, 2024
1 parent 8346c5a commit 88b7ecc
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 88b7ecc

Please sign in to comment.