npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

generate-react-cli

v11.0.1

Published

A simple React CLI to generate components instantly and more.

Downloads

30,569

Readme

Generate React CLI

License

A CLI tool to speed up productivity in React projects by generating components instantly with configurable templates.

Table of Contents

Quick Start

# Generate your first component (creates config on first run)
npx generate-react-cli component Box

# Or install globally
npm i -g generate-react-cli
generate-react component Button

Requirements

  • Node.js 22 or higher
  • npm 10 or higher

Config File

When you run GRC within your project the first time, it will ask you a series of questions to customize the CLI for your project needs (this will create a generate-react-cli.json config file).

{
  "usesTypeScript": true,
  "usesCssModule": true,
  "cssPreprocessor": "scss",
  "testLibrary": "Testing Library",
  "component": {
    "default": {
      "path": "src/components",
      "withLazy": false,
      "withStory": false,
      "withStyle": true,
      "withTest": true
    }
  }
}

Test library options:

| Option | Description | |--------|-------------| | Testing Library | Uses React Testing Library | | Vitest | Uses Vitest with React Testing Library | | None | Basic tests using React's createRoot API |

Generate Components

npx generate-react-cli component Box

This command will create a folder with your component name within your default (e.g., src/components) directory, and its corresponding files.

|-- /src
    |-- /components
        |-- /Box
            |-- Box.js
            |-- Box.css
            |-- Box.test.js

Options

You can override config rules using command-line options:

npx generate-react-cli component Box --withTest=false

| Option | Description | Default | |--------|-------------|---------| | --path | Output directory for the component | Config value | | --type | Custom component type to use | default | | --withLazy | Generate a lazy-loading wrapper file | Config value | | --withStory | Generate a Storybook story file | Config value | | --withStyle | Generate a stylesheet file | Config value | | --withTest | Generate a test file | Config value | | --dry-run | Preview what will be generated without writing files | false | | --flat | Generate files directly in path without creating a folder | false | | --customDirectory | Override the component's folder name (see below) | Component name |

Custom Component Types

By default, GRC uses the component.default configuration. You can define additional component types with their own rules:

{
  "usesTypeScript": false,
  "usesCssModule": true,
  "cssPreprocessor": "scss",
  "testLibrary": "Testing Library",
  "component": {
    "default": {
      "path": "src/components",
      "withLazy": false,
      "withStory": false,
      "withStyle": true,
      "withTest": true
    },
    "page": {
      "path": "src/pages",
      "withLazy": true,
      "withStory": false,
      "withStyle": true,
      "withTest": true
    },
    "layout": {
      "path": "src/layout",
      "withLazy": false,
      "withStory": false,
      "withStyle": false,
      "withTest": true
    }
  }
}

Generate components with custom types:

npx generate-react-cli component HomePage --type=page
npx generate-react-cli component Sidebar --type=layout

Custom Component Templates

Create your own templates that GRC uses instead of the built-in ones. Add a customTemplates object to any component type:

{
  "component": {
    "default": {
      "path": "src/components",
      "withStyle": true,
      "withTest": true,
      "customTemplates": {
        "component": "templates/TemplateName.js",
        "style": "templates/TemplateName.module.css",
        "test": "templates/TemplateName.test.js"
      }
    }
  }
}

Example custom component template:

// templates/TemplateName.js

import styles from './TemplateName.module.css';

const TemplateName = () => (
  <div className={styles.TemplateName} data-testid="TemplateName">
    <h1>TemplateName component</h1>
  </div>
);

export default TemplateName;

Example custom test template:

// templates/TemplateName.test.js

import { createRoot } from 'react-dom/client';
import TemplateName from './TemplateName';

it('should mount', () => {
  const container = document.createElement('div');
  const root = createRoot(container);
  root.render(<TemplateName />);
  root.unmount();
});

All template types are optional. If you don't specify a custom template for a file type, GRC uses its built-in template.

Template Keywords

Use these keywords in your custom templates and filenames. GRC replaces them with the component name in various formats:

| Keyword | Output Format | Example (Box) | |---------|--------------|-----------------| | templatename | raw (as typed) | Box | | TemplateName | PascalCase | Box | | templateName | camelCase | box | | template-name | kebab-case | box | | template_name | snake_case | box | | TEMPLATE_NAME | UPPER_SNAKE | BOX | | TEMPLATENAME | UPPERCASE | BOX |

Custom Component Files

Add custom files beyond the built-in options (withStyle, withTest, withStory, withLazy).

Example: Adding an index.js barrel file for cleaner imports:

{
  "component": {
    "default": {
      "path": "src/components",
      "withStyle": true,
      "withTest": true,
      "withIndex": true,
      "customTemplates": {
        "index": "templates/index.js"
      }
    }
  }
}
// templates/index.js
export { default } from './TemplateName';

Custom files require corresponding custom templates in customTemplates.

Advanced: Custom Directory

Override the generated component's folder name using customDirectory. This is useful when you need naming conventions that differ from the component name.

Example: Generate a Theme provider where files live in a ThemeProvider folder:

{
  "component": {
    "provider": {
      "path": "src/providers",
      "withTest": true,
      "customDirectory": "TemplateNameProvider",
      "customTemplates": {
        "component": "templates/TemplateNameProvider.tsx"
      }
    }
  }
}
npx generate-react-cli component Theme --type=provider
# Creates: src/providers/ThemeProvider/ThemeProvider.tsx

You can also pass it as a CLI option:

npx generate-react-cli component Box --customDirectory=TemplateNameLayout

License

Generate React CLI is open source software licensed as MIT.