How to package and deploy react application to tomcat

藏色散人
Release: 2023-01-19 13:46:26
Original
1678 people have browsed it

How to package and deploy react applications to tomcat: 1. Use "npm run build" to package the project; 2. Put the contents of the packaged folder into the Root under webapps in tomcat; 3. Open The server can access the "localhost:8080" port.

How to package and deploy react application to tomcat

The operating environment of this tutorial: Windows 10 system, react18.0.0, Dell G3 computer.

How to package and deploy react application to tomcat?

How to deploy the React project in Tomcat

The blogger has worked hard to type the react code, but the result cannot be displayed when he wants to deploy it to Tomcat. After that, I visited Baidu and Google, and finally found the reason why the project deployment failed. I will summarize it below.

Deployment method:

  • Use npm run build to package the project

  • Put the packaged The contents of the folder are placed in the Root under webapps in tomcat

  • Open the server and access the localhost:8080 port to see the content of your project

The pitfalls of not placing it in the Root directory:

Because the default path.js [path: your react project name\node_modules\react-scripts\config\path.js] configuration is '/', that is It is valid for the root directory, so if it is not placed under the root, you need to change '/' to './', that is, the relative path is valid. (Modify the code at about line 45)

How to package and deploy react application to tomcat

At this time you can access your react project through localhost:8080/project name.

Recommended learning: "react video tutorial"

The above is the detailed content of How to package and deploy react application to tomcat. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template