import { defineConfig, Plugin } from "vite"; import react from "@vitejs/plugin-react-swc"; import path from "path"; // https://vitejs.dev/config/ export default defineConfig(({ mode }) => ({ server: { host: "::", port: 8080, fs: { allow: ["./client", "./shared"], deny: [".env", ".env.*", "*.{crt,pem}", "**/.git/**", "server/**"], }, }, build: { outDir: "dist/spa", }, plugins: [react(), expressPlugin()], resolve: { alias: { "@": path.resolve(__dirname, "./client"), "@shared": path.resolve(__dirname, "./shared"), }, }, })); function expressPlugin(): Plugin { return { name: "express-plugin", apply: "serve", // Only apply during development (serve mode) configureServer(server) { (async () => { const { createServer } = await import("./server"); const app = createServer(); server.middlewares.use(app); })().catch((e) => { console.error("Failed to start express middleware:", e); }); }, }; }