How can I deploy the Vite application on any URL instance without manually changing the basename?

262 Views Asked by At

I use ViteJS + React in my application, which should be deployable on any instance. The application has deep-routed routers, such as myapp/dev/measurements/1834.

To achieve this flexibility, I set the 'base' parameter in the ViteJS config as './' and the 'base href' in the index.html file of the app build.

<base href="/" />

This setup works well. When deploying, for example, to the URL myapp/dev.com, I simply set the href as '/dev/'. Alternatively, when deploying to a direct URL address, I keep the href as '/'.

However, I encountered an issue because Vite renders indexes for chunks in each build. While this resolves the client browser caching problem, it requires me to manually change the href each time I deploy.

To address this, I considered moving the 'base href' to a configuration file (config.js). This way, I could update the deploy by overwriting the index.html without affecting config.js. The challenge now is that I don't have information about the correct file path to this config.

Do you have any ideas on how I can configure the basename to avoid manually changing text on each deploy of each instance?

The application is deployed on IIS, so I'm unsure if I can configure server redirects.

0

There are 0 best solutions below