unis_crm/frontend/vite.config.ts

46 lines
1.4 KiB
TypeScript
Raw Permalink Normal View History

2026-03-26 09:29:55 +00:00
import fs from 'fs';
2026-03-19 06:23:03 +00:00
import tailwindcss from '@tailwindcss/vite';
import react from '@vitejs/plugin-react';
import path from 'path';
import {defineConfig, loadEnv} from 'vite';
export default defineConfig(({mode}) => {
const env = loadEnv(mode, '.', '');
2026-03-26 09:29:55 +00:00
const certPath = path.resolve(__dirname, '.cert/dev.crt');
const keyPath = path.resolve(__dirname, '.cert/dev.key');
2026-04-01 09:24:06 +00:00
const enableHttps = String(env.VITE_DEV_HTTPS || '').trim().toLowerCase() === 'true';
2026-03-26 09:29:55 +00:00
const https =
2026-04-01 09:24:06 +00:00
enableHttps && fs.existsSync(certPath) && fs.existsSync(keyPath)
2026-03-26 09:29:55 +00:00
? {
cert: fs.readFileSync(certPath),
key: fs.readFileSync(keyPath),
}
: undefined;
2026-03-19 06:23:03 +00:00
return {
plugins: [react(), tailwindcss()],
define: {
'process.env.GEMINI_API_KEY': JSON.stringify(env.GEMINI_API_KEY),
},
resolve: {
alias: {
'@': path.resolve(__dirname, './src'),
},
},
server: {
2026-03-26 09:29:55 +00:00
https,
2026-03-19 06:23:03 +00:00
// HMR is disabled in AI Studio via DISABLE_HMR env var.
// Do not modify—file watching is disabled to prevent flickering during agent edits.
hmr: process.env.DISABLE_HMR !== 'true',
2026-03-20 08:39:07 +00:00
proxy: {
'/api': {
target: 'http://localhost:8080',
rewrite: (requestPath) =>
requestPath.startsWith('/api/sys')
? requestPath.replace(/^\/api\/sys/, '/sys')
: requestPath,
},
},
2026-03-19 06:23:03 +00:00
},
};
});