LAOP-web/vite.config.js
2026-09-18 16:50:27 +08:00

40 lines
1.4 KiB
JavaScript
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 vue from '@vitejs/plugin-vue'
import path from 'node:path'
// Vite 构建配置
// docs: https://vitejs.dev/config/
export default defineConfig({
plugins: [vue()],
resolve: {
// 路径别名 @ -> src
alias: {
'@': path.resolve(__dirname, 'src')
}
},
server: {
port: 5173,
// 开发代理:前端请求转发到后端 Spring Boot(port 8081, context-path /laop)
proxy: {
// 后端静态资源(图片、文件):前端浏览器直接访问 /static/xxx,代理到后端 /laop/static/xxx
'/static': {
target: 'http://localhost:8081',
changeOrigin: true,
rewrite: (path) => path.replace(/^\/static/, '/laop/static')
},
// 文件上传接口:保留 /api 前缀不变(后端实际是 /api/file/upload)
'/api/file': {
target: 'http://localhost:8081',
changeOrigin: true,
rewrite: (path) => path.replace(/^\/api/, '/laop/api')
},
// Web 管理端其余接口:/api/* → /laop/*
'/api': {
target: 'http://localhost:8081',
changeOrigin: true,
rewrite: (path) => path.replace(/^\/api/, '/laop')
}
}
}
})