134 lines
4.3 KiB
TypeScript
134 lines
4.3 KiB
TypeScript
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: {
|
|
chunkSizeWarningLimit: 600,
|
|
rollupOptions: {
|
|
onwarn(warning: any, defaultHandler: any) {
|
|
// 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: string) {
|
|
if (id.includes('node_modules')) {
|
|
// 1. Heavy export and PDF document generation
|
|
if (id.includes('xlsx')) {
|
|
return 'vendor-xlsx';
|
|
}
|
|
if (id.includes('html2canvas')) {
|
|
return 'vendor-html2canvas';
|
|
}
|
|
if (id.includes('fflate')) {
|
|
return 'vendor-fflate';
|
|
}
|
|
if (id.includes('dompurify')) {
|
|
return 'vendor-purify';
|
|
}
|
|
if (id.includes('fast-png')) {
|
|
return 'vendor-png';
|
|
}
|
|
if (id.includes('polyfills.es.js') || id.includes('jspdf/dist/polyfills')) {
|
|
return 'vendor-pdf-polyfills';
|
|
}
|
|
if (id.includes('jspdf-autotable')) {
|
|
return 'vendor-pdf-autotable';
|
|
}
|
|
if (id.includes('jspdf') || id.includes('canvg')) {
|
|
return 'vendor-pdf';
|
|
}
|
|
// 2. Iconography
|
|
if (id.includes('lucide-react')) {
|
|
return 'vendor-icons';
|
|
}
|
|
// 3. Query & state management
|
|
if (id.includes('@tanstack')) {
|
|
return 'vendor-query';
|
|
}
|
|
// 4. OIDC Authentication
|
|
if (id.includes('oidc-client-ts')) {
|
|
return 'vendor-auth';
|
|
}
|
|
// 5. Schema & form validation
|
|
if (id.includes('zod') || id.includes('react-hook-form') || id.includes('@hookform')) {
|
|
return 'vendor-forms';
|
|
}
|
|
// 6. HTTP networking
|
|
if (id.includes('axios')) {
|
|
return 'vendor-http';
|
|
}
|
|
// 7. Client routing
|
|
if (id.includes('react-router')) {
|
|
return 'vendor-router';
|
|
}
|
|
// 8. Core React framework runtime
|
|
if (
|
|
id.includes('/react/') ||
|
|
id.includes('/react-dom/') ||
|
|
id.includes('/scheduler/')
|
|
) {
|
|
return 'vendor-react';
|
|
}
|
|
}
|
|
},
|
|
},
|
|
},
|
|
},
|
|
preview: {
|
|
port: 3000,
|
|
host: '0.0.0.0',
|
|
},
|
|
};
|
|
});
|