就像提到的其他答案一样,由于此评论中提到的原因,npm 不支持此方法
但是您可以使用semver包和 npm 脚本通过在package.json
"scripts": {
"beta-version-patch": "npm version $(semver $npm_package_version -i prerelease --preid beta)",
"beta-version-minor": "npm version $(semver $npm_package_version -i preminor --preid beta)",
"beta-version-major": "npm version $(semver $npm_package_version -i premajor --preid beta)",
"rc-version": "npm version $(semver $npm_package_version -i prerelease --preid rc)",
"final-release": "npm version $(semver $npm_package_version -i)"
}
并运行npm run beta-version-patch
为了更通用,您可以使用以下内容:
"scripts": {
"semver": "npm version $(semver $npm_package_version -i $release --preid $preid)"
}
并运行以下命令:
release=prerelease preid=alpha npm run semver
release=prerelease preid=beta npm run semver
release=premajor preid=alpha npm run semver