import { defineConfig } from 'vite' import react from '@vitejs/plugin-react' import path from 'node:path' /** * 第三方依赖按稳定性分组,避免业务代码改动时把整个 vendor 也打成新 hash, * 让浏览器能长期复用 vendor 缓存。 */ function vendorChunks(id: string): string | undefined { if (!id.includes('node_modules')) return undefined if (/[\\/]node_modules[\\/]@tanstack[\\/]/.test(id)) return 'vendor-query' if (/[\\/]node_modules[\\/](react-router|react-router-dom|@remix-run)[\\/]/.test(id)) { return 'vendor-router' } if (/[\\/]node_modules[\\/](react|react-dom|scheduler)[\\/]/.test(id)) return 'vendor-react' return undefined } export default defineConfig({ plugins: [react()], resolve: { alias: { '@': path.resolve(__dirname, './src'), }, }, server: { proxy: { '/api': 'http://localhost:8080', }, }, build: { rollupOptions: { output: { manualChunks: vendorChunks, }, }, }, })