我有一个包含3个项目的角工作区:
WR-核心是共享服务,组件和数据模型。
在WR-核心,我已经创建以下文件夹:
/lib/data
在这方面,我有一些数据模型。
我在一个单独的文件名为wr.models.ts
这些捆绑在一起,然后通过public_api.ts
出口这包。
wr.models.ts
export * from './entity.model';
export * from './party.model';
export * from './person.model';
export * from './organisation.model';
export * from './party-role.model';
export * from './role-type.model';
public_api.ts
export * from './lib/wr-core.service';
export * from './lib/wr-core.component';
export * from './lib/wr-core.module';
export * from './lib/data/wr.models';
我内置使用这个库:
ng build wr-core
我导入库中拖入app.module.ts:
import { WrCoreModule } from 'wr-core';
...
imports: [ WrCoreModule ],
...
然后我得到这个错误:
ERROR in : Error: Module not found: WrCoreModule
我也尝试没有成功如下:
import { WrCoreModule } from 'wr-core/wr-core';
import { WrCoreModule } from 'wr-core/public_api';
WR核列在tsconfig.json:
"paths": {
"wr-core": [
"dist/wr-core"
],
"wr-core/*": [
"dist/wr-core/*"
]
}
我的问题是,我该如何使用存储共享数据模型库?
我想用这个方法,因为相同的数据模型将在wr-admin
使用。不仅如此,但我会加入我的API服务等方式来wr-core
,使他们也能应用程序之间共享。
是你的车型平原打字稿类?在这种情况下,为什么你打造毕竟是一个模块?
在我的项目,我通常只需导入打字稿文件,并添加相应的部分,你tsconfig.json
的include
财产份额多张客户端应用程序或客户机/服务器之间的代码。
比方说,你的文件夹结构如下所示:
- project1
- tsconfig.json
- project2
- tsconfig.json
- your-library
- file1.ts
- file2.ts
- ...
然后,你可以导入你的角度应用.ts
文件,并把它们包含在每个项目的tsconfig.json
编译过程:
{
"compilerOptions": {...}
"include": [
"./",
"../your-library/**/*",
]
}