fix(desktop): restructure to standard electron-vite layout for HMR

- Move renderer files to src/renderer/src/ (electron-vite standard)
- Move index.html to src/renderer/
- Remove root: '.' config that broke HMR
- Use ELECTRON_RENDERER_URL instead of VITE_DEV_SERVER_URL
- Update tsconfig paths for new structure

This fixes hot module replacement not working after the monorepo
restructure. The previous non-standard directory layout with root: '.'
caused electron-vite's HMR to fail silently.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Naiyuan Qing
2026-02-10 22:03:18 +08:00
parent 98b8126c89
commit 2269677ded
36 changed files with 5 additions and 12 deletions

View File

@@ -18,18 +18,10 @@ export default defineConfig({
},
},
renderer: {
root: '.',
build: {
rollupOptions: {
input: {
index: path.resolve(__dirname, 'index.html'),
},
},
},
plugins: [react(), tailwindcss()],
resolve: {
alias: {
'@': path.resolve(__dirname, 'src'),
'@': path.resolve(__dirname, 'src/renderer/src'),
},
},
},

View File

@@ -55,7 +55,8 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url))
// APP_ROOT points to apps/desktop (two levels up from out/main/)
process.env.APP_ROOT = path.join(__dirname, '../..')
export const VITE_DEV_SERVER_URL = process.env['VITE_DEV_SERVER_URL']
// electron-vite uses ELECTRON_RENDERER_URL for dev server
export const VITE_DEV_SERVER_URL = process.env['ELECTRON_RENDERER_URL']
// electron-vite outputs to out/ directory
export const MAIN_DIST = path.join(__dirname)
export const RENDERER_DIST = path.join(__dirname, '../renderer')

View File

@@ -7,6 +7,6 @@
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
<script type="module" src="./src/main.tsx"></script>
</body>
</html>

View File

@@ -15,7 +15,7 @@
"jsx": "react-jsx",
"baseUrl": ".",
"paths": {
"@/*": ["./src/*"],
"@/*": ["./src/renderer/src/*"],
"@multica/ui/*": ["../../packages/ui/src/*"],
"@multica/store/*": ["../../packages/store/src/*"]
},