Skip to main content

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

1

Install Node.js

React Icons requires Node.js 14 or higher:
Download from nodejs.org if needed.
2

Install Yarn

The project uses Yarn (v3.2.4+) as the package manager:
3

Clone the repository

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

1

Install dependencies

This installs dependencies for all packages in the monorepo.
2

Navigate to the package

3

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.
4

Build the icons

Generate React components from SVG files:
This creates:
  • lib/ - Compiled JavaScript modules
  • Icon components for each pack (e.g., fa/, md/, hi/)

Build Scripts Explained

The main package has several build scripts defined in package.json:

Fetch Icons

This script (scripts/fetcher.ts):
  1. Reads icon pack definitions from src/icons/index.ts
  2. Clones/updates Git repositories for each icon pack
  3. Copies SVG files to the icons/ directory
  4. Validates icon sources

Build Components

The build script (scripts/build.ts):
  1. Processes SVG files with SVGO for optimization
  2. Converts SVG to React components using GenIcon
  3. Generates TypeScript definitions
  4. Creates CommonJS and ES Module outputs
  5. Builds icon manifests for each pack

Validate Icons

Validates that:
  • All icon sources are accessible
  • SVG files are valid
  • No duplicate icon names
  • Licenses are documented

Type Check

Runs TypeScript compiler to verify types without generating output.

Build Output

After building, you’ll find:

Building for Development

When developing, use the demo app to test changes:
1

Build react-icons package

2

Start the demo app

The demo app runs at http://localhost:3000
3

Make changes and rebuild

Edit source files in packages/react-icons/src/, then rebuild:
Refresh the demo app to see changes.

Build Configuration

Babel Configuration

React Icons uses Babel for transpilation with two configs: CommonJS (babel.config.commonjs.json):
ES Modules (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:
Building all 30+ icon packs generates 40,000+ components and may take significant time and disk space (500MB+).

Testing Your Build

1

Create a test project

2

Link your local build

3

Test importing icons

App.js
4

Verify tree-shaking

Check the bundle size to ensure only imported icons are included.

Building the Documentation Site

The documentation site is built with Astro:
1

Build react-icons first

2

Start the preview site

Access the site at http://localhost:4321
The project is not actively accepting PRs for the preview site at this time.

Common Build Issues

Building all icons requires significant memory. Increase Node.js heap size:
If fetching icons fails, check your internet connection and GitHub access:
Some icon repositories may be rate-limited or temporarily unavailable.
Ensure you’re using a compatible TypeScript version:
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:
  1. Install dependencies with Yarn
  2. Lint code with ESLint
  3. Type check with TypeScript
  4. Fetch icon sources
  5. Build packages
  6. Run tests

Next Steps

Contributing

Learn how to contribute your changes

Adding Icon Sets

Add new icon packs to the library