How can I change an environment variable at build time?

145 views Asked by At

I have the following environment.ts file:

export const environment = {
    serverUrl: 'anything',
};

I often need to change this serverUrl, so I want to change this property by CLI, for example: ng build --configuration=production serverUrl:'http://whatever'. I don't want to create one environment to each server

I've read this answer which say to use the @ngx-env/builder. Then, I've installed the package and changed my env.d.ts file:

interface ImportMetaEnv {
  readonly NG_SERVER_URL: string;
  [key: string]: any;
}

But when I tried to run the command: NG_SERVER_URL=anything ng build --configuration I received the classic error:

The term 'NG_SERVER_URL=anything' is not recognized as the name of an operable cmdlet, function, script file, or program.

What am I doing wrong? Is there another approach to change this URL at build time?

0

There are 0 answers