Files
podux/site/vite.config.ts
2026-03-02 17:40:35 +08:00

66 lines
1.7 KiB
TypeScript
Raw Permalink 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 tailwindcss from '@tailwindcss/vite'
// https://vite.dev/config/
export default defineConfig({
plugins: [react(), tailwindcss()],
server: {
host: '0.0.0.0',
proxy: {
'/api': {
target: 'http://127.0.0.1:8090',
changeOrigin: true,
}
}
},
build: {
// 代码分割优化
rollupOptions: {
output: {
manualChunks: {
// 将 React 相关库单独打包
'react-vendor': ['react', 'react-dom', 'react-router-dom'],
// UI 组件库单独打包
'ui-vendor': ['@radix-ui/themes', 'sonner', 'framer-motion'],
// 图表库单独打包
'chart-vendor': ['recharts'],
// 工具库单独打包
'utils-vendor': ['i18next', 'react-i18next', 'pocketbase'],
},
// 优化资源文件名
chunkFileNames: 'assets/js/[name]-[hash].js',
entryFileNames: 'assets/js/[name]-[hash].js',
assetFileNames: 'assets/[ext]/[name]-[hash].[ext]',
},
},
// 压缩优化
minify: 'terser',
terserOptions: {
compress: {
drop_console: true, // 移除 console
drop_debugger: true, // 移除 debugger
pure_funcs: ['console.log'], // 移除特定函数
},
},
// 启用 CSS 代码分割
cssCodeSplit: true,
// 设置 chunk 大小警告限制
chunkSizeWarningLimit: 600,
// 生成 sourcemap(生产环境可以设为 false)
sourcemap: false,
},
// 依赖优化
optimizeDeps: {
include: [
'react',
'react-dom',
'react-router-dom',
'@radix-ui/themes',
'pocketbase',
'i18next',
'react-i18next',
],
},
})