Files
vue-beta/vite.config.ts

32 lines
1003 B
TypeScript
Raw 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 { fileURLToPath, URL } from 'node:url'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueDevTools from 'vite-plugin-vue-devtools'
// https://vite.dev/config/
export default defineConfig({
plugins: [
vue(),
vueDevTools(),
],
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url))
},
},
server: {
host: '0.0.0.0', // 允许局域网访问(可选)
port: 5173, // 修改端口号(默认是 5173
open: true, // 启动项目时自动打开浏览器
// 配置代理解决跨域问题
proxy: {
'/api': { // 以/api开头的请求会被代理
target: 'http://localhost:8080', // 目标后端服务器地址如Spring Boot服务
changeOrigin: true, // 开启跨域请求头中的host会被设置成target
rewrite: path => path.replace(/^\/api/, '') // 重写路径,去掉开头的/api
}
}
}
})