All threads / How to import javascript from Gems with webpacker

Ask A Question

Notifications

You’re not receiving notifications from this thread.

How to import javascript from Gems with webpacker

Alex Deering asked in Ruby

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.

Join the discussion

Want to stay up-to-date with Ruby on Rails?

Join 37,344+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    logo Created with Sketch.

    Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

    © 2020 GoRails, LLC. All rights reserved.