2022-03-09 18:57:47 +00:00
|
|
|
# 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.
|
|
|
|
|
2022-03-11 07:57:59 +00:00
|
|
|
This command sets `process.env.NODE_ENV` to `development`. To override, define `NODE_ENV` in a `.env` file or as command-line argument.
|
|
|
|
|
2022-03-09 18:57:47 +00:00
|
|
|
## 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.
|
|
|
|
|
2022-03-11 07:57:59 +00:00
|
|
|
This command sets `process.env.NODE_ENV` to `production`. To override, define `NODE_ENV` in a `.env` file or as command-line argument.
|
|
|
|
|
2022-03-09 18:57:47 +00:00
|
|
|
## 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.
|
|
|
|
|
2022-03-11 07:57:59 +00:00
|
|
|
This command sets `process.env.NODE_ENV` to `production`. To override, define `NODE_ENV` in a `.env` file or as command-line argument.
|
|
|
|
|
2022-03-09 18:57:47 +00:00
|
|
|
## 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.
|
|
|
|
|
2022-03-11 07:57:59 +00:00
|
|
|
This command sets `process.env.NODE_ENV` to `production`. To override, define `NODE_ENV` in a `.env` file or as command-line argument.
|
|
|
|
|
2022-03-09 18:57:47 +00:00
|
|
|
## Upgrade
|
|
|
|
|
|
|
|
```{bash}
|
|
|
|
npx nuxi upgrade [--force|-f]
|
|
|
|
```
|
|
|
|
|
2022-03-11 07:57:59 +00:00
|
|
|
The `upgrade` command upgrades Nuxt 3 to the latest version.
|
2022-03-09 18:57:47 +00:00
|
|
|
|
|
|
|
Option | Default | Description
|
|
|
|
-------------------------|-----------------|------------------
|
|
|
|
`--force, -f` | `false` | Removes `node_modules` and lock files before upgrade.
|
2022-03-25 14:56:36 +00:00
|
|
|
|
|
|
|
## 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 already exsits.
|
|
|
|
|
|
|
|
**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`)
|