import tailwindcss from '@tailwindcss/vite'; import react from '@vitejs/plugin-react'; import path from 'path'; import {defineConfig} from 'vite'; export default defineConfig(async ({ command }) => { // In containerized cloud environments where the reverse proxy / ingress terminates TLS externally, // Vite serves over HTTP on port 3000. // For local development, HTTPS can be enabled. const isAiStudioContainer = Boolean( process.env.APPLET_ID || process.env.K_SERVICE || process.env.CONTROL_PLANE_PORT ); const isHttps = !isAiStudioContainer && ( process.env.HTTPS === 'true' || process.env.VITE_ENABLE_HTTPS === 'true' || (process.env.HTTPS !== 'false' && process.env.VITE_ENABLE_HTTPS !== 'false') ); const plugins: any[] = [ react(), tailwindcss(), ]; // Only load SSL plugin when running the local dev server with HTTPS enabled if (command === 'serve' && isHttps) { try { const basicSslModule: any = await import('@vitejs/plugin-basic-ssl'); const basicSsl = basicSslModule.default || basicSslModule; plugins.push(basicSsl()); } catch { console.warn( '[vite.config] @vitejs/plugin-basic-ssl is not installed; running dev server over HTTP. Run `yarn add -D @vitejs/plugin-basic-ssl` to enable local HTTPS.' ); } } return { plugins, resolve: { alias: { '@': path.resolve(__dirname, '.'), }, }, server: { hmr: process.env.DISABLE_HMR !== 'true', watch: process.env.DISABLE_HMR === 'true' ? null : {}, }, build: { rollupOptions: { onwarn(warning, defaultHandler) { // Suppress benign Rollup warnings where Zod's internal explanatory doc comments mention `@__PURE__` if ( warning.code === 'INVALID_ANNOTATION' && (warning.id?.includes('zod') || warning.message?.includes('@__PURE__') || warning.loc?.file?.includes('zod')) ) { return; } defaultHandler(warning); }, output: { manualChunks(id) { if (id.includes('node_modules')) { if (id.includes('react') || id.includes('scheduler')) { return 'vendor-react'; } if (id.includes('@tanstack')) { return 'vendor-query'; } if (id.includes('oidc-client-ts')) { return 'vendor-auth'; } if (id.includes('lucide-react')) { return 'vendor-icons'; } if (id.includes('zod') || id.includes('react-hook-form') || id.includes('@hookform')) { return 'vendor-forms'; } if (id.includes('axios')) { return 'vendor-http'; } } }, }, }, }, preview: { port: 3000, host: '0.0.0.0', }, }; });