import { defineConfig, loadEnv } from 'vite'; import react from '@vitejs/plugin-react'; // The ColdFusion backend is unchanged. In dev it is proxied so the browser sees one origin // (session cookies work, no CORS). In production IIS serves /mams next to /OmanTCS_stg. export default defineConfig(({ mode }) => { const env = loadEnv(mode, process.cwd(), ''); const target = env.VITE_BACKEND_ORIGIN || 'http://192.168.6.46'; const proxy = { '/OmanTCS_stg': { target, changeOrigin: true } }; return { base: env.VITE_BASE || '/mams/', plugins: [react()], server: { port: 5173, proxy }, // `npm start` serves the production build from your PC with the same backend proxy preview: { port: 4173, proxy }, build: { // staging builds go to their own folder so they never overwrite (or get deployed as) the production build outDir: mode === 'staging' ? 'dist-staging' : 'dist', sourcemap: false, target: 'es2022', rollupOptions: { output: { // libraries change rarely: keep them in their own files so the browser can cache them across releases manualChunks: (id) => { if (!id.includes('node_modules')) return undefined; if (/node_modules\/(react|react-dom|react-router|react-router-dom|scheduler)\//.test(id)) return 'react'; if (id.includes('@mui/icons-material')) return 'mui-icons'; if (/node_modules\/(@mui|@emotion)\//.test(id)) return 'mui'; if (id.includes('@tanstack')) return 'query'; return undefined; }, }, }, }, }; });