ElMassimo / vite_ruby

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

Ability to import from gem's folders #243

Closed Kukunin closed 2 years ago

Kukunin commented 2 years ago

Is your feature request related to a problem? Please describe. The problem is that we have a lot of gems relying on sprockets, and not everyone supports webpacker/vite_ruby approach. For example, activeadmin_sortable_table gem allows records to be re-ordered in ActiveAdmin. It provides both js and CSS file, but it can't be imported from the entrypoint directly.

Describe the solution you'd like It would be cool if it is possible to import assets from gem folders. So in my app/frontend/entrypoints/activeadmin.js I could do

import '~activeadmin_sortable_table/app/assets/javascripts/activeadmin_sortable_table.js'

I assume that an automatic alias can be added that is resolved to the bundle gem folder. I added the ~ just to make a difference from node_modules. The prefix can be anything (@gems/ etc)

Describe alternatives you've considered Currently, what I do is copy the assets to app/frontend and import them as usual. It's bad because once the dependent gem is updated, I need to copy assets one more time otherwise they will be outdated.

Additional context

ElMassimo commented 2 years ago

Fortunately, it's possible 😃

See this discussion for details, and feel free to share your particular setup in case it's useful for someone else.