Christopher Townsend
Christopher Townsend

Reputation: 1745

NPM build with version number

Is there a way to update the version number of my react app package.json version variable via command line? Maybe with npm build or before/after npm build?

I have a build server that will run npm build and then deploy to production. I want to be able to update the version number of my application either during the build process or before it as part of the build pipeline. I am planning to just use the last git commit sha as the version number.

Is there a command that I am missing? I have had a look at npm version but I believe that is for just updating packages. I could be wrong.

Upvotes: 4

Views: 3581

Answers (2)

Mehmet Onar
Mehmet Onar

Reputation: 353

npm version [major|minor|patch] 

if you get "npm ERR! Git working directory not clean." you should

npm version [major|minor|patch] --no-git-tag-version

Upvotes: 0

Nipuna
Nipuna

Reputation: 372

You can use,

npm version [major|minor|patch]

to bump the version variable on package.json using cli.

If you want to combine it with the build, you can use;

npm version [major|minor|patch] && react-scripts build

References

  1. npmjs.com for syntax documentation.
  2. semvar.org for version notation.

Upvotes: 0

Related Questions