如何使用辅助端点为Angular库创建API [英] How to use secondary endpoints to create API for Angular library
问题描述
场景:
我使用 ng-packagr
创建了一个自定义UI库,导出了自定义组件
和一些模型类.
I created a custom UI library using ng-packagr
, exported custom components
and some model classes.
问题:
在主项目中, import
语句对导出的组件工作正常,但对导出的类不起作用,并且 webpack
无法编译并给出错误:
In main project, import
statement works fine for exported components but it doesn't work for exported classes and webpack
fails to compile giving error:
找不到模块错误无法解决
my-custom-library/models
图书馆项目代码:
模型类: src/app/modules/my-custom-module/models/my-model.ts
export class MyModel {
constructor() {
// default values for props here
}
// ...props here
}
索引文件: src/app/modules/my-custom-module/models/index.ts
export * from './my-model';
export * from './my-other-model';
从根目录导出文件: models.ts
export * from './src/app/modules/my-custom-module/models/index';
根目录下的
ng-packagr
文件: public_api.ts
export * from './models';
export * from './src/app/modules/my-custom-module/my-custom-module.module';
export * from './src/app/modules/my-custom-module/components/index';
主要项目代码:
import {MyCustomModule} from 'my-custom-library'; // works
import {MyModel} from 'my-custom-library'; // works
import {MyModel} from 'my-custom-library/models'; // does not works
目的:为最终开发人员简化和划分UI库API.
Purpose: Simplifying and dividing the UI library API for end developers.
我相信,我缺少有关映射 webpack
模块分辨率的信息,因为VS Code可以识别 import
,智能感知甚至是 Ctrl +单击
导航到正确的文件,但 webpack
编译失败.
I believe, I'm missing something about mapping webpack
module resolution because VS Code recognizes the import
, intellisense works and even Ctrl + Click
navigates to right file but webpack
fails in compilation.
推荐答案
I was able to achieve my required API pattern using Seconday End Points
.
信用:在 Alan Agius 上://github.com/dherges/ng-packagr/issues/992"rel =" nofollow noreferrer> Git问题
这篇关于如何使用辅助端点为Angular库创建API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!