-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Import assets from Ruby Gem #488
Comments
@frozenfung Just copy the static files into vendor folder and then reference them using module resolver or something - https://github.com/rails/webpacker#using-babel-module-resolver Or you could try adding your gem directory to module resolve in |
@gauravtiwari do you mean the vendor folder of the Gem or the final application? |
@JasonHerr Rails application vendor folder. You could put it anywhere though that makes most sense to you 👍 |
Finally I decide to resolve them from
How do you think? It is possible? |
@frozenfung Looks good 👍 Not sure if you need I have been thinking to add something like resolved_paths:
- vendor/bundle/gems
- engines/x_engine/assets/javascripts |
In dev, the path looks like /Users/frozenfung/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/rails-5.1 in prod, which we use docker /usr/local/bundle/gems/rails-5.1 I am not sure if I am the only one that has the situation. I think For example, if I would like to import a bootstrap js module from
with gem
Anyway we need to tackle the version either in If it's ok I would like to make a PR for this. |
@frozenfung Sorry, I am such late 😄 From your comment, gem doesn't seem like a place to store JS or CSS assets. The idea behind Does bower works normally if you add it to resolved path? I think it's not worth the effort. As you know most of the stuff are now moving to npm so perhaps use the time to migrate your packages to npm - more future proof that way. |
I decide to transfer all my gem-based assets into npm pkgs. Eventually, it is a must. :) |
It's great that you feel that way, but this is a frequently used pattern in the rails community. For example, turbolinks is a gem that includes assets that are included via the asset pipeline. Turbolinks also has an npm package you can use, but this is not the case for most rails plugins (gems). Supporting this would be a huge step towards webpacker being a full replacement of the rails asset pipeline. |
I agree with @quinn , if Webpacker NPM is certainly the way to go for one to package its javascript and such, but I think it is illogical to have to depend on the individual gems to provide this. If Gems contain assets that don't make sense on their own ( For people that are looking for a (more elegant) solution, I've been toying with this. Feel to take a look and comment. With this I'm able to configure gems by name in my |
@justinvdk Gem devs have started to publish NPM "companion" packages like https://www.npmjs.com/package/ahoy.js |
@guilleiguaran once said there could be a helper to make this easily happen. And it seems Guillermo is the one with a lot of knowledge of sprockets and webpacker. Is this already available? 🤔 |
call me crazy but I did some messing around with this: https://api.rubyonrails.org/classes/ActionView/Helpers/AssetUrlHelper.html This allows me to still use sprockets for gems and use webpacker for my JS related things # development.rb
config.action_controller.asset_host = Proc.new { |source|
if source.include?('packs')
ENV['ASSETS_URL']
else
"http://localhost:3000"
end
} |
Hey guys,
I know it may be sound weird. But I do have a lot assets (scss, font) which are bundled with Gems. Right now I am not able to re-pack them all with NPM pkgs.
I would like to let webpack search around my Ruby Gems' nest for those treasures.
Recommended, crazy or suck?
thanks
Fung
The text was updated successfully, but these errors were encountered: