Macil / browserify-hmr

Hot Module Replacement plugin for Browserify
MIT License
373 stars 26 forks source link

Dynamic hostname of websocket connection? #4

Closed kentor closed 8 years ago

kentor commented 8 years ago

Sometimes I need to test my app in a VM or remotely, so I access the js bundle using a different hostname than localhost. For hmr I specify -u http://0.0.0.0:3123 as the url of the websocket connection. The problem is the in the VM it will try to access http://0.0.0.0:3123 instead of using the IP/hostname of the server running the websocket server and fail. Is it possible to substitute 0.0.0.0 to the hostname that accessed the bundle at runtime?

Macil commented 8 years ago

Is there a reason that you can't specify your IP/hostname with the -u option? Are you listening on a different IP+port than your VM is trying to connect to? It seems like I should separate those to separate options then.

kentor commented 8 years ago

I could, but it'd be inconvenient if I want to access the bundle locally. Say I want to access the websocket locally (via localhost:3123) and in the VM (via 10.0.2.2:3123) at the same time without killing the watchify process. Hmm Another option is to specify the hostname through a query param on the bundle maybe.

Macil commented 8 years ago

I'm going to split up the -u option so there's a separate option (-l/listen?) for controlling the IP+port is listened on because that doesn't always match up with -u. Then I'll add a function for changing the update mode and settings at runtime. Something like

module.hot.setUpdateMode("websocket", {url: "http://10.0.2.2:3123"});

Going a little further, I'll add a "none" update mode so that the bundle can be started as or switched to not doing any updating at all. Hm, right now, the socket.io-client dependency is only brought in if the -m/mode flag is set to "websocket". I'll need to add an option to allow the dependency to be brought in even if the mode isn't set to it so it can be switched to at runtime. I could add an option so a list of desired modes to support can be passed so that browserify-hmr makes sure to pull in the right dependencies for all of them so they can be switched to at runtime.

kentor commented 8 years ago

Thanks a lot! :+1: It's working great. Definitely a feature that is missing from webpack's hmr