vue3 整合 springboot 打完整jar包
前端
- .env.developmen
VITE_APP_BASE_URL='/api'
- .env.production
VITE_APP_BASE_URL='/'
axios 配置
axios.defaults.baseURL = import.meta.env.VITE_APP_BASE_URL
package.json
"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.mojo</groupId><artifactId>exec-maven-plugin</artifactId><version>1.6.0</version><executions><execution><id>exec-pnpm-install</id><phase>validate</phase><goals><goal>exec</goal></goals><configuration><executable>pnpm</executable><arguments><argument>install</argument></arguments><workingDirectory>${basedir}/src/ui</workingDirectory></configuration></execution><execution><id>exec-pnpm-run-build</id><phase>validate</phase><goals><goal>exec</goal></goals><configuration><executable>pnpm</executable><arguments><argument>build</argument></arguments><workingDirectory>${basedir}/src/ui</workingDirectory></configuration></execution></executions></plugin>