Skip to content

Commit

Permalink
feat: allow custom HMR configuration
Browse files Browse the repository at this point in the history
fixes #394
  • Loading branch information
schiller-manuel committed Oct 26, 2024
1 parent 432fdf5 commit b061c1d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
5 changes: 3 additions & 2 deletions packages/vinxi/lib/dev-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<NonNullable<import("vite").UserConfig["server"]>["hmr"], boolean> }} DevConfig */

/**
*
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -81,6 +81,7 @@ export async function createViteHandler(router, app, serveConfig) {
},
middlewareMode: true,
hmr: {
...serveConfig.hmr,
port,
},
https: serveConfig.https,
Expand Down
3 changes: 3 additions & 0 deletions packages/vinxi/lib/vite-dev.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ export type CustomizableConfig = Omit<
"outDir" | "ssr" | "ssrManifest" | "rollupOptions"
> & {
rollupOptions?: Omit<import("vite").BuildOptions["rollupOptions"], "input">;
server?: {
hmr?: Exclude<NonNullable<import("vite").UserConfig["server"]>["hmr"], boolean>;
}
};
};

Expand Down

0 comments on commit b061c1d

Please sign in to comment.