Processing ERB files with Rails Webpacker
This blog post was originally published a little while ago. Please consider that it may no longer be relevant or even accurate.
When using Webpacker you may want to interpolate some values into your assets. For example, API keys are best to come from the deployment environment rather than being hard-coded into your assets. With Webpacker this is really easy, you can just append .erb
to your scripts and import it.
First, import the script that requires processing including the .erb
suffix.
Then just include your embedded Ruby as you would usually.