[英]Make your NPM package support multiple versions of peer depedency
I have a package on NPM that is using React version 15 as peer dependency.我在 NPM 上有一个使用 React 版本 15 作为对等依赖项的包。 However, I want it to stop from throwing warnings for users that upgraded their React version.
但是,我希望它停止向升级其 React 版本的用户发出警告。 How do I make package support both version 15 and 16?
如何使包同时支持版本 15 和 16?
"peerDependencies": {
"react-dom": "^15.0.0"
},
which is the most convenient way to deal with these?处理这些问题最方便的方法是什么?
Is "*15.0.0"
good enough? "*15.0.0"
够好吗?
What about:关于什么:
"peerDependencies": {
"react": "^15.0.0 || ^16.0.0",
"react-dom": "^15.0.0 || ^16.0.0"
}
To address a range you can use following notation :要解决范围,您可以使用以下符号:
"peerDependencies": {
"react-dom": "15 - 16"
}
Makes it really easy to define a range as well.也可以很容易地定义一个范围。
You can test them out here : https://semver.npmjs.com/你可以在这里测试它们: https : //semver.npmjs.com/
Just checked some other packages on GitHub how they do it.刚刚检查了 GitHub 上的其他一些软件包是如何做到的。
Using *
didn't work out for me and therefore seems like bad practice anyway.使用
*
对我不起作用,因此无论如何似乎都是不好的做法。
Better solution:更好的解决方案:
"peerDependencies": {
"react": ">=0.14.0 <= 16",
"react-dom": ">=0.14.0 <= 16"
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.