feat: Add base project structure with API and web components

This commit is contained in:
Ke Sun
2025-12-02 20:28:01 +08:00
parent f3de6d6cc9
commit c1adc62ec6
817 changed files with 111226 additions and 106 deletions

91
web/vite.config.ts Normal file
View File

@@ -0,0 +1,91 @@
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import { resolve } from 'path'
import AutoImport from 'unplugin-auto-import/vite'
import tailwindcss from '@tailwindcss/vite'
// https://vite.dev/config/
export default defineConfig({
server: {
host: '0.0.0.0', // 支持通过IP地址访问
proxy: {
// 主要API代理支持 /api 和 /api/* 格式
'/api': {
target: 'http://0.0.0.0:5173', // 后端服务地址
changeOrigin: true,
// 匹配所有以/api开头的请求包括/api/token
configure: (proxy) => {
// 确保能够匹配/api/token这样的路径
proxy.on('error', (err) => {
console.log('代理错误:', err)
})
}
},
},
},
plugins: [
tailwindcss(),
react(),
AutoImport({
imports: ['react', 'react-router-dom'],
dts: 'public/auto-imports.d.ts',
}),
],
css: {
modules: {
generateScopedName: '[name]__[local]___[hash:base64:5]',
localsConvention: 'camelCaseOnly',
},
},
resolve: {
alias: {
'@': resolve(__dirname, 'src'),
},
},
base: './', // 使用相对路径,确保资源能正确加载
build: {
outDir: 'dist',
emptyOutDir: true,
assetsDir: 'assets', // 静态资源目录
sourcemap: false, // 生产环境不生成 sourcemap
rollupOptions: {
input: {
main: resolve(__dirname, 'index.html'),
},
output: {
// 分块策略
manualChunks: (id) => {
if (id.includes('node_modules')) {
if (id.includes('react') || id.includes('react-dom')) {
return 'react-vendor';
}
if (id.includes('react-router')) {
return 'router-vendor';
}
if (id.includes('antd')) {
return 'antd-vendor';
}
if (id.includes('echarts')) {
return 'echarts-vendor';
}
// 其他第三方库
return 'vendor';
}
},
// 输出文件命名
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
},
},
},
})