如何使用 npm 包中的 Angular 库?

How to use Angular library from npm package?

我已经通过命令创建了一个库Angular:

ng generate library wrapper-cesium-panorama

然后我构建它:

ng build cesium-panorama-lib

我移动到 /dict/cesium-panorama-lib 文件夹并制作后:

npm publish

它创建了一个 npm 包。

然后我在现有的 Angular 应用程序中安装了这个包:

npm i cesium-panorama-lib

它在 /node_modules 文件夹中创建了程序包:

我尝试在 Angular 应用中使用这个库:

import { CesiumPanoramaLibModule } from "cesium-panorama-libi";

找不到路径。然后我试了:

import { CesiumPanoramaLibModule } from "cesium-panorama-lib/src/public-api";
imports: [CesiumPanoramaLibModule]

它有效,但在构建应用程序后我收到此消息:

ERROR in ./node_modules/cesium-panorama-lib/src/public-api.ts
Module build failed (from ./node_modules/@ngtools/webpack/src/index.js):
Error: C:\Users\poDesktop\AngularPrototype\node_modules\cesium-panorama-lib\src\public-api.ts is missing from the TypeScript compilation. Please make sure it is in your tsconfig via the 'files' or 'include' property.
The missing file seems to be part of a third party library. TS files in published libraries are often a sign of a badly packaged library. Please open an issue in the library repository to alert its author and ask them to package the library using the Angular Package Format
    at AngularCompilerPlugin.getCompiledFile (C:\Users\ponom\Desktop\AngularPrototype\node_modules\@ngtools\webpack\src\angular_compiler_plugin.js:913:23)

我做错了什么以及如何使用它?我的意思是其他软件包在根目录

中有 index.js

您应该导出您想要在 public-api.ts

中公开的所有组件和模块

然后当你安装了你的库后,你应该可以像这样导入你的modules/component:import { CesiumPanoramaLibModule } from "cesium-panorama-lib";

如果你不能像这样导入它,那么你的库有问题