使`npm install --save`添加一个严格的版本到package.json [英] Make `npm install --save` add a strict version to package.json

查看:129
本文介绍了使`npm install --save`添加一个严格的版本到package.json的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

运行npm install --save somepackage时,通常会在package.json中添加如下内容:

When you run npm install --save somepackage, it usually adds something like this into package.json:

"dependencies": {
    "somepackage": "^2.1.0"
}

因为该版本前面带有脱字符号(^),这意味着如果以后运行npm install,它可能会安装2.3.0版.由于相当明显的原因,这可能是不希望的. npm shrinkwrap是有用的,但不能真正解决问题.

Because the version is prepended with a caret(^), this means that if you later run npm install, it might install version 2.3.0 instead. This can be undesirable for fairly obvious reasons. npm shrinkwrap is useful, but doesn't really solve the problem.

所以,我有几个问题:

  1. 在安装软件包时,是否可以在package.json中指定要将其设置为特定版本(版本号前无需插入符号)?
  2. 将软件包发布到npm时,是否有任何方法可以防止其他开发人员安装软件包时在版本之前包含插入号?

推荐答案

要默认指定确切版本,可以使用

To specify by default a exact version, you can change your npm config with save-exact:

npm config set save-exact true

您还可以使用保存前缀用波浪号指定前缀版本.

You can also specify the prepend version with a tilde with save-prefix

而且,不,您不能强迫用户更新到次要版本或补丁程序版本,NPM使用 semver ,这是发布软件包的推荐方法.

And, no you can't force user to update to a minor or a patch version, NPM uses semver and it's the recommend way of publishing packages.

这篇关于使`npm install --save`添加一个严格的版本到package.json的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆