Files
HouseholdBudgetBook/frontend/vite.config.ts
T

39 lines
1010 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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,
},
},
},
})