How to deploy Vite app to Tomcat correctly?

How to deploy Vite app to Tomcat correctly?

I have a Vite app built and I want to deploy it with my Tomcat, but it throws the following error:

Failed to load resource: the server responded with a status of 404 ()

for index.js file

When I run my app locally with npm run preview it works fine

My deploying procedure:

  1. run npm run build to build my app
  2. Transfer the contents of dist directory into Tomcat 9.0\webapps\my-app
  3. Go to http://localhost:8080/my-app/

Result is empty webpage with a singular console error mentioned above.

React config files' contents:

vite.config.ts

***
  base: '/',
***

package.json

***
"homepage": "/",
***

What is the correct procedure to deploy React/Vite apps using Tomcat?

Answer

Solution provided by @Phil in the comment section. Update base config as well as router's basename with my app name, then update Tomcat config as mentioned in this post

Enjoyed this question?

Check out more content on our blog or follow us on social media.

Browse more questions