How can I make HMR work with docker compose? #33
-
I have a new fresh rails application in which I want to use vite to build the frontend. I'm trying to get I followed the installation instructions and when I run However, when I do it from my docker-compose setup, the rails middleware behaves as if vite development server wasn't running. My findings so far are that this line: vite_ruby/vite_ruby/lib/vite_ruby.rb Line 94 in 436268b raises an exception informing that the other end has refused to connect. That makes me think that I need some extra configuration for this to work. I've tried:
What I think is happening is that I'm somehow not getting visibility of the websocket connection to the vite container from the rails container. Not sure if there's any other port or configuration I might need or if there might be a better and easier way to do this. Any help is more than welcome :) I've created a test application repo https://github.com/franciscoj/vite_example just in case anyone else wants to give it a look to help me find the solution, just clone and I'll be more than happy to help with a PR if any fix or improvement is needed for this to work :) Thanks a lot for |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Hi there! Forked your example, please take a look at https://github.com/ElMassimo/vite_rails_docker_example. The missing piece is setting Setting I don't use Docker in development, someone else might be able to provide a better setup 😃 |
Beta Was this translation helpful? Give feedback.
Hi there!
Forked your example, please take a look at https://github.com/ElMassimo/vite_rails_docker_example.
The missing piece is setting
VITE_RUBY_HOST
to0.0.0.0
in the Vite service, so that the process can receive external requests.Otherwise, the service will not be reachable by the Rails service.
Setting
hmr.host
tovite
causes a browser running in the host to attempt communicating withhttp://vite:3036
, which does not exist. Removing thehmr
option fromvite.config.ts
does the trick.I don't use Docker in development, someone else might be able to provide a better setup 😃