admin管理员组

文章数量:1410730

Prior to publishing to NPM I need to bump the minor version. What I usually do is: - Change package.json - Run npm i which syncs package-lock.json with the change. Now both can be published.

Is there a way to do this with a single NPM mand?

Prior to publishing to NPM I need to bump the minor version. What I usually do is: - Change package.json - Run npm i which syncs package-lock.json with the change. Now both can be published.

Is there a way to do this with a single NPM mand?

Share Improve this question edited Mar 19, 2019 at 2:55 Ole asked Mar 18, 2019 at 11:46 OleOle 47.5k70 gold badges238 silver badges445 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 6

Use npm version.

For example, the following mand

npm version 1.0.2

will bump both package.json and package-lock.json to 1.0.2

The following mand

npm i -S <module>@<version>

installs the specific version of the given module.

-S or --save tells npm to save the reference of the module + version into both package.json and package-lock.json

It depends on the granularity of control you want to have. For example, if you just want to check for an update on an individual module you can run: npm update <pkg>. As this mand will update your package.json file to save the newest version of this <pkg> as the now required version to build your project. Alternatively, you could run npm update to update all your project's top-level packages. Ok so those are the more general use cases but if you want a specific version of a package and you know the version of which you desire you can do the following: npm i --save <pkg>@<version> as this mand will grab the package specified by your version number as well as update the package.json file to include this version of package as now being required to build your project. This will eliminate the need to first update the package.json file and then installing the newer version of said package, rather this will be condensed down to one step. Lastly, just for thoroughness the package-lock.json file is dynamically generated when you make important changes to your project, such as requiring new dependencies or updating existing dependencies. This file kind of serves as source of truth so others can build your project and have the same setup as you, for more information on this file take a look at the npm docs

Hopefully that helps!

本文标签: javascriptBumping packagelockjson and packgelock at the same timeStack Overflow