首页 > 解决方案 > Spring Boot 和 React 生产构建

问题描述

我创建了一个 Spring Boot 项目。之后,我在 Spring Boot 项目上创建了 React 项目。现在,前端和后端服务器都在运行。在前端文件夹中,我运行该命令npm run build

它创建了一个名为 build 的文件夹。我想做的是用一台服务器运行所有项目。(例如:localhost:8080)。我知道我应该将前端文件移动到静态文件夹下。我该怎么做?

我尝试了 maven-antrun-plugin 但它不起作用。

<plugin>
            <artifactId>maven-antrun-plugin</artifactId>
            <executions>
                <execution>
                    <phase>generate-resources</phase>
                    <configuration>
                        <target>
                            <copy todir="${project.build.directory}/classes/public">
                                <fileset dir="${project.basedir}/frontend/build"/>
                            </copy>
                        </target>
                    </configuration>
                    <goals>
                        <goal>run</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

标签: reactjsspring-bootbuild

解决方案


使用 maven复制资源插件


推荐阅读