How to insert a Build Number or Timestamp at build time in AngularCLI

前端 未结 8 986
故里飘歌
故里飘歌 2020-12-04 08:51

I want to have a timestamp or build number somewhere on my Angular2 App so I can tell if a user is using an old cached version or not.

How to do this with AngularCLI

8条回答
  •  一整个雨季
    2020-12-04 09:14

    Add this step to your build (ie Jenkins-Job):

    echo export class MyVersion {public static readonly number = '%SVN_REVISION%'} > src\my-version.ts
    

    You can access the number like this:

    import {MyVersion} from "../my-version";
    
    export class AppComponent {
        constructor() {
            console.log("Welcome to MyApp version " + MyVersion.number);
        }
    }
    

    This solution is + lightweight, + easy to read, + robust.

提交回复
热议问题