chihab/dotenv-run

Set the environment with--configuration option

mhkolk opened this issue · 5 comments

The extension/CLI is not picking up .env files for example .env.production (present in the same dir as package.json) with NG_APP_ENV being undefined even though valid Angular configuration was provided through ng build.

PS C:\Git\myproj> ng build --configuration production
------- @ngx-env/builder -------

  • Verbose: true
  • Prefix: NG_APP
  • Working directory: C:\Git\myproj
  • Environment files:
    ✔ C:\Git\myproj.env
  • Injected keys:
    ✔ NG_APP_ENV => undefined
    ✔ NG_APP_API_FQDN
    ✔ NG_APP_API_URL

None of the default (development, production) files are being picked up, it only detects .env and .env.local (if I place it in the same dir).

Could you try this?

NG_APP_ENV=production ng build

It should pick .env.production and .env if present

This worked though I had to use different syntax (Windows).

$env:NG_APP_ENV='production'

However I can't do this for example

"build:dev": "$env:NG_APP_ENV='k8s-dev'; ng build --configuration k8s-dev",

results in

The filename, directory name, or volume label syntax is incorrect

Why wouldn't be providing configuration with the --configuration option enough?

maybe you'd want to use cross-env package to set the environment variable.

start: cross-env NG_APP_ENV=k8s-dev ng build --configuration k8s-dev

Your other suggestion to set NG_APP_ENV to the configuration option (when not set via NODE_ENV/NG_APP_ENV) is also interesting, thinking about it.

I intuitively assumed that this environment would be set if I used the --configuration option, but I guess not 😅 Please do consider this as an option. This package would be a good replacement for the built-in file replacements with minimal effort if this was the default behavior, in my opinion.

chihab commented

Available in @ngx-env/builder 17.0.6