diff --git a/.changeset/light-panthers-bow.md b/.changeset/light-panthers-bow.md new file mode 100644 index 00000000..01c10fcb --- /dev/null +++ b/.changeset/light-panthers-bow.md @@ -0,0 +1,5 @@ +--- +"vinxi": patch +--- + +feat: allow custom HMR configuration diff --git a/packages/vinxi/lib/dev-server.js b/packages/vinxi/lib/dev-server.js index 381b6326..5b728728 100644 --- a/packages/vinxi/lib/dev-server.js +++ b/packages/vinxi/lib/dev-server.js @@ -8,7 +8,7 @@ import { join, normalize } from "./path.js"; export * from "./router-dev-plugins.js"; /** @typedef {{ force?: boolean; devtools?: boolean; port?: number; ws?: { port?: number }; https?: import('@vinxi/listhen').HTTPSOptions | boolean; }} DevConfigInput */ -/** @typedef {{ force: boolean; port: number; devtools: boolean; ws: { port: number }; https?: import('@vinxi/listhen').Certificate; }} DevConfig */ +/** @typedef {{ force: boolean; port: number; devtools: boolean; ws: { port: number }; https?: import('@vinxi/listhen').Certificate; hmr?: Exclude["hmr"], boolean> }} DevConfig */ /** * @@ -49,7 +49,7 @@ export async function createViteDevServer(config) { export async function createViteHandler(router, app, serveConfig) { const vite = await import("vite"); const { getRandomPort } = await import("get-port-please"); - const port = await getRandomPort(); + const port = serveConfig.hmr?.port ?? await getRandomPort(); const plugins = [ // ...(serveConfig.devtools ? [inspect()] : []), ...(((await router.internals.type.dev.plugins?.(router, app)) ?? []).filter( @@ -81,6 +81,7 @@ export async function createViteHandler(router, app, serveConfig) { }, middlewareMode: true, hmr: { + ...serveConfig.hmr, port, }, https: serveConfig.https, diff --git a/packages/vinxi/lib/vite-dev.d.ts b/packages/vinxi/lib/vite-dev.d.ts index a27f1bca..aed76edd 100644 --- a/packages/vinxi/lib/vite-dev.d.ts +++ b/packages/vinxi/lib/vite-dev.d.ts @@ -48,6 +48,9 @@ export type CustomizableConfig = Omit< "outDir" | "ssr" | "ssrManifest" | "rollupOptions" > & { rollupOptions?: Omit; + server?: { + hmr?: Exclude["hmr"], boolean>; + } }; };