Nuxt/docs/content/3.docs/1.usage/8.cli.md
2022-03-29 15:14:11 +02:00

134 lines
4.5 KiB
Markdown

# Nuxi CLI
Nuxi is the new Command-line interface (CLI) for Nuxt 3. This page references the commands and options of Nuxi.
## Init
```{bash}
npx nuxi init|create [--verbose|-v] [--template,-t] [dir]
```
The `init` command initializes a fresh Nuxt project.
Option | Default | Description
-------------------------|-----------------|------------------
`--verbose, -v` | `false` | Log informations about the installation process.
`--template, -t` | `nuxt/starter#v3` | Specify a Git repository to use as a template.
`dir` | `nuxt-app` | Name of the install directory.
## Dev
```{bash}
npx nuxi dev [rootDir] [--clipboard] [--open, -o] [--port, -p] [--host, -h] [--https] [--ssl-cert] [--ssl-key]
```
The `dev` command starts a development server with hot module replacement at [http://localhost:3000](https://localhost:3000)
Option | Default | Description
-------------------------|-----------------|------------------
`rootDir` | `.` | The root directory of the application to serve.
`--clipboard` | `false` | Copy URL to clipboard.
`--open, -o` | `false` | Open URL in browser.
`--port, -p` | `3000` | Port to listen.
`--host, -h` | `localhost` | Hostname of the server.
`--https` | `false` | Listen with `https` protocol with a self-signed certificate by default.
`--ssl-cert` |`null` | Specify a certificate for https.
`--ssl-key` |`null` | Specify the key for the https certificate.
This command sets `process.env.NODE_ENV` to `development`. To override, define `NODE_ENV` in a `.env` file or as command-line argument.
## Build
```{bash}
npx nuxi build [rootDir]
```
The `build` command creates a `.output` directory with all your application, server and dependencies ready for production.
Option | Default | Description
-------------------------|-----------------|------------------
`rootDir` | `.` | The root directory of the application to bundle.
This command sets `process.env.NODE_ENV` to `production`. To override, define `NODE_ENV` in a `.env` file or as command-line argument.
## Preview
```{bash}
npx nuxi preview [rootDir]
```
The `preview` command starts a server to preview your Nuxt application after running the `build` command.
Option | Default | Description
-------------------------|-----------------|------------------
`rootDir` | `.` | The root directory of the application to preview.
This command sets `process.env.NODE_ENV` to `production`. To override, define `NODE_ENV` in a `.env` file or as command-line argument.
## Info
```{bash}
npx nuxi info [rootDir]
```
The `info` command logs informations about the current or specified Nuxt project.
Option | Default | Description
-------------------------|-----------------|------------------
`rootDir` | `.` | The directory of the target application.
## Typecheck
```{bash}
npx nuxi typecheck [rootDir]
```
The `typecheck` command runs [`vue-tsc`](https://github.com/johnsoncodehk/volar/tree/master/packages/vue-tsc) to check types throughout your app.
Option | Default | Description
-------------------------|-----------------|------------------
`rootDir` | `.` | The directory of the target application.
This command sets `process.env.NODE_ENV` to `production`. To override, define `NODE_ENV` in a `.env` file or as command-line argument.
## Upgrade
```{bash}
npx nuxi upgrade [--force|-f]
```
The `upgrade` command upgrades Nuxt 3 to the latest version.
Option | Default | Description
-------------------------|-----------------|------------------
`--force, -f` | `false` | Removes `node_modules` and lock files before upgrade.
## Add
```{bash}
npx nuxi add [--cwd] [--force] <TEMPLATE> <NAME>
```
Option | Default | Description
-------------------------|-----------------|------------------
`TEMPLATE` | - | Specify a template of the file to be generated.
`NAME` | - | Specify a name of the file that will be created.
`--cwd` | `.` | The directory of the target application.
`--force` | `false` | Force override file if it already exists.
**Example:**
```{bash}
npx nuxi add component TheHeader
```
The `add` command generates new elements:
* **component**: `npx nuxi add component TheHeader`
* **composable**: `npx nuxi add composable foo`
* **layout**: `npx nuxi add layout custom`
* **plugin**: `npx nuxi add plugin analytics`
* **page**: `npx nuxi add page about` or `npx nuxi add page "category/[id]"`
* **middleware**: `npx nuxi add middleware auth`
* **api**: `npx nuxi add api hello` (CLI will generate file under `/server/api`)