Skip to content

Load .env environment variables for vite dev#540

Open
ryansch wants to merge 1 commit into
ElMassimo:mainfrom
detaso:vite-dev-env-vars
Open

Load .env environment variables for vite dev#540
ryansch wants to merge 1 commit into
ElMassimo:mainfrom
detaso:vite-dev-env-vars

Conversation

@ryansch

@ryansch ryansch commented Apr 10, 2025

Copy link
Copy Markdown

Description 📖

This pull request ensures that Rails has initialized before running the vite dev server.

Background 📜

I noticed that setting VITE_RUBY_* environment variables via .env.* files would work for vite build but not for vite dev.

The Fix 🔨

I generalized the ViteRails::CLI::Build module to apply to both vite build and vite dev.

@ryansch

ryansch commented Feb 19, 2026

Copy link
Copy Markdown
Author

We've been running this in production (and development) for almost a year without issues.

@ryansch ryansch force-pushed the vite-dev-env-vars branch from 4e47b97 to ce1bb02 Compare March 6, 2026 19:48
@ryansch

ryansch commented Mar 6, 2026

Copy link
Copy Markdown
Author

@ElMassimo Any chance of getting eyes on this? I'd love to not need to maintain a fork.

@ElMassimo

Copy link
Copy Markdown
Owner

Hi Ryan. I'd like to make this optional.

One of the advantages of the Vite dev server is that it starts very fast, which is wasted if you boot Rails first.

@ryansch

ryansch commented Jun 12, 2026

Copy link
Copy Markdown
Author

The problem I have is that without this patch, the server starts with an incorrect configuration.

I'm setting these 3: VITE_RUBY_HOST, VITE_HMR_HOST, and VITE_HMR_CLIENT_PORT. I'm using puma-dev for local development and this gets me full TLS with a proper hostname. It works great if vite dev loads me .env.local file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants