Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to inject commit hash in environtment.ts in angular-cli

Is it possible to generate environment object asynchronously?

Reason: I would like to have available commit hash in my application. Idea is to use environment.ts file. However to obtain current commit hash I need asynchronous call (eg. using git-rev).

I tried to inject variable from environment variables using process.env: $ VERSION=123 ng serve

declare var process: any;

export const environment = {
  production: false,
  version: process.env.VERSION
};

But this results in undefined version.

like image 453
Martin Nuc Avatar asked Feb 27 '17 23:02

Martin Nuc


1 Answers

Take a look at this question : How to include git revision into angular-cli application?

There is also a discussion on github on this related subject, which it will be easier to add possibility to pass environment variables to environment.ts : https://github.com/angular/angular-cli/issues/4318

like image 148
Alexandre Duros Avatar answered Nov 17 '22 04:11

Alexandre Duros