VITE_APP_BASE_URL='/api'
VITE_APP_BASE_URL='/'
axios 配置
axios.defaults.baseURL = import.meta.env.VITE_APP_BASE_URL
"scripts": {
"dev": "vite --mode development",
"build": "vite build --mode production"
}
vite.config.js
server: {
port: 4000, //设置服务启动端口号,是一个可选项,不要设置为本机的端口号,可能会发生冲突
open: true, //是否自动打开浏览器,可选项
cors: true, //允许跨域。
// 设置代理
proxy: {
'/api': {
target: 'http://localhost:8053/', //这是你要跨域请求的地址前缀
changeOrigin: true, //开启跨域
rewrite: (path) => path.replace(/^\/api/, '')
}
}
}
pom.xml
<plugin>
<groupId>org.codehaus.mojogroupId>
<artifactId>exec-maven-pluginartifactId>
<version>1.6.0version>
<executions>
<execution>
<id>exec-pnpm-installid>
<phase>validatephase>
<goals>
<goal>execgoal>
goals>
<configuration>
<executable>pnpmexecutable>
<arguments>
<argument>installargument>
arguments>
<workingDirectory>${basedir}/src/uiworkingDirectory>
configuration>
execution>
<execution>
<id>exec-pnpm-run-buildid>
<phase>validatephase>
<goals>
<goal>execgoal>
goals>
<configuration>
<executable>pnpmexecutable>
<arguments>
<argument>buildargument>
arguments>
<workingDirectory>${basedir}/src/uiworkingDirectory>
configuration>
execution>
executions>
plugin>