In an Angular (>= 2) application, how to include version information from npm package.json file into the compiled output files?

Viewed 516

Information:

  1. I have created an Angular (version >= 2) application using @angular/cli.

  2. This application is undergoing version changes.

  3. I do keep the semantic version information of my application updated inside my package.json file using the command npm version major or npm version minor or npm version patch.

  4. I was unable to find this version information inside any files on the "dist" output folder when I run ng build or ng build --prod.

Question:

Is there a way to bring my application's version information automatically from the package.json file into one of the output files (perhaps inside an html file or a js file)?

Sample from my package.json file:

{
  "name": "angular-ui",
  "version": "17.6.27",
  "description": "My awesome UI application",
  "license": "MIT",
  ...
}

Ideally, I would want to create an "about" component where I would like to publish my application's version information when I visit a URL similar to:

http://localhost:4200/about

Expected Output on the page:

Application version: v17.6.27
1 Answers
Related