在angular 6库项目中使用依赖的npm软件包的正确方法是什么? [英] What is the proper way to use a dependent npm package in angular 6 library project?

查看:470
本文介绍了在angular 6库项目中使用依赖的npm软件包的正确方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于我应该如何引用我的库angular6项目中的外部npm软件包,我有些困惑。我们有一个内部的scss库,可以用来在库中设置可重用组件的样式。我该如何导入呢?

I'm a little confused as to how im supposed to reference external npm packages in my library angular6 project. We have an internal scss library I'd like to use to style my reusable components in my library. How do i go about importing that?

package.json for lib project:

package.json for lib project:

{
  "name": "ikr-lib",
  "version": "0.0.1",
  "peerDependencies": {
    "@angular/common": "^6.0.0-rc.0 || ^6.0.0",
    "@angular/core": "^6.0.0-rc.0 || ^6.0.0",
    "document-register-element": "1.8.1"
  },
  "dependencies": {
    "element.ui": "^1.0.1"
  }
}

在构建库项目时,我得到以下信息:

When I build the library project I get this:

Distributing npm packages with 'dependencies' is not recommended. Please consider adding element.ui to 'peerDependencies' or remove it from 'dependencies'.

BUILD ERROR
Dependency element.ui must be explicitly whitelisted.


推荐答案

似乎将软件包名称添加到 whitelistedNonPeerDependencies中ng-package.json文件中的集合将解决此构建问题。不过,我仍然不确定最佳做法是什么。我们是否应该创建依赖于其他npm软件包的角度库,还是最好仅具有peerDependancies?

It looks like adding the package name to a "whitelistedNonPeerDependencies" collection in the ng-package.json file will resolve this build issue. I'm still not sure what the best practice is here though. Should we create angular libraries that have dependancies on other npm packages or is it best to only have peerDependancies?

ng-package.json文件:

ng-package.json file:

{
  "$schema": "../../node_modules/ng-packagr/ng-package.schema.json",
  "dest": "../../dist/ikr-lib",
  "deleteDestPath": false,
  "lib": {
    "entryFile": "src/public_api.ts"
  },
  "whitelistedNonPeerDependencies": [
    "element.ui"
  ]
}

这篇关于在angular 6库项目中使用依赖的npm软件包的正确方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆