Tip
Watch for Changes and Automatically Rebuild Projects in an NPM Workspace Monorepo
Automatically rebuild dependencies when they change within an Nx monorepo
By now we're accustomed to have a HMR experience when developing. When we change a file, the underlying dev server watches for the changes and automatically re-compiles. In a monorepo this is more tricky. Consider you have your dev server running on APP with a dependency tree that looks like APP -> LIB-A -> LIB-B -> LIB-C. You'd have to watch all of these dependencies of APP s.t. if you change any of them it'd automatically recompile it. And it should work even as you change that dependency tree while developing.
Nx has such command built-in:
nx watch --projects=app1 --includeDependentProjects -- echo \$NX_PROJECT_NAME
Let's have a look how this works in an NPM workspace monorepo.