# Install dependency in specific package
pnpm add react --filter @repo/ui
pnpm add -D typescript --filter @repo/ui
# Install workspace dependency
pnpm add @repo/ui --filter web
# Install in all packages
pnpm add -D eslint -w
# Update all dependencies
pnpm update -r
# Remove dependency
pnpm remove react --filter @repo/ui
Scripts
# Run script in specific package
pnpm --filter web dev
pnpm --filter @repo/ui build
# Run in all packages
pnpm -r build
pnpm -r test# Run in parallel
pnpm -r --parallel dev
# Filter by pattern
pnpm --filter "@repo/*" build
pnpm --filter "...web" build # Build web and dependencies
# Run task for specific project
nx build my-app
nx test ui-components
nx lint utils
# Run for affected projects
nx affected:build
nx affected:test --base=main
# Visualize dependencies
nx graph
# Run in parallel
nx run-many --target=build --all --parallel=3
// packages/types/src/user.tsexportinterfaceUser {
id: string;
email: string;
name: string;
role: "admin" | "user";
}
exportinterfaceCreateUserInput {
email: string;
name: string;
password: string;
}
// Used in both frontend and backendimporttype { User, CreateUserInput } from"@repo/types";
Build Optimization
Turborepo Caching
// turbo.json{"pipeline":{"build":{// Build depends on dependencies being built first"dependsOn":["^build"],// Cache these outputs"outputs":["dist/**",".next/**"],// Cache based on these inputs (default: all files)"inputs":["src/**/*.tsx","src/**/*.ts","package.json"]},"test":{// Run tests in parallel, don't depend on build"cache":true,"outputs":["coverage/**"]}}}
# .github/workflows/ci.ymlname:CIon:push:branches: [main]
pull_request:branches: [main]
jobs:build:runs-on:ubuntu-lateststeps:-uses:actions/checkout@v3with:fetch-depth:0# For Nx affected commands-uses:pnpm/action-setup@v2with:version:8-uses:actions/setup-node@v3with:node-version:18cache:"pnpm"-name:Installdependenciesrun:pnpminstall--frozen-lockfile-name:Buildrun:pnpmturborunbuild-name:Testrun:pnpmturboruntest-name:Lintrun:pnpmturborunlint-name:Typecheckrun:pnpmturboruntype-check
Deploy Affected Only
# Deploy only changed apps-name:Deployaffectedappsrun:|
if pnpm nx affected:apps --base=origin/main --head=HEAD | grep -q "web"; then
echo "Deploying web app"
pnpm --filter web deploy
fi