Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vite_rails: Improve default deployment and dev enviroment support #491

Open
bamnet opened this issue Aug 28, 2024 · 5 comments
Open

vite_rails: Improve default deployment and dev enviroment support #491

bamnet opened this issue Aug 28, 2024 · 5 comments
Labels
documentation Improvements or additions to documentation

Comments

@bamnet
Copy link

bamnet commented Aug 28, 2024

Rails 7.2+ ships with features like the ability to generate a devcontainer for development, Github Action to run tests and Rails 8 will ship with Kamal configured by default for deployment.

It would be helpful if vite_rails integrated into these systems automatically or (as a fallback) documented what steps users need to take in order to work with these new defaults.

At a first pass, I ran into trouble with:

  • Github Action tests where vite wasn't installed (solved by manually adding run: npm install)
  • Kamal, where npx wasn't installed
  • Devcontainers - untested.

There are some pointers in the existing docs, like a dependency on npx and some notes about devcontainers port forwarding, but I think it would be helpful to have very clear steps for Rails users as part of the vite_rails setup docs.

For example, I'm not sure if I should actually be running npm install in my Github Action or if there's a bug somewhere in vite:install_dependencies or other hooks which should automatically install the deps.

@ElMassimo ElMassimo added the documentation Improvements or additions to documentation label Aug 28, 2024
@ElMassimo
Copy link
Owner

Hi Brian!

The guide recommends running assets:precompile in the CI, which should install dependencies, although it's more robust to do it explicitly.

I'm not familiar with Kamal or Devcontainers, happy to include setup guides in the docs. Instructions should be concise, following the existing style of the docs. Alternatively, we can link to other resources that go into more detail of how to setup either.

@mattbrictson
Copy link
Contributor

I have not used them personally, but I believe Kamal and Dev Containers are both based on Docker. When you run rails new and specify a Node-based build system, like --javascript esbuild, Rails will automatically inject the necessary Node steps into the generated Dockerfile, like this:

# Install JavaScript dependencies
ARG NODE_VERSION=20.17.0
ARG YARN_VERSION=1.22.22
ENV PATH=/usr/local/node/bin:$PATH
RUN curl -sL https://github.com/nodenv/node-build/archive/master.tar.gz | tar xz -C /tmp/ && \
    /tmp/node-build-master/bin/node-build "${NODE_VERSION}" /usr/local/node && \
    npm install -g yarn@$YARN_VERSION && \
    rm -rf /tmp/node-build-master

# Install node modules
COPY package.json yarn.lock ./
RUN yarn install --frozen-lockfile

Likewise, it adds a Node "feature" to .devcontainer/devcontainer.json:

"features": {
  "ghcr.io/devcontainers/features/node:1": {}
}

The problem is that Vite is not a supported option for rails new. For starting new Vite Rails apps, I recommend using rails new --javascript esbuild as a workaround to ensure the necessary Node pieces are in place, then proceed with the Vite installer.

The Vite Ruby docs could be updated to explain this, and/or mention specifically how to update the Docker files and GitHub actions workflow after the fact.

@planetaska
Copy link

Second the documentation website needs a thorough review. Many sections simply state, “You can use this (link to GitHub page),” without explaining what to expect or how to configure the options correctly. This is especially problematic when certain options are incompatible with each other.

Additionally, I can no longer get vite_rails to work on a freshly created Rails 8 app. The significant changes since Rails 7.0, combined with conflicting or outdated documentation, make it difficult to resolve these issues.

If you try creating a new Rails 7.2 or 8 app with: rails new --javascript esbuild, and then install the vite_rails gem along with vite_plugin_rails, you will encounter issues such as misconfigured Procfile, wrong javascript path, and many other strange problems. I hope we can at least have a working app after following the installation steps.

@adenta
Copy link

adenta commented Dec 18, 2024

@planetaska I just skip javascript and then run the standard vite ruby install steps

@Peredery
Copy link

Peredery commented Jan 13, 2025

Is it still broken with rails new --javascript esbuild?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

6 participants