Hi Has anyone built a m…

1 minute read

Hi! Has anyone built a monorepo with multiple namespaces? Is it possible to that with nx?

Responses:

Can you give me an example of what you mean by namespaces?

let’s say i have multiple libraries (some of them, publishable) and i want to group them further and have different namespaces, e.g.

@shared-ui/lib-a @shared-ui/lib-b @shared-logic/lib-c @shared-logic/lib-d

we are planning to move our project to nx from lerna and this is one thing that we wanted to see if we can address since our current libs already live in different namespaces and are already published and used as packages in different apps

I am not an expert on this but this should be possible.

When you create a new library you can specify a prefix. This is the prefix that you would use by default on your angular components when they are created. (not really namespace)

Scoped Libraries: You can also update the tsconfig paths section to contain separate scope for (but not sure if this is a best practice)

{ "paths": { "@shared-ui/lib-a": ["libs/shared-ui/lib-a/src/index.ts"], "@shared-logic/lib-c": ["libs/shared-logic/lib-c/src/index.ts"] } Publishable Libraries: Publishable libraries contain their own package.json where you could also specify a different scope within the library package.json

Other consideration: updating your tslinting rules be aware of deep imports

Thanks, I’ll give that a try!

Hey is correct, you will have to change it in a few locations though. The main one being tsconfig.json, but you will also have to change the project name in angular.json and i believe nx.json.

I think the issue come when you publish the packages i do not believe the nx.json supports it

Updated: