import { defineConfig, loadEnv } from "vite"; import vue from "@vitejs/plugin-vue"; import { fileURLToPath, URL } from "node:url"; // https://vitejs.dev/config/ export default defineConfig(({ mode }) => { // Load env file from repository root (parent directory) const env = loadEnv(mode, fileURLToPath(new URL("..", import.meta.url)), ""); return { // Load .env files from repository root envDir: "..", plugins: [ vue(), // Plugin to set correct MIME types { name: "configure-server", configureServer(server) { server.middlewares.use((req, res, next) => { if (req.url && req.url.endsWith(".wasm")) { res.setHeader("Content-Type", "application/wasm"); } if (req.url && req.url.endsWith(".mjs")) { res.setHeader("Content-Type", "application/javascript"); } next(); }); } } ], // Point to parent project's public directory publicDir: fileURLToPath(new URL("../public", import.meta.url)), resolve: { alias: { "@": fileURLToPath(new URL("./src", import.meta.url)), "@inc": fileURLToPath(new URL("../inc", import.meta.url)) } }, server: { host: env.VITE_HOST || "localhost", port: parseInt(env.VITE_PORT) || 5173, strictPort: true, open: false, fs: { // Allow serving files from node_modules allow: ["..", "../.."] }, // Proxy socket.io requests to backend server proxy: { "/socket.io": { target: env.VITE_SERVER_URL || "http://localhost:8157", changeOrigin: true, ws: true // Enable WebSocket proxying } } }, optimizeDeps: { exclude: ["onnxruntime-web"] }, build: { rollupOptions: { external: ["/lib/tgnParser.cjs"] } }, css: { preprocessorOptions: { scss: { api: "modern" // Use modern Sass API } } }, define: { "process.env": {} } }; });