32 lines
1.0 KiB
TypeScript
32 lines
1.0 KiB
TypeScript
import { fileURLToPath, URL } from "node:url";
|
|
|
|
import tailwindcss from "@tailwindcss/vite";
|
|
import react from "@vitejs/plugin-react";
|
|
import { defineConfig, loadEnv } from "vite";
|
|
|
|
// The SPA always calls the API at a relative `/api/...`:
|
|
// dev -> this proxy forwards to Django
|
|
// prod -> nginx serves the built files and proxies /api to gunicorn
|
|
export default defineConfig(({ mode }) => {
|
|
const env = loadEnv(mode, process.cwd(), "");
|
|
const apiTarget = env.VITE_API_PROXY_TARGET ?? "http://localhost:8000";
|
|
|
|
return {
|
|
plugins: [react(), tailwindcss()],
|
|
resolve: {
|
|
alias: { "@": fileURLToPath(new URL("./src", import.meta.url)) },
|
|
},
|
|
server: {
|
|
host: true,
|
|
port: 5173,
|
|
proxy: {
|
|
"/api": { target: apiTarget, changeOrigin: true },
|
|
"/admin": { target: apiTarget, changeOrigin: true },
|
|
"/static": { target: apiTarget, changeOrigin: true },
|
|
"/media": { target: apiTarget, changeOrigin: true },
|
|
},
|
|
},
|
|
build: { outDir: "dist", sourcemap: mode !== "production" },
|
|
};
|
|
});
|