Workspace Management
Yarn Workspaces
The monorepo uses Yarn Workspaces for dependency management. All workspaces are defined in the rootpackage.json:
- Shared dependencies - Common dependencies are hoisted to the root
node_modules - Symlinked packages - Internal packages are symlinked for local development
- Single lock file - All dependencies managed in one
yarn.lock
Installing Dependencies
Runyarn from the root to install all dependencies for all packages:
- Installs all dependencies listed in every
package.json - Hoists shared dependencies to the root
- Symlinks internal packages together
Directory Structure
Build Orchestration with Nx
The monorepo uses Nx for build orchestration, caching, and affected analysis.Why Nx?
- Task orchestration - Runs tasks across packages in the correct order
- Intelligent caching - Caches build outputs to speed up rebuilds
- Affected detection - Runs tasks only for packages affected by changes
- Parallel execution - Runs independent tasks in parallel
Nx Configuration
Nx is configured innx.json:
dependsOn- Defines task dependencies^prefix - Means “this target’s dependencies from upstream packages”outputs- Tells Nx what files to cachecache: true- Enables caching for the targetparallel: 5- Runs up to 5 tasks in parallel
Running Tasks with Nx
Nx provides several ways to run tasks:Package Structure
Each package follows a consistent structure:Package Entry Points
Packages use exports to define entry points:- Supports both CommonJS and ES modules
- Provides TypeScript types
- Offers downleveled types for older TypeScript versions
Dependency Management
Internal Dependencies
Packages depend on each other via workspace protocol:workspace:* is replaced with the actual version.
Shared Dependencies
Common development dependencies are defined in the rootpackage.json:
Dependency Resolutions
Forced dependency versions are specified inresolutions:
Build Outputs
After building, each package contains:CommonJS (CJS)
ES Modules (ESM)
TypeScript Types
CDN Bundles (Browser Only)
Nx Cache
Nx caches build outputs in.nxcache/:
Version Management with Volta
Volta ensures everyone uses the same tool versions:Scripts Organization
Root scripts coordinate across all packages:run-s- Run scripts sequentiallyrun-p- Run scripts in parallelnx run-many- Run tasks across packages
Next Steps
- Learn about individual packages
- Understand the build system
- Explore the development workflow