Repository navigation
Conversation
nesquena
left a comment
There was a problem hiding this comment.
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:
autoBuildbuilds intopublic/vite-dev. - Production:
rake assets:precompilewrites the manifest, and Padrino serves the hashed asset. Without a build the app still boots; only pages that use the tag error. - Test:
autoBuildworks.
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
activesupportdependency and overridevite_preload_tagin a small generated initializer, with the samerespond_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: withskip: true, an existingpackage.jsonis left withoutvite/vite-plugin-ruby, but the message still says "Runnpm installto install Vite". When the file exists, printingnpm install -D vite@^8.0.0 vite-plugin-ruby@^5.2.5would 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.
--leanand--api:--leanhas noapp/app.rb, soregister VitePadrinois skipped silently.--apiregisters VitePadrino but notPadrino::Helpers, so the tags aren't usable.- Binstub warning:
rake assets:precompilewarns "vite binstub not found". Generatingbin/vite, or mentioningbundle 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=vitepath, thepackage.jsonskip, or the admin interaction.
The padrino-gen suite passes (246 runs) and rubocop is clean.
Generated by Claude Code
# Conflicts: # CHANGES.rdoc
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>
|
Thanks @osbre! This shipped in #2351 (2b2c1a0). Your commits are there unchanged, and the squash commit credits you with On top, each with a test:
Generated by Claude Code |
Adds Vite as a script component:
It sets up
vite_padrino(Gemfile,register VitePadrino, config files, anapp/frontendentrypoint, rake tasks,Procfile.dev) without running npm, then tells you tonpm installand addvite_client_tag/vite_javascript_tag 'application'to your layout.activesupport(justobject/try) is added to the Gemfile for now, sincevite_padrino3.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).