mirror of
https://github.com/hanzoai/kms.git
synced 2026-10-30 14:57:36 +00:00
Root cause: jsrp (SRP library) uses bare `process` without browser guard. Vite preloadError handler called preventDefault too early, masking the real error and causing TanStack Router to get undefined components. - Add global process shim in main.tsx (env, version, browser, nextTick) - Add process.env/version/browser define in vite.config.ts - Fix vite:preloadError: only preventDefault when about to reload
80 lines
2.1 KiB
TypeScript
80 lines
2.1 KiB
TypeScript
import { TanStackRouterVite } from "@tanstack/router-plugin/vite";
|
|
import react from "@vitejs/plugin-react-swc";
|
|
import { defineConfig, loadEnv, PluginOption } from "vite";
|
|
import topLevelAwait from "vite-plugin-top-level-await";
|
|
import wasm from "vite-plugin-wasm";
|
|
import tsconfigPaths from "vite-tsconfig-paths";
|
|
|
|
const virtualRouteFileChangeReloadPlugin: PluginOption = {
|
|
name: "watch-config-restart",
|
|
configureServer(server) {
|
|
server.watcher.add("./src/routes.ts");
|
|
server.watcher.on("change", (path) => {
|
|
if (path.endsWith("src/routes.ts")) {
|
|
console.log("Virtual route changed");
|
|
server.restart();
|
|
}
|
|
});
|
|
}
|
|
};
|
|
|
|
// https://vite.dev/config/
|
|
export default defineConfig(({ mode }) => {
|
|
const env = loadEnv(mode, process.cwd());
|
|
const allowedHosts = env.VITE_ALLOWED_HOSTS?.split(",") ?? [];
|
|
const version = (
|
|
env.INFISICAL_PLATFORM_VERSION ||
|
|
env.VITE_INFISICAL_PLATFORM_VERSION ||
|
|
"0.0.1"
|
|
).replaceAll(".", "-");
|
|
|
|
return {
|
|
define: {
|
|
"process.env": "{}",
|
|
"process.version": '"v22.0.0"',
|
|
"process.browser": "true",
|
|
},
|
|
server: {
|
|
allowedHosts,
|
|
host: true,
|
|
port: 3000
|
|
// proxy: {
|
|
// "/api": {
|
|
// target: "http://localhost:8080",
|
|
// changeOrigin: true,
|
|
// secure: false,
|
|
// ws: true
|
|
// }
|
|
// }
|
|
},
|
|
build: {
|
|
rollupOptions: {
|
|
output: {
|
|
entryFileNames: `assets/[name]-${version}-[hash].js`,
|
|
chunkFileNames: `assets/[name]-${version}-[hash].js`,
|
|
assetFileNames: `assets/[name]-${version}-[hash].[ext]`
|
|
}
|
|
}
|
|
},
|
|
experimental: {
|
|
renderBuiltUrl(filename, { hostType }) {
|
|
if (hostType === "js") {
|
|
return { runtime: `window.__toCdnUrl(${JSON.stringify(filename)})` };
|
|
}
|
|
|
|
return { relative: true };
|
|
}
|
|
},
|
|
plugins: [
|
|
tsconfigPaths(),
|
|
wasm(),
|
|
topLevelAwait(),
|
|
TanStackRouterVite({
|
|
virtualRouteConfig: "./src/routes.ts"
|
|
}),
|
|
react(),
|
|
virtualRouteFileChangeReloadPlugin
|
|
]
|
|
};
|
|
});
|