Use env var in a static web file (ejected)

I have an ejected project and I build my web with expo tools.

I want to have a JS file in a static directory that has replaced env variables. I already tried this:

Steps that I expected it to work:

  1. Add babel variable substitution plugin (from URL)
  2. Include the variable into the babel substitution plugin as it’s done in the expo tutorial from the URL
  3. Create /web/file.js
  4. Add a reference to env variable into the JS file. I used this content and none of these were substituted:

I’d like to know a good way to handle this.
Alternatively I consider fetching the data inside that JS file from back-end or generating that JS file using a template (during the build step).

I’d prefer to not involve back-end in this and I’d also prefer that this templating work would be done by env library and not by me.


This is what I’ll use in my build step for now:

yarn run babel --plugins "react-native-dotenv,transform-inline-environment-variables" web-pre-babel/hi.js