Building React Icons from Source
This guide covers how to build React Icons from source, useful for development, testing, or contributing to the project.Prerequisites
Install Node.js
Project Structure
React Icons is a monorepo with multiple packages:Quick Build
For a complete build of all packages:This script builds the main package and all related packages. It may take several minutes on first run.
Building the Main Package
Fetch icon sources
Download SVG files from upstream icon repositories:
This downloads icons from 30+ repositories defined in
src/icons/index.ts. First run may take 5-10 minutes.Build Scripts Explained
The main package has several build scripts defined inpackage.json:
Fetch Icons
scripts/fetcher.ts):
- Reads icon pack definitions from
src/icons/index.ts - Clones/updates Git repositories for each icon pack
- Copies SVG files to the
icons/directory - Validates icon sources
Build Components
scripts/build.ts):
- Processes SVG files with SVGO for optimization
- Converts SVG to React components using
GenIcon - Generates TypeScript definitions
- Creates CommonJS and ES Module outputs
- Builds icon manifests for each pack
Validate Icons
- All icon sources are accessible
- SVG files are valid
- No duplicate icon names
- Licenses are documented
Type Check
Build Output
After building, you’ll find:Building for Development
When developing, use the demo app to test changes:Start the demo app
Build Configuration
Babel Configuration
React Icons uses Babel for transpilation with two configs: CommonJS (babel.config.commonjs.json):
babel.config.esm.json):
TypeScript Configuration
tsconfig.json enables strict type checking:
Building Specific Icon Packs
To build only specific icon packs, modify the build script or fetch only needed sources:Testing Your Build
Building the Documentation Site
The documentation site is built with Astro:Start the preview site
The project is not actively accepting PRs for the preview site at this time.
Common Build Issues
Out of memory errors
Out of memory errors
Building all icons requires significant memory. Increase Node.js heap size:
Git fetch failures
Git fetch failures
If fetching icons fails, check your internet connection and GitHub access:Some icon repositories may be rate-limited or temporarily unavailable.
TypeScript errors
TypeScript errors
Ensure you’re using a compatible TypeScript version:
Missing SVG files
Missing SVG files
If build complains about missing SVGs, re-fetch icons:
CI/CD Build
The project uses GitHub Actions for CI. See.github/workflows/ for build pipelines.
Key CI steps:
- Install dependencies with Yarn
- Lint code with ESLint
- Type check with TypeScript
- Fetch icon sources
- Build packages
- Run tests
Next Steps
Contributing
Learn how to contribute your changes
Adding Icon Sets
Add new icon packs to the library