I would like to package a js.erb file with esbuild. In my app, a user clicks on a 'Buy' button, which is connected to a Stimulus controller. The Stimulus action redirects to Stripe, but needs a public key. I want to read that key from the Rails credentials at esbuild-time, rather than hard-cding it into the js-file. Akin to
import { Controller } from "@hotwired/stimulus"
export default class extends Controller {
redirect(event) {
// event.preventDefault();
const stripe = Stripe("<%= Rails.application.credentials[:stripe][:public] %>");
stripe.redirectToCheckout({...});
}
My esbuild line in package.json:
"build": "esbuild app/javascript/*.* --bundle --sourcemap --outdir=app/assets/builds",
I tried without success
Sprockets.register_mime_type 'application/javascript', extensions: ['.js.erb']