I need to display git revision on my angular2 application\'s about page. The project is based on angular-cli.
How can build be extended so git revision is put for exampl
I like to keep things simple. Can add to your index.html:
Then add a postbuild
script to your package.json
:
"postbuild": "sed -i '' \"s/{git\\-hash}/$(git rev-parse --short HEAD)/g\" dist/*/index.html"
Not elegant by any means. Personally I create an object on window
with various information about the build (time, version, and a release summary link).
To stay more 'pure', stick the {git-hash}
string in environment.prod.ts
and run the sed
against all main-*.js
files produced.
"postbuild": "sed -i '' \"s/{git\\-hash}/$(git rev-parse --short HEAD)/g\" dist/*/main-*.js"
Note you'll always see '{git-hash}' running locally as it's only replaced post-build. If you replace it before the build, obviously can't replace it on future builds locally and would most definitely accidentally check that in.
---- UPDATE ----
Ended up creating a library to pull various information. Only ended up using version, build time, and commitTime personally.
https://www.npmjs.com/package/@rippell/ngx-build-info