Back to Nuxt

nuxt add

docs/4.api/4.commands/add.md

4.4.43.1 KB
Original Source
<!--add-cmd-->
bash
npx nuxt add <TEMPLATE> <NAME> [--cwd=<directory>] [--logLevel=<silent|info|verbose>] [--force]
<!--/add-cmd-->

Arguments

<!--add-args-->
ArgumentDescription
TEMPLATESpecify which template to generate (options: <api|app|app-config|component|composable|error|layer|layout|middleware|module|page|plugin|server-middleware|server-plugin|server-route|server-util>)
NAMESpecify name of the generated file
<!--/add-args-->

Options

<!--add-opts-->
OptionDefaultDescription
--cwd=<directory>.Specify the working directory
--logLevel=<silent|info|verbose>Specify build-time log level
--forcefalseForce override file if it already exists
<!--/add-opts-->

Modifiers:

Some templates support additional modifier flags to add a suffix (like .client or .get) to their name.

bash
# Generates `/plugins/sockets.client.ts`
npx nuxt add plugin sockets --client

nuxt add component

  • Modifier flags: --mode client|server or --client or --server
bash
# Generates `app/components/TheHeader.vue`
npx nuxt add component TheHeader

nuxt add composable

bash
# Generates `app/composables/foo.ts`
npx nuxt add composable foo

nuxt add layout

bash
# Generates `app/layouts/custom.vue`
npx nuxt add layout custom

nuxt add plugin

  • Modifier flags: --mode client|server or --clientor --server
bash
# Generates `app/plugins/analytics.ts`
npx nuxt add plugin analytics

nuxt add page

bash
# Generates `app/pages/about.vue`
npx nuxt add page about
bash
# Generates `app/pages/category/[id].vue`
npx nuxt add page "category/[id]"

nuxt add middleware

  • Modifier flags: --global
bash
# Generates `app/middleware/auth.ts`
npx nuxt add middleware auth

nuxt add api

  • Modifier flags: --method (can accept connect, delete, get, head, options, patch, post, put or trace) or alternatively you can directly use --get, --post, etc.
bash
# Generates `server/api/hello.ts`
npx nuxt add api hello

nuxt add layer

bash
# Generates `layers/subscribe/nuxt.config.ts`
npx nuxt add layer subscribe