Search code examples
angularbuildversionauto-incrementenvironment

Automatic version increment of angular build while building angular project every time


I am an angular developer. and as a requirement of company, I need to add version into my angular project's one page(component).

for manage version. I did make one variable called "Version" in environment/environment.ts and other environment's files.

Now current flow of version is like this :

  1. Increase version variable value into environment file.
  2. Then make a build using this command : ng build --prod -c production
  3. It will replace environment.ts file with environment.prod.ts file in which I did increase the verison variable.
  4. Every time I need to increase version number manually and then I ran command for make a new build.

But Now I want to automate that version variable into environment files. while I run command with appropriate configuration, It should automatic increase version into appropriate file and then should made a new build.

I started to find this kind of scenario and solution on google before a week ago, but still not found any solution, how to achieve that.

If anyone have any idea about environment's variable change while build. then Please share it with me. It will really helpful for me.


Solution

  • Yes it's possible. Instead of using the values directly on environment files , you can use package.json file. Which will serve the purpose of increment the value automatically. Check the link for step by step guide.

    https://medium.com/@tolvaly.zs/how-to-version-number-angular-6-applications-4436c03a3bd3