Nuxt/docs/content/3.docs/1.usage/8.cli.md

5.1 KiB

Nuxi CLI

Nuxi is the new Command-line interface (CLI) for Nuxt 3. This page references the commands and options of Nuxi.

Init

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

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

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.

The port and host can also be set via NUXT_PORT, PORT, NUXT_HOST or HOST environment variables.

This command sets process.env.NODE_ENV to development. To override, define NODE_ENV in a .env file or as command-line argument.

Build

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

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.

::alert{type=info} For convenience, in preview mode, your .env file will be loaded into process.env. (However, in production you will need to ensure your environment variables are set yourself.) ::

Info

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.

Analyze

npx nuxi analyze [rootDir]

The analyze command builds nuxt and analyzes the production bundle (experimental)

Option Default Description
rootDir . The directory of the target application.

Typecheck

npx nuxi typecheck [rootDir]

The typecheck command runs 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

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

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:

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)