How do I pass the environment info to javascript code with importmaps

Hi all! I’m using Rails 7 with importmaps and I’m trying to make JavaScript code conditionally depend on the environment specific config. At the very least, I’d need to pass what environment is it in the first place (dev, test, etc) and ideally I’d like to pass arbitrary env dependent configuration.

What I could do is serve a js file from a controller and create a global config var in it, serving whatever config info I want to be available to the js code.

But I’m wondering if I’m missing some obvious “official” way do so. Is there one?

I don’t know if there is such a thing as an “official” approach to this, but you could pass specific variables as data parameters on some DOM element of the layout, or even as CSS classes. Or maybe inline javascript in the head. I’d be interested to hear about other approaches as well. You can also aim for greater dev/prod parity to minimise the issue.