import { defineConfig } from 'vite'; import react from '@vitejs/plugin-react'; export default defineConfig({ plugins: [react()], // ★ 必须是相对路径。 // // 同一份 `dist/` 有两个宿主:网关在 `/` 下伺服它(Web),Electron 用 // `loadFile()` 从 **file:///…/dist/index.html** 加载它(桌面)。 // Vite 的默认 base 是 `/`,产物里写的是 `/assets/index-xxx.js` —— // 在 file:// 下它会解析成 `file:///assets/index-xxx.js`(不存在), // 于是 **Electron 应用白屏**:`#root` 里一个子节点都没有, // 而且加载失败只以一条资源错误出现,看起来像「应用没起来」。 // // 相对路径两边都对:Web 在 `/index.html` 里 `./assets/x.js` → `/assets/x.js`; // Electron 在 `dist/index.html` 里 `./assets/x.js` → `dist/assets/x.js`。 base: './', server: { port: 5173, proxy: { // Gateway 默认监听 8180(与 config.Load() 的 PORT 默认值一致) '/api': { target: 'http://localhost:8180', changeOrigin: true } } } });