LazyBoy2/web/vite.config.ts

39 lines
1.2 KiB
TypeScript

import { dirname, resolve } from "node:path";
import { fileURLToPath } from "node:url";
import { defineConfig, loadEnv, type ServerOptions } from "vite";
import react from "@vitejs/plugin-react";
const rootDir = resolve(dirname(fileURLToPath(import.meta.url)), "..");
export default defineConfig(({ mode }) => {
const env = loadEnv(mode, rootDir, "");
const version = (process.env.LAZYBOY_VERSION || env.LAZYBOY_VERSION || "0.1.0").trim() || "0.1.0";
// The API accepts HTTP even when its optional TLS listener is enabled.
const backendPort = process.env.LAZYBOY_WEB_PORT || env.LAZYBOY_WEB_PORT || "8787";
const backend = `http://127.0.0.1:${backendPort}`;
const server: ServerOptions = {
port: 5173,
host: "0.0.0.0",
strictPort: true,
proxy: {
"/api": { target: backend, secure: false },
"/novnc": { target: backend, ws: true, secure: false },
"/lazyboy-ca.crt": { target: backend, secure: false },
},
};
return {
plugins: [react()],
resolve: { dedupe: ["react", "react-dom"] },
define: {
"import.meta.env.LAZYBOY_VERSION": JSON.stringify(version),
},
server,
preview: {
port: 4173,
host: "0.0.0.0",
strictPort: true,
},
};
});