I m hoping someone knows…

2 minute read

I’m hoping someone knows how to do this off the top of their head. We have some shared node libraries that are developed outside the nx repo (the libraries predate the nx monorepo, or they would just be in the repo).

What I would like to do is, when I run nx serve <app-name> I’d like the server to restart when a certain path in the node_modules directory changes, for when I have my libs npm linked into my mono repo

Responses:

I am not sure that is possible to be honest, unless there is a way to configure ng serve with different paths to watch. I know there are plugins for webpack that can watch (webpack-dev-server I think?) but you would have to override the webpack config (or extend it). I believe there are plugins for extending angular webpack config so I would start there and then see if you can add those node_modules paths as paths to watch.

watching files in node_modules seems like an anti pattern, does this module change constantly?

a git submodule might be use best bet, if you have access to both external lib and mono repo

Alex it is a locally linked package that they are developing in another repo. So yes it very well could change often.

fair, like you said above. I’m not sure if this is possible. Ive never seen a setup like this before

ok, thanks for the replies. I looked at the schema for the serve command and didn’t see anything obvious.

Yeah, during development of these libs they will be changing. We basically will link or libraries locally and check them against our app as we build, fairly typical in this scenario I think.

I think the easiest approach might be to move the libs into the monorepo, except then I have to deal with publishing those libs out of the monorepo, which I’ve heard is a bit of a pain.

I’ll just deal with restarting for the time being, and probably figure it out later

nx 9 has better support for publishable libraries. I would start there. but ya if you are going to go the monorepo route, might as well embrace it fully.

submodule might help with keeping your external repos and use them inside the nx repo. maybe just to help you migrate over?

that’s a possibility, the submodule thing. I’ve dealt with that pain in the past though and it’s not my favorite. I love it when people push refs to the submodule that aren’t in git yet, so much fun :slightly_smiling_face:

haha yeah they can be a pita

but if you use it to migrate over might not be an issue

yeah, thanks for the idea. it could be an ok half measure

good luck :smile:

have you ever developed an angular library outside of nx and used in another project with npm link?

What you are describing is OOtB behavior with ng serve and npm link in my experience.

The one part you might be missing is when you build your library add --watch

Here is the little documentation I wrote for our team a while back

## Modifying the package and using in another project without releasing it

If you want to update the package and test it out in your project without creating a new build you will use the npm link functionality https://docs.npmjs.com/cli/link. To use this functionality run the following steps:

1. build the library package ng build your-library --watch adding watch so that changes to the package are automatically rebuilt 2. cd to dist/your-library then type npm link 3. open a command/bash prompt in the project folder you want to test the package in and type npm link your-library 4. start your application

Updated: