Skip to content

ElMassimo/vite_rails_docker_example

 
 

Repository files navigation

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.

Setup 💿

To prepare the Docker image, run:

docker-compose build

To start the Rails and Vite services, run:

docker-compose up

Debugging 🐞

Once 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" rails

and then:

> ViteRuby.instance.dev_server_running?
=> true

Further Configuration 📖

Now 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 dev instead of bundle exec ./bin/webpack-dev-server
  • Expose port 3036 instead of 3035
  • Rename the webpacker service to vite
  • Rename WEBPACKER_DEV_SERVER_HOST to VITE_RUBY_HOST:

Languages

  • Ruby 78.7%
  • HTML 16.7%
  • JavaScript 1.9%
  • Dockerfile 1.2%
  • CSS 0.8%
  • TypeScript 0.4%
  • Shell 0.3%