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.