例如:
{
"name": "wdd",
"version": "0.0.0",
"private": true,
"scripts": {
"start": "node ./bin/www"
},
"dependencies": {
"body-parser": "^1.13.2",
"cookie-parser": "~1.3.5",
"ejs": "*",
"express": "~4.13.x",
}
}
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
~x.y.z: 匹配大于 x.y.z 的 z 的最新版
^x.y.z: 匹配大于 x.y.z 的 y.z 的最新版
当 x 为 0 时,^x.y.z 等价于 ~x.y.z,即只会安装z 的最新版本;
当 x 和 y 为 0 时,^x.y.z 等价于 x.y.z,即只会安装x.y.z 版本;
*: 任意版本,一般是最后一次正式发布版本(包括非 latest tag),不是最大版本号版本
这是一种叫
semver的版本表示法,~^*x都是范围表示方式,参考:semver-ranges<Less than<=Less than or equal to>Greater than>=Greater than or equal to=Equal. If no operator is specified, then equality is assumed, so this operator is optional, but MAY be included.*:= >=0.0.0 (Any version satisfies)1.x:= >=1.0.0 <2.0.0 (Matching major version)1.2.x:= >=1.2.0 <1.3.0 (Matching major and minor versions)