11import { VIRTUAL_MODULES } from "@medusajs/admin-shared"
22import path from "path"
3- import type { InlineConfig } from "vite"
3+ import type { HmrOptions , InlineConfig } from "vite"
44import { injectTailwindCSS } from "../plugins/inject-tailwindcss"
55import { writeStaticFiles } from "../plugins/write-static-files"
66import { BundlerOptions } from "../types"
@@ -16,6 +16,7 @@ export async function getViteConfig(
1616 const hmrPort = process . env . HMR_PORT
1717 ? parseInt ( process . env . HMR_PORT )
1818 : await getPort . default ( )
19+ const hmrOptions = getHmrConfig ( hmrPort )
1920
2021 const root = path . resolve ( process . cwd ( ) , ".medusa/client" )
2122
@@ -51,16 +52,7 @@ export async function getViteConfig(
5152 fs : {
5253 allow : [ searchForWorkspaceRoot ( process . cwd ( ) ) ] ,
5354 } ,
54- hmr : {
55- port : hmrPort ,
56- ...( process . env . HMR_PROTOCOL
57- ? { protocol : process . env . HMR_PROTOCOL }
58- : { } ) ,
59- ...( process . env . HMR_HOST ? { host : process . env . HMR_HOST } : { } ) ,
60- ...( process . env . HMR_CLIENT_PORT
61- ? { clientPort : parseInt ( process . env . HMR_CLIENT_PORT ) }
62- : { } ) ,
63- } ,
55+ hmr : hmrOptions ,
6456 } ,
6557 plugins : [
6658 writeStaticFiles ( {
@@ -85,3 +77,18 @@ export async function getViteConfig(
8577
8678 return baseConfig
8779}
80+
81+ function getHmrConfig ( hmrPort : number ) : HmrOptions | boolean {
82+ const options = { } as HmrOptions
83+ options . port = hmrPort
84+ if ( process . env . HMR_PROTOCOL ) {
85+ options . protocol = process . env . HMR_PROTOCOL
86+ }
87+ if ( process . env . HMR_HOST ) {
88+ options . host = process . env . HMR_HOST
89+ }
90+ if ( process . env . HMR_CLIENT_PORT ) {
91+ options . clientPort = parseInt ( process . env . HMR_CLIENT_PORT )
92+ }
93+ return options
94+ }
0 commit comments