From 57a201a56202b7cf97ca7d55a5e0a0a3f138b8cc Mon Sep 17 00:00:00 2001 From: Juri Date: Mon, 16 Sep 2024 11:22:15 +0200 Subject: [PATCH] docs(core): update watch command with new example and embed YT video --- .../recipes/running-tasks/workspace-watching.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/docs/shared/recipes/running-tasks/workspace-watching.md b/docs/shared/recipes/running-tasks/workspace-watching.md index e867290906..11fd92626c 100644 --- a/docs/shared/recipes/running-tasks/workspace-watching.md +++ b/docs/shared/recipes/running-tasks/workspace-watching.md @@ -1,5 +1,7 @@ # Workspace Watching +{% youtube src="https://youtu.be/0eVplUl1zBE?si=KtmiyRm1AcYc01td" title="Workspace watching" /%} + Nx can watch your workspace and execute commands based on project or files changes. Imagine the following project graph with these projects: @@ -156,3 +158,15 @@ To watch for a project and it's dependencies, run this command: ```shell nx watch --projects=app1 --includeDependentProjects -- echo \$NX_PROJECT_NAME ``` + +### Rebuilding dependent projects while developing an application + +In a monorepo setup, your application might rely on several libraries that need to be built before they can be used in the application. While the [task pipeline](/recipes/running-tasks/defining-task-pipeline) automatically handles this during builds, you'd want the same behavior during development when serving your application with a dev server. + +To watch and rebuild the dependent libraries of an application, use the following command: + +```shell +nx watch --projects=my-app --includeDependentProjects -- nx run-many -t build -p \$NX_PROJECT_NAME --exclude=my-app +``` + +`--includeDependentProjects` ensures that any changes to projects your application depends on trigger a rebuild, while `--exclude=my-app` skips rebuilding the app itself since it's already being served by the development server.