Replies: 2 comments 1 reply
-
As long as the shared libs aren't buildable (e.g. have a
I wouldn't group unrelated concerns into the same library just for performance. |
Beta Was this translation helpful? Give feedback.
-
Maybe check on #9183 there also some people sharing their best practices |
Beta Was this translation helpful? Give feedback.
-
Hello,
I work in a NX monorepo and we have a growing problem with how to organize our shared code.
We're wondering how other teams deal with shared code, particularly a lot of small pieces of independent code which are each used in a few different projects each.
If additional context might be helpful, in our particular case we have a general structure of (each leaf is a project):
The shared project for each app is where all of the code shared between two or more pages for that app ends up, which results in these shared projects being rather large, and causes projects to be unnecessarily affected.
A majority (~60%) of the code in these shared projects is fully independent (meaning a file being reference in one project doesn't correlate to another file also being referenced; e.g. a tab UI component, an Angular pipe for checking if an array includes a value, etc...).
Lacking a meaningful way of grouping these, the best option seems to be to make a project for each one.
However, in our experience there is a base overhead to running a task, so tripling the number of projects is a concern in terms of performance, to say nothing of the additional configuration (though Project Crystal may help there) and mental overhead of having so many projects.
We could reduce the total number projects by adding arbitrary groupings, perhaps of vaguely related code we don't expect to change very often (e.g. the generic Angular pipes, the generic Angular form validators), but that seems to lead down the same path because most of these independent pieces are used in maybe 7% of the pages for an app (and not the same 7%).
The other option which comes to mind is making projects with groupings based on the pages the code is used in (e.g. the pageA-and-pageC shared code, the pageG-and-pageO shared code, etc...). This though feels like a manual solution to something which would be better as an automated solution (e.g. linting and testing just the individual files which were affected).
All that said, we are curious what approaches other teams have to used to deal with similar problems.
Thanks,
Joshua
Beta Was this translation helpful? Give feedback.
All reactions