I am totally new in React Js. Currently I need to auto update the version number whenever I build so that the browser can automatically reload the JS/CSS files without having to clear the cache manually. Is there any way to do this? I searched but most of it is for .net answers. Really appreciate any guidance and helps..Thank you

2

There are 2 answers

2
James White On

Looks like you can easily do this with a small NPM package that is already pre-built

https://richhewlett.com/2020/07/11/auto-increment-build-number-in-a-javascript-app/

0
Dorian B On

There is also an npm package named auto-version-js which allows you to automatically increase your version number :

npx auto-version --patch  # +0.0.1
npx auto-version --minor  # +0.1.0
npx auto-version --major  # +1.0.0

To implement it in your package.json file :

"scripts": {
  "dev:patch": "npx auto-version --patch",
  "dev:minor": "npx auto-version --minor",
  "dev:major": "npx auto-version --major"
}

The documentation is available here.