javascript - Angular 库 Node 模块

标签 javascript node.js angular npm

所以我创建了以下库:

enter image description here

现在您可以看到有一些红色下划线。

在此包中,我希望使用其他 npm 包(例如 ioniccrypto 等)

我尝试修改库内的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.

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

关于javascript - Angular 库 Node 模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59104129/

相关文章:

javascript - jQuery 动画的大图像移动波涛汹涌

node.js - 是否可以使用 Nodejs 开发桌面应用程序?

javascript - Angular 从 ng-repeat 中的 $scope 获取动态变量

javascript - 为什么这个模板不能正常工作?

javascript - html内容在iframe中呈现,但不在div中呈现

javascript - 在 Angular 2 中使用 Typescript 将对象适合应用于元素

javascript - 从 CSS 属性设置 Canvas strokeStyle 颜色?

Angular 2/4。内置FormsModule时,我应该使用Reactive Forms做什么?

javascript - jquery - 动态地将div添加到子级

javascript - 允许用户在js创建的文本区域内进行选择