new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

Nuxt · API · all subjects

commands

101 notes in this subject, read out of this brain and free to use. This is page 2 of 2.

nuxt module search arguments

The `nuxt module search` command accepts one argument: `QUERY` for keywords to search for.

nuxt prepare ROOTDIR argument

The ROOTDIR argument specifies the working directory for the prepare command, with a default value of '.'

nuxt prepare command purpose

The prepare command creates a .nuxt directory in your application and generates types. This is useful in a CI environment or as a postinstall command in package.json.

nuxt prepare --envName option

The --envName option specifies the environment to use when resolving configuration overrides. The default is 'production' when building, and 'development' when running the dev server.

nuxt prepare sets NODE_ENV to production

The prepare command sets process.env.NODE_ENV to 'production'.

nuxt prepare command signature

The prepare command is invoked as: npx nuxt prepare [ROOTDIR] [--dotenv] [--cwd=<directory>] [--logLevel=<silent|info|verbose>] [--envName] [-e, --extends=<layer-name>]

preview command sets NODE_ENV to production

The preview command sets process.env.NODE_ENV to production. To override this, define NODE_ENV in a .env file or as a command-line argument.

preview command purpose

The preview command starts a server to preview your Nuxt application after running the build command. The start command is an alias for preview.

nuxt preview command syntax

The preview command is invoked with: npx nuxt preview [ROOTDIR] [--cwd=<directory>] [--logLevel=<silent|info|verbose>] [--envName] [-e, --extends=<layer-name>] [-p, --port] [--dotenv]

preview command ROOTDIR argument

The ROOTDIR argument specifies the working directory with a default value of '.' (current directory).

preview mode .env file loading

In preview mode, the .env file will be loaded into process.env for convenience. In production, environment variables must be set separately, for example with Node.js 20+ by running NODE_ENV=production node --env-file .env .output/server/index.mjs to start the server.

preview command options reference

The preview command accepts these options: --cwd=<directory> (specify working directory, takes precedence over ROOTDIR, default '.'), --logLevel=<silent|info|verbose> (specify build-time log level), --envName (the environment to use when resolving configuration overrides, default is 'production' when building and 'development' when running the dev server), -e or --extends=<layer-name> (extend from a Nuxt layer), -p or --port (port to listen on, use PORT environment variable to override), --dotenv (path to .env file to load, relative to the root directory).

nuxt test --watch option

The --watch option enables watch mode for the test command.

nuxt test sets NODE_ENV to test

The test command automatically sets process.env.NODE_ENV to 'test' if it is not already set.

nuxt test command syntax

The test command is invoked with: npx nuxt test [ROOTDIR] [--cwd=<directory>] [--logLevel=<silent|info|verbose>] [--dev] [--watch]. The command runs tests using @nuxt/test-utils and sets process.env.NODE_ENV to 'test' if not already set.

nuxt test ROOTDIR argument

The ROOTDIR argument specifies the working directory for the test command. Its default value is '.' (current directory).

nuxt test --dev option

The --dev option runs the test command in dev mode.

nuxt typecheck sets NODE_ENV to production by default

The typecheck command sets process.env.NODE_ENV to 'production'. To override this, define NODE_ENV in a .env file or as a command-line argument.

nuxt typecheck command syntax

The typecheck command runs vue-tsc to check types throughout your app. The command syntax is: npx nuxt typecheck [ROOTDIR] [--cwd=<directory>] [--logLevel=<silent|info|verbose>] [--dotenv] [-e, --extends=<layer-name>]

nuxt typecheck ROOTDIR argument

The ROOTDIR argument specifies the working directory for the typecheck command, with a default value of '.'

nuxt typecheck --logLevel option

The --logLevel=<silent|info|verbose> option specifies the build-time log level for the typecheck command.

nuxt typecheck --dotenv option

The --dotenv option accepts a path to a .env file to load, specified relative to the root directory.

nuxt typecheck --extends option

The -e, --extends=<layer-name> option extends configuration from a Nuxt layer.

nuxt upgrade ROOTDIR argument

The ROOTDIR argument specifies the working directory for the upgrade command, with a default value of '.'

nuxt upgrade command syntax

The nuxt upgrade command syntax is: npx nuxt upgrade [ROOTDIR] [--cwd=<directory>] [--logLevel=<silent|info|verbose>] [--dedupe] [-f, --force] [-ch, --channel=<stable|nightly|v3|v4|v4-nightly|v3-nightly>]

nuxt upgrade --dedupe option

The --dedupe option dedupes dependencies after upgrading Nuxt

nuxt upgrade --force option

The -f or --force option forces the upgrade to recreate the lockfile and node_modules

nuxt upgrade --channel option

The -ch or --channel=<stable|nightly|v3|v4|v4-nightly|v3-nightly> option specifies which channel to install from, with a default value of 'stable'

nuxt upgrade --logLevel option

The --logLevel=<silent|info|verbose> option specifies the build-time log level for the upgrade command

nuxt upgrade --cwd option

The --cwd=<directory> option specifies the working directory and takes precedence over ROOTDIR, with a default value of '.'

addPluginTemplate dynamic code generation example

import { addPluginTemplate, defineNuxtModule } from '@nuxt/kit' export default defineNuxtModule({ setup (_, nuxt) { if (nuxt.options.vue.config && Object.values(nuxt.options.vue.config).some(v => v !== null && v !== undefined)) { addPluginTemplate({ filename: 'vue-app-config.mjs', write: true, getContents: () => `import { defineNuxtPlugin } from '#app/nuxt' export default defineNuxtPlugin({ name: 'nuxt:vue-app-config', enforce: 'pre', setup (nuxtApp) { ${Object.keys(nuxt.options.vue.config!) .map(k => `nuxtApp.vueApp.config[${JSON.stringify(k)}] = ${JSON.stringify(nuxt.options.vue.config![k as 'idPrefix'])}`) .join('\n') } } })`, }) } }, }) This example shows how to generate different plugin code depending on configuration, such as generating a plugin that sets Vue app configuration options at build time.

addPluginTemplate usage example

import { addPluginTemplate, defineNuxtModule } from '@nuxt/kit' export default defineNuxtModule({ setup (options) { addPluginTemplate({ filename: 'module-plugin.mjs', getContents: () => `import { defineNuxtPlugin } from '#app/nuxt' export default defineNuxtPlugin({ name: 'module-plugin', setup (nuxtApp) { ${options.log ? 'console.log("Plugin install")' : ''} } })`, }) }, })

addPluginTemplate options parameter

addPluginTemplate accepts an optional second parameter options with property append (boolean, optional, defaults to false) - if true, the plugin will be appended to the plugins array; if false, it will be prepended.

addPlugin usage example

import { addPlugin, createResolver, defineNuxtModule } from '@nuxt/kit' export default defineNuxtModule({ setup () { const { resolve } = createResolver(import.meta.url) addPlugin({ src: resolve('runtime/plugin.js'), mode: 'client', }) }, })

addPluginTemplate function signature

addPluginTemplate is a function with signature: function addPluginTemplate (pluginOptions: NuxtPluginTemplate, options?: AddPluginOptions): NuxtPlugin. It adds a template and registers it as a Nuxt plugin, useful for plugins that need to generate code at build time.

addPlugin function signature

addPlugin is a function with signature: function addPlugin (plugin: NuxtPlugin | string, options?: AddPluginOptions): NuxtPlugin. It registers a Nuxt plugin and adds it to the plugins array.

addPlugin plugin parameter - object properties

When addPlugin receives a plugin object, it must have these properties: src (string, required) - path to the plugin file; mode ('all' | 'server' | 'client', optional) - controls which bundle includes the plugin (all for both bundles, server for server bundle only, client for client bundle only, or use .client and .server modifiers on src); order (number, optional) - controls plugin execution order with lower numbers running first, user plugins default to 0, recommended range is -20 for pre-plugins to 20 for post-plugins.

addPlugin plugin parameter - string input

When addPlugin receives a string parameter, it represents the path to the plugin file and will be converted to a plugin object with src set to the string value.

addPluginTemplate pluginOptions parameter properties

addPluginTemplate pluginOptions parameter has these properties: src (string, optional) - path to the template, required if getContents is not provided; filename (string, optional) - filename of the template, required if src is not provided, generated from src path if not provided; dst (string, optional) - path to destination file, generated from filename and nuxt buildDir if not provided; mode ('all' | 'server' | 'client', optional) - controls which bundle includes the plugin; options (Record<string, any>, optional) - options to pass to the template; getContents (function, optional) - function called with options object, should return string or Promise<string>, ignored if src is provided; write (boolean, optional) - if true, template is written to destination file, otherwise used only in virtual filesystem; order (number, optional) - controls plugin execution order with lower numbers running first, user plugins default to 0, recommended range is -20 for pre-plugins to 20 for post-plugins.

addPluginTemplate best practice

Prefer using getContents for dynamic plugin generation rather than setting the order option unless necessary.

Plugin order recommendation

Avoid using the order option unless necessary. Use append if you simply need to register plugins after Nuxt defaults. For advanced control, order values should be between -20 for pre-plugins (plugins that run before Nuxt plugins) and 20 for post-plugins (plugins that run after Nuxt plugins).

Give your agent this brain