Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
131 views
in Technique[技术] by (71.8m points)

javascript - 角库节点模块(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 ect)) 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?(如果我的代码依赖于这些模块怎么办?)   ask by Marc Rasmussen translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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://medium.com/angular-in-depth/npm-peer-dependencies-f843f3ac4e7f(摘自https://medium.com/angular-in-depth/npm-peer-dependencies-f843f3ac4e7f)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...