import { defineConfig } from 'vite'; import react from '@vitejs/plugin-react'; import tailwindcss from 'tailwindcss'; import autoprefixer from 'autoprefixer'; import path from 'path'; import nesting from 'tailwindcss/nesting'; const isDev = process.env.NODE_ENV === 'development'; const isKV = process.env.VITE_USE_KV === 'true'; // use kevisual service as backend const unamiPlugin = { name: 'html-transform', transformIndexHtml(html: string) { return html.replace( '', ``, ); }, }; const plugins = []; if (!isDev) { plugins.push(unamiPlugin); } let proxy = {}; if (isKV) { proxy = { '/api': { target: 'https://envision.xiongxiao.me', changeOrigin: true, rewrite: (path: any) => path.replace(/^\/api/, '/api'), }, '/api/router': { target: 'wss://envision.xiongxiao.me', changeOrigin: true, ws: true, rewriteWsOrigin: true, rewrite: (path: any) => path.replace(/^\/api/, '/api'), }, '/resources': { target: 'https://envision.xiongxiao.me', changeOrigin: true, rewrite: (path: any) => path.replace(/^\/resources/, '/resources'), }, }; } // https://vitejs.dev/config/ export default defineConfig({ plugins: [react(), ...plugins], css: { postcss: { // @ts-ignore plugins: [ nesting({ // 兼容 tailwindcss 4.0 tailwindcss: { config: './tailwind.config.js', }, }), tailwindcss, autoprefixer, ], }, }, resolve: { alias: { '@': path.resolve(__dirname, './src'), }, }, define: { DEV_SERVER: JSON.stringify(process.env.NODE_ENV === 'development'), }, server: { port: 6020, host: '0.0.0.0', proxy: { '/system/lib': { target: 'https://kevisual.xiongxiao.me', changeOrigin: true, }, '/api': { target: 'http://localhost:4002', changeOrigin: true, rewrite: (path) => path.replace(/^\/api/, '/api'), }, '/api/router': { target: 'ws://localhost:4002', changeOrigin: true, ws: true, rewriteWsOrigin: true, rewrite: (path) => path.replace(/^\/api/, '/api'), }, '/resources': { target: 'https://envision.xiongxiao.me', changeOrigin: true, rewrite: (path) => path.replace(/^\/resources/, '/resources'), }, ...proxy, }, }, });