feat: websocket HMR

This commit is contained in:
cha0s 2024-06-12 23:56:50 -05:00
parent d86e696cd2
commit 767cd4d564
2 changed files with 10 additions and 5 deletions

View File

@ -11,12 +11,17 @@ import { RemixServer } from "@remix-run/react";
import { isbot } from "isbot"; import { isbot } from "isbot";
import { renderToPipeableStream } from "react-dom/server"; import { renderToPipeableStream } from "react-dom/server";
import websocketServer from './websocket';
const ABORT_DELAY = 5_000; const ABORT_DELAY = 5_000;
export async function websocket(server) { export async function websocket(server, viteDevServer) {
await websocketServer(server); if (viteDevServer) {
const {createViteRuntime} = await import('vite');
const runtime = await createViteRuntime(viteDevServer);
(await runtime.executeEntrypoint('/app/websocket.js')).default(server);
}
else {
(await import('./websocket.js')).default(server);
}
} }
export default function handleRequest( export default function handleRequest(

View File

@ -49,7 +49,7 @@ const remixHandler = createRequestHandler({
build: () => ssr, build: () => ssr,
}); });
await ssr.entry.module.websocket(server); await ssr.entry.module.websocket(server, viteDevServer);
app.use(compression()); app.use(compression());