mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-11 08:33:53 +00:00
95 lines
1.7 KiB
Markdown
95 lines
1.7 KiB
Markdown
---
|
|
title: Nitro
|
|
description: 'Activate Nitro to your Nuxt 2 application with Nuxt Bridge.'
|
|
---
|
|
|
|
## Remove Modules
|
|
|
|
- Remove `@nuxt/nitro`: Bridge injects same functionality
|
|
|
|
## Update Config
|
|
|
|
```ts [nuxt.config.ts]
|
|
import { defineNuxtConfig } from '@nuxt/bridge'
|
|
|
|
export default defineNuxtConfig({
|
|
bridge: {
|
|
nitro: true
|
|
}
|
|
})
|
|
```
|
|
|
|
## Update Your Scripts
|
|
|
|
You will also need to update your scripts within your `package.json` to reflect the fact that Nuxt will now produce a Nitro server as build output.
|
|
|
|
### Install Nuxi
|
|
|
|
Install `nuxi` as a development dependency:
|
|
|
|
::code-group
|
|
|
|
```bash [yarn]
|
|
yarn add --dev nuxi
|
|
```
|
|
|
|
```bash [npm]
|
|
npm install -D nuxi
|
|
```
|
|
|
|
::
|
|
|
|
### Nuxi
|
|
|
|
Nuxt 3 introduced the new Nuxt CLI command [`nuxi`](/docs/api/commands/add). Update your scripts as follows to leverage the better support from Nuxt Bridge:
|
|
|
|
```diff
|
|
{
|
|
"scripts": {
|
|
- "dev": "nuxt",
|
|
+ "dev": "nuxi dev",
|
|
- "build": "nuxt build",
|
|
+ "build": "nuxi build",
|
|
- "start": "nuxt start",
|
|
+ "start": "nuxi preview"
|
|
}
|
|
}
|
|
```
|
|
|
|
::tip
|
|
If `nitro: false`, use the `nuxt2` command.
|
|
::
|
|
|
|
### Static Target
|
|
|
|
If you have set `target: 'static'` in your `nuxt.config` then you need to ensure that you update your build script to be `nuxi generate`.
|
|
|
|
```json [package.json]
|
|
{
|
|
"scripts": {
|
|
"build": "nuxi generate"
|
|
}
|
|
}
|
|
```
|
|
|
|
### Server Target
|
|
|
|
For all other situations, you can use the `nuxi build` command.
|
|
|
|
```json [package.json]
|
|
{
|
|
"scripts": {
|
|
"build": "nuxi build",
|
|
"start": "nuxi preview"
|
|
}
|
|
}
|
|
```
|
|
|
|
## Exclude Built Nitro Folder From Git
|
|
|
|
Add the folder `.output` to the `.gitignore` file.
|
|
|
|
## Ensure Everything Goes Well
|
|
|
|
✔️ Try with `nuxi dev` and `nuxi build` (or `nuxi generate`) to see if everything goes well.
|