inertiajs / inertia-rails

The Rails adapter for Inertia.js.

Home Page:https://inertiajs.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Vite instead of Webpack

siba2893 opened this issue · comments

Looking at the generators I was checking that the vue installer only works for webpacker apps, which in Rails 7 is not gonna be the main way to go. Will this be updated anytime soon?

That's a good question! Internally we've definitely made the switch to Vite and are recommending it going further, but we actually weren't sure if the installers were getting good use and if something like a rails app template would make more sense for the future.

Updating the installers is a little more difficult now in a webpacker-less world because there aren't as many standards to fall back on. Before, we'd generally know what a rails webpacker setup looked like so we could make good guesses about what code to add and change; now there's a lot more guesswork.

I think we're deciding between:

  • Update the installers, but ONLY for a fresh install of rails or an existing vite_ruby setup.
  • Create a separate rails app template that includes inertia and a vite_ruby setup
  • Deprecate the installers and document step by step our recommended front end setup.

Do any of those seem obviously better or worse to you?

Does this post help (in the context of setup instructions) .
The template for using inertia with rails using vite as a bundler option for front-end work.

Hello, if you don’t mind me reviving this issue a bit, from what I understand your issue is that with Vite there aren’t really any standard of where the entrypoints folder will be is that right ?
This could easily be found by reading the config/vite.json file where the entrypoint directory’s path is written. You could the use that path to add your inertia.js inside the folder.
As for the html’s script tag that’s basically the same thing you’re doing but with vite’s helper tags instead of webpackers 🤔

Overall I think adding two options for webpacker (which is still widely used) and vite, in the same manner as what you did for js, would be great and I’d be happy to have a try at it if you want

Hey @wJoenn, just to clarify: your idea is that we can have an installer command that could work for either webpack or vite?

If that's correct and you want to take a shot at implementing it, I'd be happy to take a look!

Yeah I had the idea that we could check whether Vite is installed the same way you do for webpacker then proceed with an installation for the appropriate bundler.
I tried it out in one of my vite project and it worked

def test_webpacker_installation
  puts "Testing Webpacker installation..."

  unless system("./bin/rails webpacker:verify_install")
    puts "Webpacker is not installed"
    return
  end

  puts "Webpacker is installed"
end

def test_vite_installation
  puts "Testing Vite installation..."

  unless system("./bin/rails vite:verify_install")
    puts "Vite is not installed"
    return
  end

puts "Vite is installed"
end

test_webpacker_installation
test_vite_installation

And the result of running this in the terminal :

➜  YogaUnalome git:(master) ✗ ruby tes.rb
Testing Webpacker installation...
rails aborted!
Don't know how to build task 'webpacker:verify_install' (See the list of available tasks with `rails --tasks`)

(See full trace by running task with --trace)
Webpacker is not installed
Testing Vite installation...
Vite is installed

I'm not available to start working on that today but I'll definitely try next week, thanks for the opportunity 🙂

I think it's a good idea to revisit this to make setting up inertia-rails easier with the new Rails 7.1. Personally, I always use a template, but it seems like the standard gem always has some good opinionated installer command.

  • Maybe we can deprecate the Webpack option and support "vite_ruby".
  • I think "vite_ruby" is the best option, but it's not the default for Rails apps. Maybe it's good to also support "https://github.com/rails/jsbundling-rails"?

I can help with that.

I'm looking to test this approach but not sure where to start.