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

前端 未结 8 1002
故里飘歌
故里飘歌 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:11

    I solved this by appending a comment at the end of index.html with the last commit hash. For example:

    ng build --prod
    
    git rev-parse HEAD | awk '{print ""}' >> dist/index.html
    

    You can then do a "View Source" in the browser, look at the bottom of the HTML, and see the deployed version of your app.

    This of course assumes that you use git as the versioning system. You could easily change git rev-parse HEAD with any other command that outputs a unique version.

提交回复
热议问题