> For AI agents: the complete documentation index is available at /zh/llms.txt, the full documentation bundle is available at /zh/llms-full.txt.

# 快速上手

## 环境准备

Rslib 支持使用 [Node.js](https://nodejs.org/)、[Deno](https://deno.com/) 或 [Bun](https://bun.sh/) 作为 JavaScript 运行时。

你可以参考以下安装指南，选择其中一种运行时：

- [安装 Node.js](https://nodejs.org/zh-cn/download)
- [安装 Bun](https://bun.com/docs/installation)
- [安装 Deno](https://docs.deno.com/runtime/getting_started/installation/)

:::tip 版本要求

Rslib v1 要求 Node.js 版本 20.19+, 22.12+。

:::

## 创建 Rslib 项目

使用 [create-rslib](https://www.npmjs.com/package/create-rslib) 来创建一个 Rslib 项目，运行以下命令：


```sh [npm]
npm create rslib@latest
```

```sh [yarn]
yarn create rslib
```

```sh [pnpm]
pnpm create rslib@latest
```

```sh [bun]
bun create rslib@latest
```

```sh [deno]
deno init --npm rslib@latest
```

按照提示一步步操作即可。在创建过程中，你可以选择模板、语言、可选工具，以及供 Coding Agents 使用的可选技能。

创建的 Rslib 项目默认使用 [Rstest](https://rstest.rs/zh/) 作为测试框架，阅读 [使用 Rstest](/zh/guide/advanced/rstest.md) 了解更多信息。

脚手架默认会在生成的项目中初始化 Git 仓库。如需跳过 Git 初始化，请在创建命令中添加 `--no-git`。

在创建完成后，你可以执行以下步骤：

- 执行 `npm install`（或其他包管理器的 install 命令）安装 npm 依赖。
- 执行 `npm run dev` 启动监听模式开始开发。

### 模板

在创建项目时，你可以选择 `create-rslib` 提供的下列模板：

| 模板              | 描述         |
| --------------- | ---------- |
| Node.js package | Node.js 包  |
| React           | React 组件库  |
| Vue             | Vue 组件库    |
| Svelte          | Svelte 组件库 |
| Solid           | Solid 组件库  |

### 可选工具

`create-rslib` 能够帮助你设置以下常用工具，你可以使用上下箭头和空格进行选择。如果你不需要这些工具，可以直接按回车跳过。

| 工具                                                           | 用途                           |
| ------------------------------------------------------------ | ---------------------------- |
| [ESLint](https://eslint.org/)                                | 代码检查                         |
| [Rslint](https://rslint.rs/)                                 | 代码检查                         |
| [Prettier](https://prettier.io/)                             | 代码格式化                        |
| [Biome](https://biomejs.dev/)                                | 代码检查和格式化                     |
| [Rspress](https://rspress.rs/zh/)                            | 组件文档，仅 React + TypeScript 模板 |
| [Storybook](https://storybook.js.org/)                       | 组件开发和预览，仅 React 和 Vue 模板     |
| [React Compiler](/zh/guide/solution/react.md#react-compiler) | 优化 React 组件，仅 React 模板       |

### 可选技能

`create-rslib` 可以为支持 Skills 的 Coding Agents 安装可选技能。在交互模式下，“可选工具”的选择会影响可选技能的结果。目前提供的技能有：

| 名称                                                                                                      | 条件           |
| ------------------------------------------------------------------------------------------------------- | ------------ |
| [rslib-best-practices](https://github.com/rstackjs/agent-skills#rslib-best-practices)                   | 默认显示         |
| [rstest-best-practices](https://github.com/rstackjs/agent-skills#rstest-best-practices)                 | 默认显示         |
| [rspress-custom-theme](https://github.com/rstackjs/agent-skills#rspress-custom-theme)                   | 选择 `Rspress` |
| [rspress-description-generator](https://github.com/rstackjs/agent-skills#rspress-description-generator) | 选择 `Rspress` |

你可以使用上下箭头和空格进行选择。如果不需要这些技能，可以直接按回车跳过。

```text
◆  Select optional skills (Use <space> to select, <enter> to continue)
│  ◻ Rslib - best practices
│  ◻ Rstest - best practices
```

关于 Agent Skills 和其他 AI 相关能力的更多介绍，可参考 [AI](/zh/guide/start/ai.md)。

### 当前目录

如果你需要在当前目录下创建项目，可以将 target folder 设置为 `.`：

```text
◆  Create Rslib Project
│
◇  Project name or path
│  .
│
◇  "." is not empty, please choose:
│  Continue and override files
```

### 非交互模式

[create-rslib](https://www.npmjs.com/package/create-rslib) 支持通过命令行选项进入非交互模式。使用该模式可以跳过所有提示，直接创建项目，适合脚本、CI 以及 coding agents 等自动化场景。

例如，以下命令将在 `my-project` 目录中创建一个 React 项目：

```bash
npx -y create-rslib@latest my-project --template react

# 使用缩写
npx -y create-rslib@latest my-project -t react

# 指定多个 tools
npx -y create-rslib@latest my-project -t react --tools storybook,biome

# 为 Coding Agents 安装可选 skill
npx -y create-rslib@latest my-project -t react --skill rslib-best-practices
```

`create-rslib` 完整的 CLI 选项如下：

```text
Usage: create-rslib [dir] [options]

Options:

  -h, --help            display help for command
  -d, --dir <dir>       create project in specified directory
  -t, --template <tpl>  specify the template to use
  --no-git              skip Git repository initialization
  --tools <tool>        add additional tools, comma separated
  --skill <skill>       add optional skills, comma separated
  --override            override files in target directory
  --packageName <name>  specify the package name

Available templates:
  node-js, node-ts, react-js, react-ts, vue-js, vue-ts, svelte-js, svelte-ts, solid-js, solid-ts

Optional tools:
  react-compiler, eslint, rslint, biome, prettier, rspress, storybook

Optional skills:
  rslib-best-practices, rstest-best-practices, rspress-custom-theme, rspress-description-generator
```

## 从现有项目迁移

如果你需要从一个现有项目迁移迁移到 Rslib，可以参考以下指南：

- [从 tsup 迁移](/zh/guide/migration/tsup.md)
- [从 tsc 迁移](/zh/guide/migration/tsc.md)

### 其他项目

对于其他类型的项目，你可以手动安装 [@rslib/core](https://www.npmjs.com/package/@rslib/core) 包：


```sh [npm]
npm add @rslib/core -D
```

```sh [yarn]
yarn add @rslib/core -D
```

```sh [pnpm]
pnpm add @rslib/core -D
```

```sh [bun]
bun add @rslib/core -D
```

```sh [deno]
deno add npm:@rslib/core -D
```

然后参考指南和文档，按需启用各个功能：

- 参考 [命令行工具](/zh/guide/basic/cli.md) 来了解可用的 CLI 命令。
- 参考 [配置 Rslib](/zh/guide/basic/configure-rslib.md) 进行配置。
