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 instead of Webpack #85

Open
siba2893 opened this issue Aug 3, 2022 · 8 comments
Open

Vite instead of Webpack #85

siba2893 opened this issue Aug 3, 2022 · 8 comments

Comments

@siba2893
Copy link

siba2893 commented Aug 3, 2022

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?

@BrandonShar
Copy link
Collaborator

BrandonShar commented Aug 5, 2022

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?

@awkward-minion
Copy link

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.

@wJoenn
Copy link

wJoenn commented Apr 29, 2023

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

@BrandonShar
Copy link
Collaborator

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!

@wJoenn
Copy link

wJoenn commented Apr 29, 2023

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 🙂

@PedroAugustoRamalhoDuarte
Copy link
Contributor

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.

@iamajvillalobos
Copy link

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

@PedroAugustoRamalhoDuarte
Copy link
Contributor

@iamajvillalobos for now you can use this template to get some inspiration: https://github.com/BrandonShar/inertia-rails-template

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 a pull request may close this issue.

6 participants