Create a Task Pipeline

You may have noticed in the packages/zoo/package.json file, there is a serve script that expects the build task to already have created the dist folder. Let’s set up a task pipeline that will guarantee that the project’s build task has been run.

nx.json
{
"$schema": "./node_modules/nx/schemas/nx-schema.json",
"targetDefaults": {
"serve": {
"dependsOn": ["build"]
},
8 collapsed lines
"build": {
"dependsOn": ["^build"],
"outputs": ["{projectRoot}/dist"],
"cache": true
},
"typecheck": {
"cache": true
}
},
"defaultBase": "main"
}

The serve target’s dependsOn line makes Nx run the build task for the current project before running the current project’s build task.

Now nx serve will run the build task before running the serve task.

Terminal window
nx serve zoo
Powered by WebContainers
Files
Preparing Environment
  • Stubbing git
  • Installing dependencies