gc-wing/apps/web/vite.config.ts

47 lines
1.6 KiB
TypeScript
Raw Normal View 히스토리

2026-02-15 11:22:38 +09:00
import react from "@vitejs/plugin-react";
import { fileURLToPath } from "node:url";
import { defineConfig, loadEnv } from "vite";
// https://vite.dev/config/
export default defineConfig(({ mode }) => {
const env = loadEnv(mode, process.cwd(), "");
const webPort = Number(env.WEB_PORT || process.env.WEB_PORT || 5175);
const apiPort = Number(env.API_PORT || process.env.API_PORT || 5174);
// Same proxy pattern as the "dark" project:
// - dev: use Vite proxy (/snp-api -> upstream host)
// - prod: set VITE_API_URL to absolute base if needed
const snpApiTarget = env.VITE_SNP_API_TARGET || process.env.VITE_SNP_API_TARGET || "http://211.208.115.83:8041";
return {
plugins: [react()],
resolve: {
alias: {
// deck.gl (via loaders.gl) contains a few Node-only helper modules.
// In browser builds, they should be tree-shaken, but Vite/Rollup may still warn.
child_process: fileURLToPath(new URL("./src/shared/shims/child_process.ts", import.meta.url)),
},
},
server: {
// IMPORTANT: keep the web dev server port fixed so it doesn't collide with the API server port.
// If the port is already taken, fail fast instead of auto-falling-back to the API port (proxy loop -> 500).
port: webPort,
strictPort: true,
proxy: {
// Optional local API server (future DB-backed APIs etc).
"/api": {
target: `http://127.0.0.1:${apiPort}`,
changeOrigin: true,
},
// SNP-Batch AIS upstream (ship positions)
"/snp-api": {
target: snpApiTarget,
changeOrigin: true,
secure: false,
},
},
},
};
});