Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

371
Views
Sprockets //= require with jsbundling-rails (esbuild) - how to include JS provided by gem?

Basically, exactly as the title says. I have a gem installed that gives me some JS to use. This wasn't a problem before as I was using Sprockets + Assets pipeline.

Now, I migrated to jsbundling-rails and have literally no idea how to include that JS code provided by gem. I've spent like 10 hours searching and no luck so far.

Please, help me.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The gem would have to have a js package that can be installed with yarn/npm so that it can be imported in application.js. If it doesn't, you can setup a js file to be processed only by sprockets, like in the old days.

Add another javascript entry point that will skip esbuild and will be processed only by sprockets.

Update manifest:

// app/assets/config/manifest.js

//= link custom.js

Add //= require directive:

// app/assets/javascripts/custom.js

//= require gem_javascript

Add it to layout:

<!-- app/views/layouts/application.html.erb -->

<%= javascript_include_tag "application", "custom", "data-turbo-track": "reload", defer: true %>

Alternatively, instead of using //= require add it to javascript_include_tag:

<%= javascript_include_tag "application", "gem_javascript", "data-turbo-track": "reload", defer: true %>

Might have to add it to manifest as well for precompilation:

// app/assets/config/manifest.js

//= link gem_javascript
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!