简体   繁体   English

角度库节点模块

[英]angular library node modules

So ive created the following library:所以我创建了以下库:

在此处输入图像描述

Now as you can see there are some red underlines.现在你可以看到有一些红色下划线。

Within this package i wish to use other npm packages (such as ionic , crypto ect)在此包中,我希望使用其他 npm 包(例如ioniccrypto等)

I tried to modify the package.json inside the library:我尝试修改库中的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"
  }
}

However i am not quite sure how to use these?但是我不太确定如何使用这些? what can i do if my code relies on these modules?如果我的代码依赖于这些模块,我该怎么办?

With peerDependencies you are required to download those packages yourself (the user consuming your library needs to download those packages, it doesn't come bundled with your library).使用peerDependencies ,您需要自己下载这些包(使用您的库的用户需要下载这些包,它不会与您的库捆绑在一起)。

So you will need to install those libraries manually in-order for you to use them.因此,您需要手动安装这些库才能使用它们。

If a user installs your library without those dependencies already installed, they will get a warning in their console.如果用户在没有安装这些依赖项的情况下安装你的库,他们将在他们的控制台中收到警告。

By adding a package in peerDependencies you are saying: My code is compatible with this version of the package.通过在 peerDependencies 中添加一个包,您是在说:我的代码与该版本的包兼容。

If this package already exists in node_modules, do nothing.如果这个包已经存在于 node_modules 中,什么也不做。

If this package doesn't already exist in the node_modules directory or it is the wrong version, don't add it.如果这个包在 node_modules 目录中不存在或者它是错误的版本,不要添加它。 But, show a warning to the user that it wasn't found.但是,向用户显示未找到它的警告。

Extract from https://indepth.dev/posts/1187/npm-peer-dependencies摘自https://indepth.dev/posts/1187/npm-peer-dependencies

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM