frontend-mentor/product-preview-card-component/vite.config.ts

33 lines
727 B
TypeScript
Raw Normal View History

2023-05-28 18:44:18 -07:00
import * as fs from 'fs';
import { homedir } from 'os';
import { resolve } from 'path';
import { defineConfig } from 'vite';
export default defineConfig({
server: detectServerConfig('frontend-mentor.test'),
});
function detectServerConfig(host: string) {
const keyPath = resolve(homedir(), `.config/valet/Certificates/${host}.key`);
const certificatePath = resolve(homedir(), `.config/valet/Certificates/${host}.crt`);
if (!fs.existsSync(keyPath)) {
return {};
}
if (!fs.existsSync(certificatePath)) {
return {};
}
return {
host: host,
hmr: {
host: host,
},
https: {
key: fs.readFileSync(keyPath),
cert: fs.readFileSync(certificatePath),
},
};
}