pnpm's .npmrc configuration file provides rich options to customize package management behavior.
Basic Configuration:
ini# .npmrc # Registry configuration registry=https://registry.npmjs.org/ # Taobao mirror (China acceleration) registry=https://registry.npmmirror.com/ # Scoped package registry @mycompany:registry=https://npm.mycompany.com/
Storage Configuration:
ini# Global store location store-dir=/path/to/custom/store # Cache directory cache-dir=/path/to/custom/cache # State directory state-dir=/path/to/custom/state
Installation Behavior Configuration:
ini# Strict mode strict-peer-dependencies=true # Auto install peer dependencies auto-install-peers=true # Flat mode (npm compatible) shamefully-hoist=true # Install production dependencies only production=true # Ignore engines check engine-strict=false
Network Configuration:
ini# Concurrent download count network-concurrency=16 # Request timeout (milliseconds) fetch-timeout=60000 # Retry count fetch-retries=3 # Proxy settings proxy=http://proxy.company.com:8080 https-proxy=http://proxy.company.com:8080 # Domains without proxy no-proxy=localhost,127.0.0.1
Workspace Configuration:
ini# Link workspace packages when installing recursively link-workspace-packages=true # Prefer workspace versions prefer-workspace-packages=true # Save workspace protocol save-workspace-protocol=true
Security and Audit:
ini# Ignore audit warnings ignore-workspace-root-check=true # Allow postinstall scripts execution ignore-scripts=false # Read-only mode (don't modify lock file) frozen-lockfile=true
Output Configuration:
ini# Log level loglevel=info # Don't show progress bar reporter=silent # Use color output color=always
Common Configuration Combinations:
ini# Development environment configuration strict-peer-dependencies=false auto-install-peers=true shamefully-hoist=false # CI/CD configuration frozen-lockfile=true prefer-offline=true reporter=silent # Monorepo configuration link-workspace-packages=true prefer-workspace-packages=true
Environment Variable Configuration:
bash# Set via environment variables export npm_config_registry=https://registry.npmmirror.com/ export npm_config_store_dir=/custom/store
View Current Configuration:
bash# View all configurations pnpm config list # View specific configuration pnpm config get registry # Set configuration pnpm config set registry https://registry.npmmirror.com/ # Delete configuration pnpm config delete registry
Configuration Priority:
- Command line parameters
- Environment variables
- Project
.npmrc - User
~/.npmrc - Global
/etc/npmrc - Default values
Practical Application Example:
ini# Enterprise environment configuration registry=https://npm.company.com/ @company:registry=https://npm.company.com/ # Use internal proxy proxy=http://proxy.company.com:8080 https-proxy=http://proxy.company.com:8080 # Strict mode strict-peer-dependencies=true engine-strict=true # Performance optimization network-concurrency=32 fetch-retries=5