vite.config.ts 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import { defineConfig } from 'vite';
  2. import react from '@vitejs/plugin-react';
  3. import path from 'node:path';
  4. // M13b W0: vite dev proxies /v1/* to the local stack:
  5. // /v1/auth/* → authd (port 8804)
  6. // /v1/* → admind (port 8803)
  7. //
  8. // In production, the SPA is embedded in admind and served from /,
  9. // so all /v1/* requests go to the same origin (admind).
  10. const devProxies = (() => {
  11. const authd = process.env.VITE_PROXY_AUTHD ?? 'http://127.0.0.1:8804';
  12. const admind = process.env.VITE_PROXY_ADMIND ?? 'http://127.0.0.1:8803';
  13. return [
  14. {
  15. context: ['/v1/auth', '/health'],
  16. target: authd,
  17. changeOrigin: false,
  18. },
  19. {
  20. context: ['/v1'],
  21. target: admind,
  22. changeOrigin: false,
  23. },
  24. ];
  25. })();
  26. export default defineConfig({
  27. plugins: [react()],
  28. resolve: {
  29. alias: {
  30. '@': path.resolve(__dirname, 'src'),
  31. },
  32. },
  33. server: {
  34. port: 5173,
  35. proxy: devProxies,
  36. },
  37. build: {
  38. outDir: process.env.VITE_OUT_DIR ?? '../cmd/admind/web-dist',
  39. emptyOutDir: true,
  40. sourcemap: false,
  41. target: 'es2022',
  42. rollupOptions: {
  43. output: {
  44. manualChunks: {
  45. react: ['react', 'react-dom', 'react-router-dom'],
  46. query: ['@tanstack/react-query'],
  47. forms: ['react-hook-form', '@hookform/resolvers', 'zod'],
  48. ui: ['lucide-react', 'sonner'],
  49. },
  50. },
  51. },
  52. },
  53. });