Aurelia 2: pass build-time variables (dot env?) to browser

Hi,
I need to register the http api service in the container, however - depending on the environment, a different backend URL should be used.

Aurelia 1 used to have environment files with a webpack loader (if I recall correctly) so it was possible to access environment-specific values in the browser app.

What is the approach in Au2? The stub app includes webpack dotenv plugin, but to my understanding it is intended for compile-time only?

I just use it like this:

.env and .env.development both have something like this in them:

API_BASE_URL=...

then in my code I use it like this: process.env.API_BASE_URL

Works for dev mode and production builds.

1 Like