Files
algorithm/frontend/vite.config.ts

77 lines
2.0 KiB
TypeScript

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import { resolve } from 'path'
import { URL } from 'url'
const __dirname = decodeURIComponent(new URL('.', import.meta.url).pathname);
// https://vitejs.dev/config/
export default defineConfig({
plugins: [vue()],
server: {
port: 3000,
proxy: {
'/api': {
target: 'http://localhost:8001',
changeOrigin: true,
rewrite: (path) => {
// 如果路径已经是 /api/v1/ 开头,则不重写
if (path.startsWith('/api/v1/')) {
return path
}
// 否则将 /api/ 重写为 /api/v1/
return path.replace(/^\/api\//, '/api/v1/')
},
timeout: 600000, // 10分钟超时
// 确保认证头在重定向时被保留
configure: (proxy, options) => {
proxy.on('proxyReq', (proxyReq, req, res) => {
// 确保认证头被正确传递
if (req.headers.authorization) {
proxyReq.setHeader('Authorization', req.headers.authorization)
}
})
}
}
}
},
build: {
outDir: 'dist',
assetsDir: 'assets',
minify: 'terser',
sourcemap: false,
// 代码分割配置
rollupOptions: {
output: {
manualChunks: {
// 第三方库分割
vendor: ['vue', 'vue-router', 'pinia'],
// UI库分割
element: ['element-plus'],
// 图表库分割
charts: ['echarts'],
// 网络请求库分割
http: ['axios']
},
// 缓存策略
chunkFileNames: 'assets/js/[name]-[hash].js',
entryFileNames: 'assets/js/[name]-[hash].js',
assetFileNames: 'assets/[ext]/[name]-[hash].[ext]'
}
},
// 压缩配置
terserOptions: {
compress: {
drop_console: true,
drop_debugger: true
}
}
},
// 别名配置
resolve: {
alias: {
'@': resolve(process.cwd(), 'src')
}
}
})