ElMassimo / vite_ruby

⚡️ Vite.js in Ruby, bringing joy to your JavaScript experience
https://vite-ruby.netlify.app/
MIT License
1.28k stars 117 forks source link

vite_hanami in hanami 2.1 #446

Open krzykamil opened 5 months ago

krzykamil commented 5 months ago

Discussed in https://github.com/ElMassimo/vite_ruby/discussions/445

Originally posted by **krzykamil** March 26, 2024 Hey So currently the vite_hanami is broken to my understanding. It is probably meant for hanami pre 2.0, and now we have 2.1 which has its own, default way of doing views and assets. However if someone wants to use hanami views, but not assets and wants to use vite, the current state of this gem, does not work for this purpose. The tag helpers use non-existing methods, need to be included in a different way, in a different place, the vite-dev folder in public does not get generated etc. In general for hanami, the gem is severely out-of-date. I was wondering if there are any plans/work in progress, to get it working again for hanami 2.1? If not, would you accept PR's that try to make it work with the newer hanami? It would be aimed for integrations that use hanami-views but skip hanami-assets I guess, although I am not sure. Without hanami-assets there are no tag halpers like javascript_tag etc. but everything else would be obsolete from that gem if using vite.
wout commented 2 months ago

I'm in the same boat. We'll start building a Hanami 2.1 app next month and another one in September. Our front-end devs want to use Vite for convenience, familiarity, and because Hanami's default setup is lacking features (HMR being the most important one).

I was also wondering if vite_hanami could just build on esbuild since hanami-assets is using it. I'm not sure if that makes sense, though.

krzykamil commented 2 months ago

Since hanami-assets is just a gem that is optional, you can just start your project without it, and add vite separately, this will however include doing your own asset helpers for the views and all.

Right now all solutions I saw were kinda workarounds, maybe not really suitable for real production projects, but if someone comes up with something I'll gladly help. However now, the problem I've outlined in the linked discussion is making most solutions pointless due to how strongly hanami-assets is connected to esbuild.

Making a sensible vite integration would probably require changes to hanami lib itself

wout commented 2 months ago

Yeah, we can't have workarounds. I don't mind creating a PR. I've done it before with lucky_vite, so it's not new to me. But I'll need to look at both ends (Hanami and vite_ruby) to see how it all fits together while staying as close as possible to Hanami's API.