Vite Rails running on Docker
A minimal example on how to configure Docker to run a Vite.js process alongside a Rails app.
The integration is powered by Vite Rails.
To prepare the Docker image, run:
docker-compose buildTo start the Rails and Vite services, run:
docker-compose upOnce you have started both services, you can verify that the Vite dev server can be reached from Rails by running:
docker-compose run --rm --entrypoint "bin/rails c" railsand then:
> ViteRuby.instance.dev_server_running?
=> trueNow that you have learned the basics, please follow this guide instead for a more comprehensive configuration:
At the time of writing, the guide covers how to use Webpacker, but configuring Vite Rails should be very similar:
- Use
bundle exec ./bin/vite devinstead ofbundle exec ./bin/webpack-dev-server - Expose port
3036instead of3035 - Rename the
webpackerservice tovite - Rename
WEBPACKER_DEV_SERVER_HOSTtoVITE_RUBY_HOST:- Including
WEBPACKER_DEV_SERVER_HOST: webpackertoVITE_RUBY_HOST: vite
- Including