Sure, several ways! You can have a small node script that creates your 
appropriate *environment.ts* on build time. Something like with templating. 
Or, e.g. create a *version.json* on build time next to the env, and have 
your app load from there on start -  basically the same idea just slower. 
Example:

const environment = { version: process.env.VERSION, environment: 
process.env.ENV } // or whatever
require('fs').writeFileSync(`./src/environments/environment.${process.env.ENV}.ts`,
 
JSON.stringify(environment, null, 2));

Or you can have a maybe nicer-looking but more involved solution, something 
like gulp-template <https://www.npmjs.com/package/gulp-template>.

So your environment looks like this:


{
  version: '<%= APP_VERSION =>',
  environment: 'prod'
}


And just run through gulp template before you serve:

const gulp = require('gulp');
const template = require('gulp-template');
 
gulp.task('default', () =>
    gulp.src('src/environments/**')
        .pipe(template({APP_VERSION: '123 or whatever you want'}))
        .pipe(gulp.dest('dist'))
);


FWIW, mgechev's popular angular seed  
<https://github.com/mgechev/angular-seed>uses gulp-template to inject stuff 
throughout the entire code base, not just env files. I find that a serious 
overkill, if I need more than what I can fit into environment.ts (and nothing 
stopping you from putting an entire 100-line JSON in there), I would reconsider 
if I actually needed a backend for this purpose.

And usually I'll just need maybe two things, so a simple node script, without 
even the npm dependency, usually does it.

Zlatko



On Thursday, August 30, 2018 at 9:10:17 PM UTC+2, Reza Razavipour wrote:
>
> Angular CLI 6
> git
>
> I need to display a version number/tag as part of my applications. 
> My jenkins building the software does have access to the git version
> QA will report a bug and need to report it using a version number.
>
> Any clean way of using that build information to display in my application?
>

-- 
You received this message because you are subscribed to the Google Groups 
"Angular and AngularJS discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to