import { defineConfig } from 'vite' import vue from '@vitejs/plugin-vue' import { fileURLToPath, URL } from 'node:url' export default defineConfig({ plugins: [vue()], resolve: { alias: { '@': fileURLToPath(new URL('./src', import.meta.url)) } }, server: { port: 3000, open: true, proxy: { // proxy 需要放在 server 对象内部 // 代理所有以 /api 开头的请求 '/api': { // target: 'http://36.212.7.246:8283/', // 后端服务地址 target: 'http://192.168.101.156:8080', // 后端服务地址 changeOrigin: true, // 支持跨域 rewrite: (path) => path.replace(/^\/api/, '') // 重写路径,去掉 /api 前缀 }, // 可以配置多个代理 '/upload': { // target: 'http://36.212.7.246:8283/', target: 'http:///192.168.101.156:8080', changeOrigin: true // 如果不需要重写路径,可以不加 rewrite } } } })