This an enhancement of the approach in https://github.com/lucasklaassen/angular-rollbar-source-maps
During the build the file src/environments/version.ts is automatically generated containing the definition of the current Git revision:
// this file is automatically generated by git-version.js script
export const version = {revision: '12f54f9'};
Import that version.ts file into the file where you create your Rollbar.Configuration and use it to set your code_version Rollbar parameter.
The same version is used when uploading the source maps and informing Rollbar of the deploy.
The entire process is initiated by a single command:
npm run prod
- Edit
package.jsonand add this line to thescriptssection:
"prod": "node git-version.js && ng build --prod --source-map && node rollbar-deploy.js"
- Create a
.envfile with values populated for (you probably want to add.envto your.gitignorefile also):
ROLLBAR_WRITE_ACCESS_TOKEN=
MAIN_APP_URL='https://...'
ROLLBAR_USERNAME=
npm install dotenv- Copy
git-version.jsandrollbar-deploy.js(below) into the same directory as yourpackage.json - Edit
rollbar.tsto import theenvironment/version.tsfile and set theversionin the Rollbar configuration.