Skip to content

Add Vite script component - #2334

Closed
osbre wants to merge 3 commits into
padrino:masterfrom
osbre:vite-script-component
Closed

osbre wants to merge 3 commits into
padrino:masterfrom
osbre:vite-script-component

Conversation

@osbre

@osbre osbre commented Oct 13, 2026

Copy link
Copy Markdown
Member

Adds Vite as a script component:

padrino g project demo --script=vite

It sets up vite_padrino (Gemfile, register VitePadrino, config files, an app/frontend entrypoint, rake tasks, Procfile.dev) without running npm, then tells you to npm install and add vite_client_tag / vite_javascript_tag 'application' to your layout.

activesupport (just object/try) is added to the Gemfile for now, since vite_padrino 3.0.0 crashes without it when entrypoints share a chunk. Fixed upstream in ElMassimo/vite_ruby#635; the Gemfile comment says to drop it once that's released.

Tested on a generated app (Ruby 4.0.6, Vite 8).

@nesquena nesquena left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this works well. I generated real ERB, Haml and Slim projects, bundled them against this branch, ran npm install, and checked all three environments:

  • Development with vite dev: the client and entrypoint are served through the dev-server proxy, and HMR reloads the page on edit.
  • Development without the dev server: autoBuild builds into public/vite-dev.
  • Production: rake assets:precompile writes the manifest, and Padrino serves the hashed asset. Without a build the app still boots; only pages that use the tag error.
  • Test: autoBuild works.

It also works on Ruby 3.1–3.3 with the current vite_ruby 3.11.1, Rack 3 and Sinatra 4. Running padrino g component --script=vite twice adds nothing a second time.

Blocker: the activesupport Gemfile line conflicts with padrino g admin

The component adds gem 'activesupport', require: '...' with no version, and padrino-admin's generator adds gem 'activesupport', '>= 3.1' (admin_app.rb:137). Bundler then refuses the Gemfile:

padrino g project p --script=vite --orm=activerecord && cd p && bundle install
bundle exec padrino g admin
bundle install
# There was an error parsing Gemfile: You cannot specify the same gem twice with
# different version requirements. You specified: activesupport (>= 3.1) and activesupport (>= 0).

Running padrino g component --script=vite on a project that already has admin should hit the same problem. That's from reading the code; I didn't run it.

Two possible fixes:

  • Preferred: drop the activesupport dependency and override vite_preload_tag in a small generated initializer, with the same respond_to? change as your upstream PR. That avoids about ten gems for one method, and it doesn't depend on a vite_padrino release. vite_padrino hasn't had one since 3.0.0 in August 2021.
  • Minimal: declare gem 'activesupport', '>= 3.1', require: 'active_support/core_ext/object/try'. With matching requirements, Bundler accepts both orders and only warns about the duplicate.

Also needed: a CHANGES.rdoc line under == Unreleased, e.g. - NEW #2334 Vite script component: padrino g project --script=vite (@osbre).

Smaller points (optional)

  • Wording about the upstream fix: vite_ruby#635 isn't merged yet, so the PR body and the Gemfile comment's "remove once … is released" read as if the fix is done. Worth saying it's pending.
  • Existing package.json: with skip: true, an existing package.json is left without vite/vite-plugin-ruby, but the message still says "Run npm install to install Vite". When the file exists, printing npm install -D vite@^8.0.0 vite-plugin-ruby@^5.2.5 would be accurate.
  • Layout instructions: they're always in ERB syntax, even for Haml and Slim projects, and Padrino doesn't generate a layout file to add them to.
  • --lean and --api: --lean has no app/app.rb, so register VitePadrino is skipped silently. --api registers VitePadrino but not Padrino::Helpers, so the tags aren't usable.
  • Binstub warning: rake assets:precompile warns "vite binstub not found". Generating bin/vite, or mentioning bundle binstub vite_ruby, would avoid it.
  • Version pin: gem 'vite_padrino', '~> 3.0' would match the other components and guard against a surprise 4.x.
  • Test coverage: the test doesn't cover the padrino g component --script=vite path, the package.json skip, or the admin interaction.

The padrino-gen suite passes (246 runs) and rubocop is clean.


Generated by Claude Code

@osbre
osbre requested a review from nesquena October 13, 2026 12:46
nesquena added a commit that referenced this pull request Oct 14, 2026
Adds `--script=vite` (vite_padrino) for `padrino g project` and `padrino g component`, with the ActiveSupport Object#try workaround until ElMassimo/vite_ruby#635 ships. Salvage of #2334.

Co-authored-by: Ostap Brehin <osbre@protonmail.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Copy link
Copy Markdown
Member

Thanks @osbre! This shipped in #2351 (2b2c1a0). Your commits are there unchanged, and the squash commit credits you with Co-authored-by. It goes out in the next release.

On top, each with a test:

  • appended Procfile.dev/.gitignore lines start on a new line;
  • edited Vite files are kept on re-run;
  • the activesupport line matches admin's;
  • an existing Procfile.dev gets the vite process;
  • projects without a Gemfile or Rakefile no longer stop halfway;
  • component files are read as UTF-8, so -s vite works under a C locale.

Generated by Claude Code

@nesquena nesquena mentioned this pull request Oct 15, 2026
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