如何在monorepo中共享loopback(nodejs)和Angular Apps之间的打字稿库
我有一个MonorePo(使用NX作为Manager),其中包含五个Angular Apps和一个Loopback 4(nodejs,ts)应用程序。我也有几个Angular库,可以按预期共享,并使用@Angular-Architects/ddd
来架构它们之间的库和依赖关系/约束的类型。
文件夹结构:
apps
angular1
angular2 (and 3,4,5)
loopback
libs
angular-shared
ts-shared
我现在想创建一个共享库ts -shared
的简单键入函数(没有任何依赖性的角度,环回) - 例如财务计算为PV,FV,INT等,我希望通过Angular和Roopback代码共享。
例如:
在ts共享的lib中:
export const square = (n:number):number => n*n;
然后以角度消耗:
import { square } from '/path/to/lib' ;
const res = square(5);
这一切都很好。
但是,当我在回环代码中执行相同的操作时,我面临IDE/构建问题(缩短了可读性),类似于
error TS6059: File '/xxx/libs/util-core/src/lib/services/algorithm.service.ts' is not under 'rootDir' '/xxx/apps/loopback-api/src'. 'rootDir' is expected to contain all source files.
我的loopback tsconfig.json:
{
"$schema": "http://json.schemastore.org/tsconfig",
"extends": "@loopback/build/config/tsconfig.common.json",
"compilerOptions": {
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"outDir": "dist",
"rootDir": "src"
},
"include": [
"src",
],
"references": [],
"files" : []
}
我认为它是因为(如它所述)库不在源代码目录下我意识到和理解的Loopback应用程序是通过这种方式设计的。
我尝试了各种包含,文件和参考的组合,但没有运气。我已经搜索了很多东西,但没有发现任何有用或相关的东西。
有人有任何建议吗?还是我可以看一下类似的东西的工作回购?
在这一点上,我对NX感到满意,除非我别无选择,否则希望不需要工作空间,Lerna或其他新技术。
I have a monorepo (using nx as manager), which contains five Angular apps, and one Loopback 4 (NodeJS, TS) app. I also have several Angular libraries which are shared as expected, and using @angular-architects/ddd
to architect the types of libraries and dependencies/constraints between them.
Folder structure:
apps
angular1
angular2 (and 3,4,5)
loopback
libs
angular-shared
ts-shared
I would now like to create a shared library ts-shared
of simple typescript functions (without any dependencies to Angular, Loopback) - for instance financial calculations as PV, FV, INT, etc., that I would like to be shared by both Angular as well as Loopback code.
For example:
in ts-shared lib:
export const square = (n:number):number => n*n;
and then consumed in Angular:
import { square } from '/path/to/lib' ;
const res = square(5);
This all works fine.
However when I do the same in my Loopback code, I am faced with IDE/build issues (shortened for readability) similar to
error TS6059: File '/xxx/libs/util-core/src/lib/services/algorithm.service.ts' is not under 'rootDir' '/xxx/apps/loopback-api/src'. 'rootDir' is expected to contain all source files.
My Loopback tsconfig.json:
{
"$schema": "http://json.schemastore.org/tsconfig",
"extends": "@loopback/build/config/tsconfig.common.json",
"compilerOptions": {
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"outDir": "dist",
"rootDir": "src"
},
"include": [
"src",
],
"references": [],
"files" : []
}
I presume its because (as it states) the library is not under the source code directory of the Loopback app - which I realise and understand - it's by design this way.
I have tried various combinations of include, files and references, but no luck. I have googled quite a bit but have not found anything useful or relevant.
Does anyone have any suggestions please? Or perhaps a working repo of something similar that I can have a look at?
At this point I am happy with nx, and am hoping not to need workspaces, lerna, or other new technologies unless I have no alternative.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论