> ## Documentation Index
> Fetch the complete documentation index at: https://bun.ll1025.cn/llms.txt
> Use this file to discover all available pages before exploring further.

# bun init

> 使用交互式 `bun init` 命令脚手架一个空的 Bun 项目

使用 `bun init` 脚手架一个新的 Bun 项目。

```bash terminal icon="terminal" theme={null}
bun init my-app
```

```txt theme={null}
? Select a project template - Press return to submit.
❯ Blank
  React
  Library

✓ Select a project template: Blank

 + .gitignore
 + CLAUDE.md
 + .cursor/rules/use-bun-instead-of-node-vite-npm-pnpm.mdc -> CLAUDE.md
 + index.ts
 + tsconfig.json (for editor autocomplete)
 + README.md
```

按 `enter` 接受每个提示的默认答案，或传递 `-y` 标志以自动接受默认值。

***

`bun init` 使用合理的默认值推断设置，并且多次运行时不会产生破坏性。

<Frame>
  ![Demo](https://user-images.githubusercontent.com/709451/183006613-271960a3-ff22-4f7c-83f5-5e18f684c836.gif)
</Frame>

它创建：

* 一个 `package.json` 文件，名称默认为当前目录名
* 一个 `tsconfig.json` 或 `jsconfig.json` 文件，取决于入口点是否是 TypeScript 文件
* 一个入口点，默认为 `index.ts`，除非存在任何 `index.{tsx, jsx, js, mts, mjs}` 或 `package.json` 指定了 `module` 或 `main` 字段
* 一个 `README.md` 文件

AI Agent 规则（使用 `$BUN_AGENT_RULE_DISABLED=1` 禁用）：

* 当检测到 Claude CLI 时（使用 `CLAUDE_CODE_AGENT_RULE_DISABLED` 环境变量禁用），创建一个 `CLAUDE.md` 文件
* 当检测到 Cursor 时，创建一个 `.cursor/rules/*.mdc` 文件，告诉 [Cursor AI](https://cursor.sh) 使用 Bun 而不是 Node.js 和 npm

传递 `-y` 或 `--yes` 以接受默认值而不提示。

最后，它运行 `bun install` 来安装 `@types/bun`。

***

## CLI 用法

```bash terminal icon="terminal" theme={null}
bun init <folder?>
```

### 初始化选项

<ParamField path="--yes" type="boolean">
  接受所有默认提示，不询问问题。别名：<code>-y</code>
</ParamField>

<ParamField path="--minimal" type="boolean">
  仅初始化类型定义（跳过应用脚手架）。别名：<code>-m</code>
</ParamField>

### 项目模板

<ParamField path="--react" type="string|boolean">
  搭建 React 项目。不加值时创建基础的 React 应用。
  <br /> 接受预设值：

  <ul>
    <li>
      <code>tailwind</code> – 预配置 Tailwind CSS 的 React 应用
    </li>

    <li>
      <code>shadcn</code> – 带 <code>@shadcn/ui</code> 和 Tailwind CSS 的 React 应用
    </li>
  </ul>

  示例：

  <pre>
    <code>bun init --react bun init --react=tailwind bun init --react=shadcn</code>
  </pre>
</ParamField>

### 输出与文件

<ParamField path="(result)" type="info">
  为所选选项初始化项目文件和配置。具体文件因模板而异。
</ParamField>

### 帮助

<ParamField path="--help" type="boolean">
  打印此帮助菜单。别名：<code>-h</code>
</ParamField>

### 示例

* 接受所有默认值

  ```bash terminal icon="terminal" theme={null}
  bun init -y
  ```

* React

  ```bash terminal icon="terminal" theme={null}
  bun init --react
  ```

* React + Tailwind CSS

  ```bash terminal icon="terminal" theme={null}
  bun init --react=tailwind
  ```

* React + @shadcn/ui
  ```bash terminal icon="terminal" theme={null}
  bun init --react=shadcn
  ```
