How to build individual projects in a monorepo without affecting other projects (Angular, NX)

64 Views Asked by At

I am working on an internal Angular project where I need to expose multiple services within a single dashboard.

The solution involves having one project act as the outer layout, and multiple projects that will be displayed within it.

The number of internal projects is likely to increase in the future, and they will likely be managed separately by service.

My question is:

Is there a way to build each of these internal projects without affecting other services? I want the build to only modify the files of the service being built, and only update those changed files in the repository.

I understand that the monorepo project management approach can help with this, and I have tried to introduce the NX tool. However, it seems that NX builds all related projects, not just the individual project. (For example, if the outer layout project references an internal project, changing the internal project will also change the build files of the outer project.)

Any help would be greatly appreciated.

Additional details:

Angular version: 16.2.12 NX version: 18.0.4 Operating system: Mac OS 14.0

I tried two approaches:

  1. Creating a library in a sub-project:
  • I created a library project using nx g @nx/angular:library my-lib.
  • I built the library using nx build my-lib.
  • I referenced the library in the external layout project using import { MyComponent } from 'my-lib';.
  1. Creating an app in a sub-project:
  • I created an app project using nx g @nx/angular:application my-app.
  • I built the app using nx build my-app.
  • I referenced the app in the external layout project using .

In both cases:

  • I expected the external layout project to only include the changed files from the sub-project.
  • I expected the external layout project to not be affected by changes to the sub-project.

However:

  • The build artifacts of the external layout project included all the files from the sub-project.
  • Changing the sub-project caused the external layout project to be rebuilt.

This is not ideal because:

  • It makes it difficult to manage and maintain the projects independently.
  • It can lead to unnecessary rebuilds and performance issues.

I am looking for a way to build each project independently without affecting other projects.

0

There are 0 best solutions below