問題陳述:我有兩個部分的應用程序。 前端和後端。前端使用React
構建,其中使用Node.js
,後端是maven web應用程序,前端和後端之間的通信使用REST
完成。 我的應用程序正在兩臺服務器上運行。前端運行在Node.js
後端運行在tomcat上。 我想要的是部署在同一臺服務器上的兩部分。如何在Tomcat中部署React應用程序?
我該怎麼做?
我試過了。
第一種方法:我試過使用maven插件。在pom.xml
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
<id>exec-npm-install</id>
<phase>compile</phase>
<configuration>
<executable>npm</executable>
<arguments>
<argument>--prefix</argument>
<argument>${basedir}/src/main/webapp/ui</argument>
<argument>install</argument>
<argument>${basedir}/src/main/webapp/ui</argument>
</arguments>
</configuration>
<goals>
<goal>exec</goal>
</goals>
</execution>
<execution>
<id>exec-webpack</id>
<phase>compile</phase>
<configuration>
<executable>npm</executable>
<arguments>
<argument>--prefix</argument>
<argument>${basedir}/src/main/webapp/ui</argument>
<argument>run</argument>
<argument>build</argument>
</arguments>
</configuration>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
</plugin>
加在後端的前端應用程序文件夾中,web應用程序的文件夾添加波紋管插件。 但這種方法的問題是,當我做mvn install
所有node module
下載和項目的大小變得非常大(700MB
),因爲節點模塊。 這不是渴望。
我該怎麼做?