vue3 整合 springboot 打完整jar包

发布于:2023-09-16 ⋅ 阅读:(71) ⋅ 点赞:(0)

前端

  • .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>
本文含有隐藏内容,请 开通VIP 后查看