[英]How to use Angular library from npm package?
我通過命令創建了一個 lib 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
中公開的所有組件和模塊
那么當你安裝了你的庫時,你應該能夠像這樣導入你的模塊/組件: import { CesiumPanoramaLibModule } from "cesium-panorama-lib";
如果你不能像這樣導入它,那么你的圖書館有問題
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.