命令行

使用命令行管理 HeroUI 依赖并初始化项目。

heroui-cli 是官方命令行工具,提供一整套命令,用于初始化、管理和优化 HeroUI 项目。你可以 install、uninstall 或 upgrade HeroUI 包、在终端查看组件文档、检查项目健康状况、下载用于 AI 编程助手的文档与设计指南,等等。

安装

环境要求:

全局安装

要全局安装 heroui-cli,请在终端中执行以下命令之一:

npm install heroui-cli@latest -g

无需安装直接使用

或者,你也可以在不进行全局安装的情况下使用 heroui-cli,运行以下命令之一即可:

pnpm dlx heroui-cli@latest

快速开始

安装 heroui-cli 后,运行以下命令以查看可用命令:

heroui

将会输出如下帮助信息:

Usage: heroui [command]

Options:
  -v, --version                 Output the current version
  --no-cache                    Disable cache, by default data will be cached for 30m after the first request
  -d, --debug                   Debug mode will not install dependencies
  --json                        Output the result as JSON
  -h, --help                    Display help for command

Commands:
  init [options] [projectName]  Initializes a new project
  install [options]             Installs @heroui/react and @heroui/styles in your project
  upgrade [options]             Upgrades @heroui/react and @heroui/styles to the latest versions
  uninstall [options]           Uninstalls @heroui/react and @heroui/styles from the project
  list [options]                Lists installed HeroUI packages (@heroui/react, @heroui/styles)
  info [options] <component>    Shows the API Reference for a HeroUI React component
  doc [options] <component>     Shows the documentation for a HeroUI React component
  env [options]                 Displays debugging information for the local environment
  doctor [options]              Checks for issues in the project
  agents-md [options]           Download HeroUI documentation for AI coding agents
  design-md [options]           Download HeroUI design guidance for AI coding agents
  help [command]                Display help for command

JSON 输出

--json 会打印一个 JSON 对象并跳过交互式提示。install、upgrade 和 uninstall 会在不询问确认的情况下继续执行。

init 和 agents-md 仍需要提供原本由提示收集的信息:

heroui init my-heroui-app --template app --package pnpm --json
heroui agents-md --react --output AGENTS.md --json

当项目中同时安装了 @heroui/react 与 heroui-native,或两者都未安装时,agents-md --json 还必须指定 --react、--native 或 --migration 之一。

当无法明确检测平台时,design-md --json 必须指定 --react 或 --native。已存在的目标文件会被直接替换,不会询问确认:

heroui design-md --react --json

缓存

注册表查询结果会缓存在用户目录中,默认 30 分钟:

平台位置
macOS~/Library/Caches/heroui-cli
Linux$XDG_CACHE_HOME/heroui-cli 或 ~/.cache/heroui-cli
Windows%LOCALAPPDATA%\heroui-cli\Cache

在所有平台上都会先检查 XDG_CACHE_HOME(包括 macOS 和 Windows),再使用上表中的默认路径。可通过 HEROUI_CACHE_DIR 自定义缓存目录,或传入 --no-cache 禁用缓存。若没有可写的缓存位置,CLI 会继续运行,只是不使用缓存。

init

使用 init 命令初始化一个新的 HeroUI 项目。该命令会为你的项目完成必要的配置。

heroui init [options]

选项:

  • -t --template [string] 新项目使用的模板,例如 app、pages、vite、react-router
  • -p --package [string] 新项目使用的包管理器

输出:

HeroUI CLI <version>

┌  Create a new project
│
◇  Select a template (Enter to select)
│  ● App (A Next.js 16 with app directory template pre-configured with HeroUI (v3) and Tailwind CSS.)
│  ○ Pages (A Next.js 16 with pages directory template pre-configured with HeroUI (v3) and Tailwind CSS.)
│  ○ Vite (A Vite template pre-configured with HeroUI (v3) and Tailwind CSS.)
│  ○ React Router (A React Router template pre-configured with HeroUI (v3) and Tailwind CSS.)
│
◇  New project name (Enter to skip with default name)
│  my-heroui-app
│
◇  Select a package manager (Enter to select)
│  ● npm
│  ○ yarn
│  ○ pnpm
│  ○ bun
│
◇  Template created successfully!
│
◇  Next steps ───────╮
│                    │
│  cd my-heroui-app  │
│  npm install       │
│                    │
├────────────────────╯
│
└  🚀 Get started with npm run dev

安装依赖以启动本地服务器:

cd my-heroui-app && npm install

启动本地服务器:

npm run dev

Install

将 @heroui/react 和 @heroui/styles 安装到你的项目中,并补齐缺失或低于要求版本的对等依赖。若两个包都已安装,命令会打印确认信息后退出。

heroui install [options]

选项:

  • -p --packagePath [string] package.json 文件的路径

输出:

HeroUI CLI <version>

📦 Packages to be installed:
╭─────────────────────────────────────────────────────────────────────────────╮
│   Package          │   Version        │   Status   │   Docs                 │
│─────────────────────────────────────────────────────────────────────────────│
│   @heroui/react    │   3.0.0          │   stable   │   https://heroui.com   │
│   @heroui/styles   │   3.0.0          │   stable   │   https://heroui.com   │
╰─────────────────────────────────────────────────────────────────────────────╯

╭─────────────── PeerDependencies ────────────────╮
│  react@^19.1.0                     latest       │
│  react-dom@^19.1.0                 latest       │
│  tailwindcss@^4.1.11               latest       │
╰─────────────────────────────────────────────────╯
? Proceed with installation? › - Use arrow-keys. Return to submit.
❯   Yes
    No

✓ @heroui/react and @heroui/styles installed successfully

upgrade

将 @heroui/react 和 @heroui/styles 升级到最新版本。仅当已安装的对等依赖低于 HeroUI 包要求的范围时,才会一并升级。若无需升级,命令会输出 All packages are up to date 且不会提示确认。

heroui upgrade [options]

选项:

  • -p --packagePath [string] package.json 文件的路径

输出:

HeroUI CLI <version>

╭──────────────────────────── Upgrade ────────────────────────────╮
│  @heroui/react               ^3.0.0  ->  ^3.1.0                │
│  @heroui/styles              ^3.0.0  ->  ^3.1.0                │
╰─────────────────────────────────────────────────────────────────╯

? Would you like to proceed with the upgrade? › - Use arrow-keys. Return to submit.
❯   Yes
    No

✓ Upgrade complete

uninstall

从你的项目中卸载 @heroui/react 和 @heroui/styles。对等依赖不会被卸载。

heroui uninstall [options]

选项:

  • -p --packagePath [string] package.json 文件的路径

输出:

HeroUI CLI <version>

❗️ Packages slated for uninstallation:
╭──────────────────────────────────────────────────────────────────────────────────────╮
│   Package          │   Version   │   Status   │   Docs                               │
│──────────────────────────────────────────────────────────────────────────────────────│
│   @heroui/react    │   3.0.0     │   stable   │   https://heroui.com                 │
│   @heroui/styles   │   3.0.0     │   stable   │   https://heroui.com                 │
╰──────────────────────────────────────────────────────────────────────────────────────╯
? Confirm uninstallation of these packages: › - Use arrow-keys. Return to submit.
❯   Yes
    No

✓ Successfully uninstalled: @heroui/react, @heroui/styles

list

列出已安装的 HeroUI 包(@heroui/react、@heroui/styles)。

heroui list [options]

选项:

  • -p --packagePath [string] package.json 文件的路径

输出:

HeroUI CLI <version>

Installed HeroUI packages:

╭──────────────────────────────────────────────────────────────────────────────────────╮
│   Package          │   Version          │   Status   │   Docs                        │
│──────────────────────────────────────────────────────────────────────────────────────│
│   @heroui/react    │   3.0.0 🚀latest   │   stable   │   https://heroui.com          │
│   @heroui/styles   │   3.0.0 🚀latest   │   stable   │   https://heroui.com          │
╰──────────────────────────────────────────────────────────────────────────────────────╯

info

在终端查看 HeroUI React 组件文档中的 API Reference 部分。

heroui info <component>

示例:

heroui info button

支持 Button、button-group 等写法。组件名不区分大小写;若名称有误,CLI 会提示最接近的组件名。

doc

在终端查看 HeroUI React 组件的完整文档页面。

heroui doc <component>

示例:

heroui doc button

支持 Button、button-group 等写法。输出内容与文档站上的组件页一致。

doctor

检查项目中存在的问题。

  • 检查 @heroui/react 和 @heroui/styles 是否已安装
  • 检查项目中是否安装了所需的 对等依赖 并满足最低版本要求
heroui doctor [options]

选项:

  • -p --packagePath [string] package.json 文件的路径

输出:

如果项目中存在问题,doctor 命令将显示问题信息。

HeroUI CLI <version>

HeroUI CLI: ✗ Your project has 1 issue that requires attention

❗️Issue 1: missingHeroUIPackages

The following HeroUI packages are not installed:
- @heroui/styles

Run `heroui install` to install them.

否则,doctor 命令将显示以下消息。

HeroUI CLI <version>

✓ Your project has no detected issues.

当检测到问题时(包括项目中未安装任何 HeroUI 包),命令会以状态码 1 退出。

env

显示本地环境的调试信息。

heroui env

输出:

HeroUI CLI <version>

Environment Info:
  System:
    OS: macOS 26.3
    CPU: (8) arm64 Apple M1 Pro
  Binaries:
    Node: 26.8.1
    Yarn: 1.22.22
    npm: 11.19.0
    pnpm: 12.5.1
    bun: 1.3.12
  Browsers:
    Safari: 26.3
  npmPackages:
    @heroui/react: 3.2.6
    @heroui/styles: 3.2.6
    react-aria-components: 1.21.1
    tailwindcss: 4.1.11

design-md

下载最新的 HeroUI React 或 Native 设计指南,供编程代理使用。明确指定平台时,无需 Git 或预先安装 HeroUI 包;命令会将已发布的 Markdown 原样保存。

heroui design-md [options]

选项:

  • --react 下载 React 设计指南(一次只能选择一个平台)
  • --native 下载 Native 设计指南
  • --output <file> 目标路径,默认为当前目录下的 DESIGN.md。支持相对和绝对路径;缺失的父目录会自动创建
  • --json 输出一个 JSON 结果,不显示提示或人类可读日志

未指定平台标志时,命令会使用与 agents-md 相同的包与工作区检测逻辑。仅检测到 @heroui/react 时选择 React,仅检测到 heroui-native 时选择 Native。两者都存在或都不存在时,命令会进入交互式提示;JSON 与非交互式运行则必须明确指定平台。

每次运行都会直接替换整个目标文件,包括 JSON 与非交互式模式,不会询问确认。成功下载后,本地的设计自定义将会丢失。取消平台选择或下载失败时,已存在的文件保持不变。

示例:

自动检测平台并保存为 DESIGN.md:

heroui design-md

明确下载 React 设计指南:

heroui design-md --react

将 Native 设计指南保存到自定义路径:

heroui design-md --native --output docs/DESIGN.md

通过编程代理或脚本刷新 React 设计指南:

heroui design-md --react --json

每次运行都会发起全新请求,直接从 React DESIGN.md 或 Native DESIGN.md 下载。命令成功下载前,对应端点必须已发布。

该命令只会写入目标文件。它会输出建议的引用方式,但不会修改 AGENTS.md、CLAUDE.md、编辑器规则或 .gitignore。请根据路径调整下列内容,并将其加入代理指令:

Follow [DESIGN.md](./DESIGN.md) for all visual and interaction decisions.

JSON 成功结果包含 command、ok、selection、绝对路径 outputFile 和 sourceUrl。失败时返回 command、ok: false 与 error,并以状态码 1 退出。

更多详情请参阅 DESIGN.md。

agents-md

下载用于 AI 编程助手(Claude、Cursor 等)的 HeroUI 文档。该命令会从 HeroUI 仓库克隆最新文档,并将一份精简索引注入到 AGENTS.md 或 CLAUDE.md 中,方便助手参考你项目中的 HeroUI 配置。

未指定文档库标志时,命令会检查项目:仅安装 @heroui/react 时选择 React 文档,仅安装 heroui-native 时选择 Native 文档;随后会询问输出文件(除非已传入 --output)。当两个包都安装或都未安装时,会询问要下载哪类文档。

heroui agents-md [options]

选项:

  • --react [boolean] 仅包含 React 文档(一次只能选择一个文档库)
  • --native [boolean] 仅包含 Native 文档
  • --migration [boolean] 仅包含 HeroUI v2 到 v3 的迁移文档
  • --output <files...> [string] 目标文件路径。可传入多个路径以同时更新多个文件,例如 AGENTS.md CLAUDE.md
  • --ssh [boolean] 使用 SSH 而非 HTTPS 进行 git clone

示例:

不带任何标志运行以进入交互模式:

heroui agents-md

将 React 文档下载到指定文件:

heroui agents-md --react --output AGENTS.md

下载 Native 或迁移文档:

heroui agents-md --native --output CLAUDE.md
heroui agents-md --migration --output AGENTS.md

当 HTTPS 克隆失败时,可使用 SSH:

heroui agents-md --react --ssh --output AGENTS.md

工作原理:

  1. 使用 git sparse-checkout 从 v3 分支克隆文档
  2. 生成文档和示例文件的精简索引
  3. 将该索引注入到你的 markdown 文件中,置于标记之间(<!-- HEROUI-REACT-AGENTS-MD-START --> / <!-- HEROUI-REACT-AGENTS-MD-END -->,Native 和 Migration 也有类似的标记)
  4. 将 .heroui-docs/ 添加到 .gitignore

--react、--native 和 --migration 一次只能选择其中一个。

更多详情请参阅 AGENTS.md。

agents-md 与 design-md 会收集匿名使用数据:所选内容类型(在命令支持的范围内为 react、native 或 migration)、输出路径、写入文件数量、耗时、成功或失败(失败时包含错误信息)。不会收集项目内容。设置 HEROUI_ANALYTICS_DISABLED=1 可以选择不参与。

从 NextUI 迁移

@heroui/codemod 可将 @nextui-org/* 包与 API 重命名为 @heroui/*,但不会把项目升级到 HeroUI v3。v3 迁移指南请运行 heroui agents-md --migration。

问题反馈

如果你发现了 bug,请在 heroui-cli Issues 中报告。

本页目录

使用 HeroUI Pro 更快构建组件、模板与 AI 工具探索 Pro