Skip to content

Commit

Permalink
style: HttpsOptions type
Browse files Browse the repository at this point in the history
  • Loading branch information
arildm committed Sep 4, 2024
1 parent 50710fb commit 7c2b00f
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
import path from "path";
import { ServerOptions as HttpsServerOptions } from "https";
import { ServerOptions } from "https";
import { defineConfig, loadEnv } from "vite";
import vue from "@vitejs/plugin-vue";
import ViteYaml from "@modyfi/vite-plugin-yaml";
import { visualizer } from "rollup-plugin-visualizer";

type HttpsOptions = Pick<ServerOptions, "key" | "cert">;

// https://vitejs.dev/config/
export default defineConfig(async ({ mode }) => {
// Load .env files. Vite will do it itself, but only later. See https://github.com/vitejs/vite/issues/1930
Object.assign(process.env, loadEnv(mode, process.cwd(), ""));

// Read HTTPS cert and key, if their paths are specified in env.
async function getHttpsOptions(): Promise<HttpsServerOptions | undefined> {
/** Read HTTPS cert and key, if their paths are specified in env. */
async function getHttpsOptions(): Promise<HttpsOptions | undefined> {
if (process.env.DEV_HTTPS_KEY && process.env.DEV_HTTPS_CERT) {
const fs = await import("fs");
return <HttpsServerOptions>{
return {
key: fs.readFileSync(process.env.DEV_HTTPS_KEY),
cert: fs.readFileSync(process.env.DEV_HTTPS_CERT),
};
Expand Down

0 comments on commit 7c2b00f

Please sign in to comment.