所以我创建了以下库:
现在您可以看到有一些红色下划线。
在此包中,我希望使用其他 npm 包(例如 ionic
、crypto
等)
我尝试修改库内的package.json
:
{
"name": "sdk-mobil-login-light",
"version": "0.0.1",
"peerDependencies": {
"@angular/common": "^8.2.14",
"@angular/core": "^8.2.14",
"crypto-js": "^3.1.9-1",
"sha256": "0.2.0",
"@ionic-native/unique-device-id": "^5.15.1",
"@ionic/angular": "^4.1.0",
"@ionic/storage": "^2.2.0"
}
}
但是我不太确定如何使用这些?如果我的代码依赖这些模块我该怎么办?
最佳答案
使用peerDependency
,您需要自己下载这些软件包(使用您的库的用户需要下载这些软件包,它不与您的库捆绑在一起)。
因此,您需要手动安装这些库才能使用它们。
如果用户在没有安装这些依赖项的情况下安装您的库,他们将在控制台中收到警告。
By adding a package in peerDependencies you are saying: My code is compatible with this version of the package.
If this package already exists in node_modules, do nothing.
If this package doesn’t already exist in the node_modules directory or it is the wrong version, don’t add it. But, show a warning to the user that it wasn’t found.
关于javascript - Angular 库 Node 模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59104129/