.agents/skills/pnpm/references/best-practices-performance.md
pnpm is fast by default, but these optimizations can make it even faster.
Skip resolution when lockfile exists:
pnpm install --frozen-lockfile
This is faster because pnpm skips the resolution phase entirely.
Use cached packages when available:
pnpm install --prefer-offline
Or configure globally:
# .npmrc
prefer-offline=true
If you don't need optional deps:
pnpm install --no-optional
For CI or when scripts aren't needed:
pnpm install --ignore-scripts
Caution: Some packages require postinstall scripts to work correctly.
Only run build scripts for specific packages:
# .npmrc
onlyBuiltDependencies[]=esbuild
onlyBuiltDependencies[]=sharp
onlyBuiltDependencies[]=@swc/core
Or skip builds entirely for deps that don't need them:
{
"pnpm": {
"neverBuiltDependencies": ["fsevents", "cpu-features"]
}
}
Cache native module build results:
# .npmrc
side-effects-cache=true
This caches the results of postinstall scripts, speeding up subsequent installs.
Use a single store for all projects (default behavior):
# .npmrc
store-dir=~/.pnpm-store
Benefits:
Periodically clean unused packages:
# Remove unreferenced packages
pnpm store prune
# Check store integrity
pnpm store status
Run workspace scripts in parallel:
pnpm -r --parallel run build
Control concurrency:
# .npmrc
workspace-concurrency=8
See output in real-time:
pnpm -r --stream run build
Only build what changed:
# Build packages changed since main branch
pnpm --filter "...[origin/main]" run build
Build dependencies before dependents:
pnpm -r run build
# Automatically runs in topological order
For explicit sequential builds:
pnpm -r --workspace-concurrency=1 run build
Use closest/fastest registry:
# .npmrc
registry=https://registry.npmmirror.com/
Tune network settings:
# .npmrc
fetch-retries=3
fetch-retry-mintimeout=10000
fetch-retry-maxtimeout=60000
network-concurrency=16
# .npmrc
proxy=http://proxy.company.com:8080
https-proxy=http://proxy.company.com:8080
Use shared lockfile for all packages (default):
# .npmrc
shared-workspace-lockfile=true
Benefits:
Only update lockfile without installing:
pnpm install --lockfile-only
# Clean install
rm -rf node_modules pnpm-lock.yaml
time pnpm install
# Cached install (with lockfile)
rm -rf node_modules
time pnpm install --frozen-lockfile
# With store cache
time pnpm install --frozen-lockfile --prefer-offline
Debug slow installs:
# Verbose logging
pnpm install --reporter=append-only
# Debug mode
DEBUG=pnpm:* pnpm install
Optimized .npmrc for performance:
# Install behavior
prefer-offline=true
auto-install-peers=true
# Build optimization
side-effects-cache=true
# Only build what's necessary
onlyBuiltDependencies[]=esbuild
onlyBuiltDependencies[]=@swc/core
# Network
fetch-retries=3
network-concurrency=16
# Workspace
workspace-concurrency=4
| Scenario | Command/Setting |
|---|---|
| CI installs | pnpm install --frozen-lockfile |
| Offline development | --prefer-offline |
| Skip native builds | neverBuiltDependencies |
| Parallel workspace | pnpm -r --parallel run build |
| Build changed only | pnpm --filter "...[origin/main]" build |
| Clean store | pnpm store prune |