---
title: "Nitro"
description: "通过 Nuxt Bridge 在你的 Nuxt 2 应用中启用 Nitro。"
canonical_url: "https://nuxt.zhcndoc.com/docs/4.x/bridge/nitro"
---
# Nitro

> 通过 Nuxt Bridge 在你的 Nuxt 2 应用中启用 Nitro。

## 移除模块

- 移除 `@nuxt/nitro`：Bridge 已注入相同功能

## 更新配置

```ts [nuxt.config.ts]
import { defineNuxtConfig } from '@nuxt/bridge'

export default defineNuxtConfig({
  bridge: {
    nitro: true,
  },
})
```

## 更新你的脚本

你还需要更新 `package.json` 中的脚本以反映 Nuxt 现在会将 Nitro 服务器作为构建输出的事实。

### 安装 Nuxi

将 `nuxi` 安装为开发依赖：

::code-group{sync="pm"}
```bash [npm]
npm install -D nuxi
```

```bash [yarn]
yarn add --dev nuxi
```

```bash [pnpm]
pnpm add -D nuxi
```

```bash [bun]
bun add -D nuxi
```

```bash [deno]
deno add -D npm:nuxi
```
::

### Nuxi

Nuxt 3 引入了新的 Nuxt CLI 命令 [`nuxi`](https://nuxt.zhcndoc.com/docs/4.x/api/commands/add)。按如下方式更新脚本，以利用 Nuxt Bridge 提供的更好支持：

```diff
{
  "scripts": {
-   "dev": "nuxt",
+   "dev": "nuxi dev",
-   "build": "nuxt build",
+   "build": "nuxi build",
-   "start": "nuxt start",
+   "start": "nuxi preview"
  }
}
```

::tip
如果 `nitro: false`，请使用 `nuxt2` 命令。
::

### 静态目标

如果你在 `nuxt.config` 中设置了 `target: 'static'`，则需要确保将你的构建脚本更新为 `nuxi generate`。

```json [package.json]
{
  "scripts": {
    "build": "nuxi generate"
  }
}
```

### 服务器目标

在其他情况下，你可以使用 `nuxi build` 命令。

```json [package.json]
{
  "scripts": {
    "build": "nuxi build",
    "start": "nuxi preview"
  }
}
```

## 将已构建的 Nitro 文件夹从 Git 排除

将文件夹 `.output` 添加到 `.gitignore` 文件中。

## 确保一切正常

✔️ 使用 `nuxi dev` 和 `nuxi build`（或 `nuxi generate`）试一下，看看是否一切正常。


## Sitemap

See the full [sitemap](https://nuxt.zhcndoc.com/sitemap.md) for all pages.
