Skip to main content

How to import javascript from Gems with webpacker

Ruby • Asked by Alex Deering

Ive come across an issue where some gems I want to use (specifically social-share-button) need to have a javascript file imported but with webpacker in rails 6, not quite sure how to do that now


Just import it in app/javascripts/packs/application.js

import "../myfile"

And put your code in app/javascripts/myfile.js

Also check out https://gorails.com/episodes/webpacker-javascript-in-rails-6


ok so just downloaded the javascript file from the gem and did that and everything works...thanks


Yep, you can do that. Or if they have a node package, you can use that instead.


Login or Create An Account to join the conversation.

Subscribe to the newsletter

Join 27,623+ developers who get early access to new screencasts, articles, guides, updates, and more.

    By clicking this button, you agree to the GoRails Terms of Service and Privacy Policy.

    More of a social being? We're also on Twitter and YouTube.