I'm working on a React-Typescript-Vite project that I want to deploy to Firebase hosting. The app is running fine locally (with npm run dev), but I'm having issues with prod. My app basically has a name of a store as the first url subdirectory then another subdirectory /entry for the homepage. So for example - http://localhost:5173/gucci/entry. The interesting thing is that on prod if I only navigate to https://myprojectname.firebaseapp.com/gucci(the url hosting my app) I do see the background picture, but if I try https://myprojectname.firebaseapp.com/gucci/entry then I get an empty page.
I've tried using the sources and network tabs in chrome dev tools to help me debug, this is what I see in the prod site in the sources tab in the 'entry' document:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="./vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + React + TS</title>
<script type="module" crossorigin src="./assets/index-f625c516.js"></script>
<link rel="stylesheet" href="./assets/index-31f53eb0.css">
</head>
<body>
<div id="root"></div>
</body>
</html>
and this what I see in the same document in my local environment:
<!DOCTYPE html>
<html lang="en">
<head>
<script type="module">
import RefreshRuntime from "/@react-refresh"
RefreshRuntime.injectIntoGlobalHook(window)
window.$RefreshReg$ = () => {}
window.$RefreshSig$ = () => (type) => type
window.__vite_plugin_react_preamble_installed__ = true
</script>
<script type="module" src="/@vite/client"></script>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + React + TS</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx?t=1677961443563"></script>
</body>
</html>
So it seems the issue is with the script tags in prod, but I'm not sure how to handle it.
This is my firebase.json
{
"hosting": {
"public": "dist",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"rewrites": [
{
"source": "**",
"destination": "/index.html"
}
]
}
}
and this is my vite.config
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
// https://vitejs.dev/config/
export default defineConfig({
plugins: [react()]
})
I'm using react-router-dom for routing. I'd appreciate anyone's help!