So what are going to do about?:
- We’ll hash our file names each build so we know when they have changed
- We’ll create version.json in our dist folder which holds the current build hash and also enter the current build hash into the code itself.
- We’ll make frontend poll the version.json every X minutes to check if the hash has changed compared to it’s “inner” hash.
- If it has, we’ll reload the client either forcefully or gracefully by giving a pop-up / other kind of notification about the new version.
Need to import Reload module and configuration in app.component.html and all Done 😊
-
Create Angular 4 project with angular-cli .
-
with ng build --prod and you’ll get bunch of files in your /dist/ folder, one of them being /dist/main.somehash.bundle.js
-
Next, I’ve created a /build/post-build.js file. post-build is just a script in our package.json:"post-build": "node ./build/post-build.js"
-
After running this script, you should have version.json in the /dist/folder with something like: