@nuxt/schema
Version:
1,445 lines • 107 kB
text/typescript
import { Defu } from "defu";
import { TSConfig } from "pkg-types";
import { InputObject, Schema, SchemaDefinition, SchemaDefinition as SchemaDefinition$1 } from "untyped";
import { IncomingMessage, Server, ServerResponse } from "node:http";
import { AssetURLTagConfig } from "@vue/compiler-sfc";
import { CompilerOptions } from "@vue/compiler-core";
import { AriaAttributes, DataKeys, GlobalAttributes, RenderSSRHeadOptions, SerializableHead } from "@unhead/vue/types";
import { BundleAnalyzerPlugin } from "webpack-bundle-analyzer";
import { PluginVisualizerOptions } from "rollup-plugin-visualizer";
import { TransformerOptions } from "unctx/transform";
import { ConfigLayerMeta, DefineConfig, DotenvOptions, ResolvedConfig, SourceOptions, UserInputConfig } from "c12";
import { CompatibilityDateSpec } from "compatx";
import { Ignore, Options } from "ignore";
import { ChokidarOptions } from "chokidar";
import { CorsOptions, H3CorsOptions } from "h3";
import { NuxtLinkOptions } from "nuxt/app";
import { FetchOptions } from "ofetch";
import { Options as Options$1 } from "autoprefixer";
import { Options as Options$2 } from "cssnano";
import { RawVueCompilerOptions } from "@vue/language-core";
import { PluginOptions } from "mini-css-extract-plugin";
import { LoaderOptions } from "esbuild-loader";
import { Options as Options$3 } from "pug";
import { VueLoaderOptions } from "vue-loader";
import { BasePluginOptions, DefinedDefaultMinimizerAndOptions } from "css-minimizer-webpack-plugin";
import { Compiler, Configuration, Stats, WebpackError } from "webpack";
import { ProcessOptions } from "postcss";
import { Options as Options$4 } from "webpack-dev-middleware";
import { ClientOptions, MiddlewareOptions } from "webpack-hot-middleware";
import { AppConfig as AppConfig$1, KeepAliveProps, TransitionProps } from "vue";
import { TransformOptions } from "oxc-transform";
import { TransformOptions as TransformOptions$1 } from "esbuild";
import { RouteLocationNormalizedGeneric, RouteLocationRaw, RouteRecordRaw, RouterHistory, RouterOptions as RouterOptions$1 } from "vue-router";
import { Server as Server$1 } from "node:https";
import { ServerOptions, UserConfig, ViteDevServer } from "vite";
import { Manifest } from "vue-bundle-renderer";
import { Import, InlinePreset, Preset, Unimport, UnimportOptions } from "unimport";
import { Options as Options$5 } from "@vitejs/plugin-vue";
import { Options as Options$6 } from "@vitejs/plugin-vue-jsx";
import { SnakeCase } from "scule";
import { AsyncLocalStorage } from "node:async_hooks";
import { Hookable } from "hookable";
interface NuxtCompatibility {
/**
* Required nuxt version in semver format.
* @example `^3.2.0` or `>=3.13.0`.
*/
nuxt?: string;
/**
* Mark a builder as incompatible, or require a particular version.
*
* @example
* ```ts
* export default defineNuxtModule({
* meta: {
* name: 'my-module',
* compatibility: {
* builder: {
* // marking as incompatible
* webpack: false,
* // you can require a (semver-compatible) version
* vite: '^5'
* }
* }
* }
* // ...
* })
* ```
*/
builder?: Partial<Record<"vite" | "webpack" | "rspack" | (string & {}), false | string>>;
}
interface NuxtCompatibilityIssue {
name: string;
message: string;
}
interface NuxtCompatibilityIssues extends Array<NuxtCompatibilityIssue> {
/**
* Return formatted error message.
*/
toString(): string;
}
type RouterOptions = Partial<Omit<RouterOptions$1, "history" | "routes">> & {
history?: (baseURL?: string) => RouterHistory | null | undefined;
routes?: (_routes: RouterOptions$1["routes"]) => RouterOptions$1["routes"] | Promise<RouterOptions$1["routes"]>;
hashMode?: boolean;
scrollBehaviorType?: "smooth" | "auto";
};
type RouterConfig = RouterOptions;
/**
* Only JSON serializable router options are configurable from nuxt config
*/
type RouterConfigSerializable = Pick<RouterConfig, "linkActiveClass" | "linkExactActiveClass" | "end" | "sensitive" | "strict" | "hashMode" | "scrollBehaviorType">;
interface ModuleMeta {
/** Module name. */
name?: string;
/** Module version. */
version?: string;
/**
* The configuration key used within `nuxt.config` for this module's options.
* For example, `@nuxtjs/axios` uses `axios`.
*/
configKey?: string;
/**
* Constraints for the versions of Nuxt or features this module requires.
*/
compatibility?: NuxtCompatibility;
/**
* Fully resolved path used internally by Nuxt. Do not depend on this value.
* @internal
*/
rawPath?: string;
/**
* Whether the module has been disabled in the Nuxt configuration.
* @internal
*/
disabled?: boolean;
[key: string]: unknown;
}
/** The options received. */
type ModuleOptions = Record<string, any>;
type ModuleSetupInstallResult = {
/**
* Timing information for the initial setup
*/
timings?: {
/** Total time took for module setup in ms */setup?: number;
[key: string]: number | undefined;
};
};
type Awaitable<T> = T | Promise<T>;
type Prettify<T> = { [K in keyof T]: T[K] } & {};
type ModuleSetupReturn = Awaitable<false | void | ModuleSetupInstallResult>;
type ResolvedModuleOptions<TOptions extends ModuleOptions, TOptionsDefaults extends Partial<TOptions>> = Prettify<Defu<Partial<TOptions>, [Partial<TOptions>, TOptionsDefaults]>>;
interface ModuleDependencyMeta<T = Record<string, unknown>> {
version?: string;
overrides?: Partial<T>;
defaults?: Partial<T>;
optional?: boolean;
}
interface ModuleDependencies {
[key: string]: ModuleDependencyMeta<Record<string, unknown>>;
}
/** Module definition passed to 'defineNuxtModule(...)' or 'defineNuxtModule().with(...)'. */
interface ModuleDefinition<TOptions extends ModuleOptions, TOptionsDefaults extends Partial<TOptions>, TWith extends boolean> {
meta?: ModuleMeta;
defaults?: TOptionsDefaults | ((nuxt: Nuxt) => Awaitable<TOptionsDefaults>);
schema?: TOptions;
hooks?: Partial<NuxtHooks>;
moduleDependencies?: ModuleDependencies | ((nuxt: Nuxt) => Awaitable<ModuleDependencies>);
onInstall?: (nuxt: Nuxt) => Awaitable<void>;
onUpgrade?: (nuxt: Nuxt, options: TOptions, previousVersion: string) => Awaitable<void>;
setup?: (this: void, resolvedOptions: TWith extends true ? ResolvedModuleOptions<TOptions, TOptionsDefaults> : TOptions, nuxt: Nuxt) => ModuleSetupReturn;
}
interface NuxtModule<TOptions extends ModuleOptions = ModuleOptions, TOptionsDefaults extends Partial<TOptions> = Partial<TOptions>, TWith extends boolean = false> {
(this: void, resolvedOptions: TWith extends true ? ResolvedModuleOptions<TOptions, TOptionsDefaults> : TOptions, nuxt: Nuxt): ModuleSetupReturn;
getOptions?: (inlineOptions?: Partial<TOptions>, nuxt?: Nuxt) => Promise<TWith extends true ? ResolvedModuleOptions<TOptions, TOptionsDefaults> : TOptions>;
getModuleDependencies?: (nuxt: Nuxt) => Awaitable<ModuleDependencies> | undefined;
getMeta?: () => Promise<ModuleMeta>;
onInstall?: (nuxt: Nuxt) => Awaitable<void>;
onUpgrade?: (nuxt: Nuxt, options: TWith extends true ? ResolvedModuleOptions<TOptions, TOptionsDefaults> : TOptions, previousVersion: string) => Awaitable<void>;
}
interface NuxtDebugContext {
/**
* Module mutation records to the `nuxt` instance.
*/
moduleMutationRecords?: NuxtDebugModuleMutationRecord[];
}
interface NuxtDebugModuleMutationRecord {
module: NuxtModule;
keys: (string | symbol)[];
target: "nuxt.options";
value: any;
method?: string;
timestamp: number;
}
interface NuxtDebugOptions {
/** Debug for Nuxt templates */
templates?: boolean;
/** Debug for modules setup timings */
modules?: boolean;
/** Debug for file watchers */
watchers?: boolean;
/** Debug for production hydration mismatch */
hydration?: boolean;
/** Debug for Vue Router */
router?: boolean;
/** Debug for hooks, can be set to `true` or an object with `server` and `client` keys */
hooks?: boolean | {
server?: boolean;
client?: boolean;
};
/**
* Profile startup/build performance.
*
* - `true` — full report printed to console, JSON + `.cpuprofile` written on exit
* - `'quiet'` — JSON + `.cpuprofile` written on exit with no console output
*
* Activated via `nuxi dev --profile=verbose`, `nuxi dev --profile` (quiet),
* `NUXT_DEBUG_PERF=1` (or `=quiet`), or `debug: { perf: true }` in nuxt.config.
* @since 4.4.0
*/
perf?: boolean | "quiet";
}
interface NuxtPlugin {
/** @deprecated use mode */
ssr?: boolean;
src: string;
mode?: "all" | "server" | "client";
/**
* This allows more granular control over plugin order and should only be used by advanced users.
* Lower numbers run first, and user plugins default to `0`.
*
* Default Nuxt priorities can be seen at [here](https://github.com/nuxt/nuxt/blob/9904849bc87c53dfbd3ea3528140a5684c63c8d8/packages/nuxt/src/core/plugins/plugin-metadata.ts#L15-L34).
*/
order?: number;
/**
* @internal
*/
name?: string;
}
type TemplateDefaultOptions = Record<string, any>;
interface NuxtTemplate<Options = TemplateDefaultOptions> {
/** resolved output file path (generated) */
dst?: string;
/** The target filename once the template is copied into the Nuxt buildDir */
filename?: string;
/** An options object that will be accessible within the template via `<% options %>` */
options?: Options;
/** The resolved path to the source file to be template */
src?: string;
/** Provided compile option instead of src */
getContents?: (data: {
nuxt: Nuxt;
app: NuxtApp;
options: Options;
}) => string | Promise<string>;
/** Write to filesystem */
write?: boolean;
/**
* The source path of the template (to try resolving dependencies from).
* @internal
*/
_path?: string;
}
interface NuxtServerTemplate {
/** The target filename once the template is copied into the Nuxt buildDir */
filename: string;
getContents: () => string | Promise<string>;
}
interface ResolvedNuxtTemplate<Options = TemplateDefaultOptions> extends NuxtTemplate<Options> {
filename: string;
dst: string;
modified?: boolean;
}
interface NuxtTypeTemplate<Options = TemplateDefaultOptions> extends Omit<NuxtTemplate<Options>, "write" | "filename"> {
filename: `${string}.d.ts`;
write?: true;
}
type _TemplatePlugin<Options> = Omit<NuxtPlugin, "src"> & NuxtTemplate<Options>;
interface NuxtPluginTemplate<Options = TemplateDefaultOptions> extends _TemplatePlugin<Options> {}
interface NuxtApp {
mainComponent?: string | null;
rootComponent?: string | null;
errorComponent?: string | null;
dir: string;
extensions: string[];
plugins: NuxtPlugin[];
components: Component[];
layouts: Record<string, NuxtLayout>;
middleware: NuxtMiddleware[];
templates: NuxtTemplate[];
configs: string[];
pages?: NuxtPage[];
}
interface Nuxt {
"__name": string;
"_version": string;
"_ignore"?: Ignore;
"_dependencies"?: Set<string>;
"~runtimeDependencies"?: string[];
"_debug"?: NuxtDebugContext;
/**
* Performance profiler instance, available when `debug.perf` is enabled.
* @internal
*/
"_perf"?: {
startPhase: (name: string) => void;
endPhase: (name?: string) => void;
collectModuleTimings: (modules: Array<{
meta?: {
name?: string;
};
timings?: Record<string, number | undefined>;
}>) => void;
recordBundlerPluginHook: (pluginName: string, hookName: string, durationMs: number, startTime?: number) => void;
printReport: (options?: {
title?: string;
}) => void;
writeReport: (buildDir: string, options?: {
quiet?: boolean;
}) => string;
dispose: () => void;
};
/** Async local storage for current running Nuxt module instance. */
"_asyncLocalStorageModule"?: AsyncLocalStorage<NuxtModule>;
/**
* Module options functions collected from moduleDependencies.
* @internal
*/
"_moduleOptionsFunctions"?: Map<string | NuxtModule, Array<() => {
defaults?: Record<string, unknown>;
overrides?: Record<string, unknown>;
}>>;
/** The resolved Nuxt configuration. */
"options": NuxtOptions;
"hooks": Hookable<NuxtHooks>;
"hook": Nuxt["hooks"]["hook"];
"callHook": Nuxt["hooks"]["callHook"];
"addHooks": Nuxt["hooks"]["addHooks"];
"runWithContext": <T extends (...args: any[]) => any>(fn: T) => ReturnType<T>;
"ready": () => Promise<void>;
"close": () => Promise<void>;
/** The production or development server. */
"server"?: any;
"vfs": Record<string, string>;
"apps": Record<string, NuxtApp>;
}
type MetaObjectRaw = SerializableHead;
type MetaObject = MetaObjectRaw;
type AppHeadMetaObject = MetaObjectRaw & {
/**
* The character encoding in which the document is encoded => `<meta charset="<value>" />`
*/
charset?: string;
/**
* Configuration of the viewport (the area of the window in which web content can be seen),
* mapped to => `<meta name="viewport" content="<value>" />`
*/
viewport?: string;
};
type SerializableHtmlAttributes = GlobalAttributes & AriaAttributes & DataKeys;
type DeepPartial<T> = T extends Function ? T : T extends Record<string, any> ? { [P in keyof T]?: DeepPartial<T[P]> } : T;
type UpperSnakeCase<S extends string> = Uppercase<SnakeCase<S>>;
declare const message: symbol;
type RuntimeValue<T, B extends string> = T & {
[message]?: B;
} | T;
type Overrideable<T extends Record<string, any>, Path extends string = ""> = { [K in keyof T]?: K extends string ? unknown extends T[K] ? unknown : T[K] extends Record<string, unknown> ? RuntimeValue<Overrideable<T[K], `${Path}_${UpperSnakeCase<K>}`>, `You can override this value at runtime with NUXT${Path}_${UpperSnakeCase<K>}`> : RuntimeValue<T[K], `You can override this value at runtime with NUXT${Path}_${UpperSnakeCase<K>}`> : K extends number ? T[K] : never };
type RuntimeConfigNamespace = Record<string, unknown>;
interface PublicRuntimeConfig extends RuntimeConfigNamespace {}
interface RuntimeConfig extends RuntimeConfigNamespace {
public: PublicRuntimeConfig;
}
/**
* User configuration in `nuxt.config` file
*/
interface NuxtConfig extends DeepPartial<Omit<ConfigSchema, "components" | "vue" | "vite" | "runtimeConfig" | "webpack" | "nitro">> {
components?: ConfigSchema["components"];
vue?: Omit<DeepPartial<ConfigSchema["vue"]>, "config"> & {
config?: Partial<Filter<AppConfig$1, string | boolean>>;
};
vite?: ConfigSchema["vite"];
runtimeConfig?: Overrideable<RuntimeConfig>;
webpack?: DeepPartial<ConfigSchema["webpack"]> & {
$client?: DeepPartial<ConfigSchema["webpack"]>;
$server?: DeepPartial<ConfigSchema["webpack"]>;
};
/**
* Experimental custom config schema
* @see [Nuxt Issue #15592](https://github.com/nuxt/nuxt/issues/15592)
*/
$schema?: SchemaDefinition$1;
}
type NuxtConfigLayer = ResolvedConfig<NuxtConfig & {
srcDir: ConfigSchema["srcDir"];
rootDir: ConfigSchema["rootDir"];
}> & {
cwd: string;
configFile: string;
};
interface DefineNuxtConfig<Config extends UserInputConfig = NuxtConfig> extends DefineConfig<Config, ConfigLayerMeta> {}
interface NuxtBuilder {
bundle: (nuxt: Nuxt) => Promise<void>;
}
interface NuxtOptions extends Omit<ConfigSchema, "vue" | "sourcemap" | "debug" | "builder" | "postcss" | "webpack"> {
vue: Omit<ConfigSchema["vue"], "config"> & {
config?: Partial<Filter<AppConfig$1, string | boolean>>;
};
sourcemap: Required<Exclude<ConfigSchema["sourcemap"], boolean>>;
debug: Required<Exclude<ConfigSchema["debug"], true>>;
builder: "@nuxt/vite-builder" | "@nuxt/webpack-builder" | "@nuxt/rspack-builder" | NuxtBuilder;
postcss: Omit<ConfigSchema["postcss"], "order"> & {
order: Exclude<ConfigSchema["postcss"]["order"], string>;
};
webpack: ConfigSchema["webpack"] & {
$client: ConfigSchema["webpack"];
$server: ConfigSchema["webpack"];
};
_layers: readonly NuxtConfigLayer[];
$schema: SchemaDefinition$1;
}
interface ViteConfig extends Omit<UserConfig, "publicDir"> {
/** The path to the entrypoint for the Vite build. */
entry?: string;
/**
* Options passed to @vitejs/plugin-vue.
* @see [@vitejs/plugin-vue](https://github.com/vitejs/vite-plugin-vue/tree/main/packages/plugin-vue)
*/
vue?: Options$5;
/**
* Options passed to @vitejs/plugin-vue-jsx.
* @see [@vitejs/plugin-vue-jsx.](https://github.com/vitejs/vite-plugin-vue/tree/main/packages/plugin-vue-jsx)
*/
vueJsx?: Options$6;
/**
* Warmup vite entrypoint caches on dev startup.
*/
warmupEntry?: boolean;
/**
* Use environment variables or top level `server` options to configure Nuxt server.
*/
server?: Omit<ServerOptions, "port" | "host">;
/**
* Directly configuring the `vite.publicDir` option is not supported. Instead, set `dir.public`.
*
* You can read more in <https://nuxt.com/docs/4.x/api/nuxt-config#public>.
* @deprecated
*/
publicDir?: never;
}
interface ViteOptions extends ViteConfig {}
interface CustomAppConfig {
[key: string]: unknown;
}
interface AppConfigInput extends CustomAppConfig {
/** @deprecated reserved */
private?: never;
/** @deprecated reserved */
nuxt?: never;
/** @deprecated reserved */
nitro?: never;
/** @deprecated reserved */
server?: never;
}
type Serializable<T> = T extends Function ? never : T extends Promise<infer U> ? Serializable<U> : T extends string & {} ? T : T extends Record<string, any> ? { [K in keyof T]: Serializable<T[K]> } : T;
type ValueOf<T> = T[keyof T];
type Filter<T extends Record<string, any>, V> = Pick<T, ValueOf<{ [K in keyof T]: NonNullable<T[K]> extends V ? K : never }>>;
interface NuxtAppConfig {
head: Serializable<AppHeadMetaObject>;
layoutTransition: boolean | Serializable<TransitionProps>;
pageTransition: boolean | Serializable<TransitionProps>;
viewTransition?: ViewTransitionOptions["enabled"] | ViewTransitionOptions;
keepalive: boolean | Serializable<KeepAliveProps>;
}
interface AppConfig {
[key: string]: unknown;
}
interface ViewTransitionOptions {
enabled: boolean | "always";
types?: string[];
}
type ViewTransitionTypesFn = (to: RouteLocationNormalizedGeneric, from: RouteLocationNormalizedGeneric) => string[];
interface ViewTransitionPageOptions {
enabled?: boolean | "always";
types?: string[] | ViewTransitionTypesFn;
toTypes?: string[] | ViewTransitionTypesFn;
fromTypes?: string[] | ViewTransitionTypesFn;
}
type HookResult = Promise<void> | void;
type TSReference = {
types: string;
} | {
path: string;
};
type WatchEvent = "add" | "addDir" | "change" | "unlink" | "unlinkDir";
type VueTSConfig = 0 extends 1 & RawVueCompilerOptions ? TSConfig : TSConfig & {
vueCompilerOptions?: RawVueCompilerOptions;
};
interface NuxtPage {
name?: string;
path: string;
props?: RouteRecordRaw["props"];
file?: string;
meta?: Record<string, any>;
alias?: string[] | string;
redirect?: RouteLocationRaw;
children?: NuxtPage[];
middleware?: string[] | string;
/**
* Set the render mode.
*
* `all` means the page will be rendered isomorphically - with JavaScript both on client and server.
*
* `server` means pages are automatically rendered with server components, so there will be no JavaScript to render the page in your client bundle.
*
* `client` means that page will render on the client-side only.
*/
mode?: "client" | "server" | "all";
/** @internal */
_sync?: boolean;
}
type NuxtMiddleware = {
name: string;
path: string;
global?: boolean;
};
type NuxtLayout = {
name: string;
file: string;
};
/**
* @deprecated Use {@link InlinePreset}
*/
interface ImportPresetWithDeprecation extends InlinePreset {}
interface GenerateAppOptions {
filter?: (template: ResolvedNuxtTemplate<any>) => boolean;
}
interface NuxtAnalyzeMeta {
name: string;
slug: string;
startTime: number;
endTime: number;
analyzeDir: string;
buildDir: string;
outDir: string;
}
/**
* The listeners to Nuxt build time events
*/
interface NuxtHooks {
/**
* Allows extending compatibility checks.
* @param compatibility Compatibility object
* @param issues Issues to be mapped
* @returns Promise
*/
"kit:compatibility": (compatibility: NuxtCompatibility, issues: NuxtCompatibilityIssues) => HookResult;
/**
* Called after Nuxt initialization, when the Nuxt instance is ready to work.
* @param nuxt The configured Nuxt object
* @returns Promise
*/
"ready": (nuxt: Nuxt) => HookResult;
/**
* Called when Nuxt instance is gracefully closing.
* @param nuxt The configured Nuxt object
* @returns Promise
*/
"close": (nuxt: Nuxt) => HookResult;
/**
* Called to restart the current Nuxt instance.
* @returns Promise
*/
"restart": (options?: {
/**
* Try to restart the whole process if supported
*/
hard?: boolean;
}) => HookResult;
/**
* Called during Nuxt initialization, before installing user modules.
* @returns Promise
*/
"modules:before": () => HookResult;
/**
* Called during Nuxt initialization, after installing user modules.
* @returns Promise
*/
"modules:done": () => HookResult;
/**
* Called after resolving the `app` instance.
* @param app The resolved `NuxtApp` object
* @returns Promise
*/
"app:resolve": (app: NuxtApp) => HookResult;
/**
* Called during `NuxtApp` generation, to allow customizing, modifying or adding new files to the build directory (either virtually or to written to `.nuxt`).
* @param app The configured `NuxtApp` object
* @returns Promise
*/
"app:templates": (app: NuxtApp) => HookResult;
/**
* Called after templates are compiled into the [virtual file system](https://nuxt.com/docs/4.x/directory-structure/nuxt) (vfs).
* @param app The configured `NuxtApp` object
* @returns Promise
*/
"app:templatesGenerated": (app: NuxtApp, templates: ResolvedNuxtTemplate[], options?: GenerateAppOptions) => HookResult;
/**
* Called before Nuxt bundle builder.
* @returns Promise
*/
"build:before": () => HookResult;
/**
* Called after Nuxt bundle builder is complete.
* @returns Promise
*/
"build:done": () => HookResult;
/**
* Called during the manifest build by Vite and Webpack. This allows customizing the manifest that Nitro will use to render `<script>` and `<link>` tags in the final HTML.
* @param manifest The manifest object to build
* @returns Promise
*/
"build:manifest": (manifest: Manifest) => HookResult;
/**
* Called when `nuxt analyze` is finished
* @param meta the analyze meta object, mutations will be saved to `meta.json`
* @returns Promise
*/
"build:analyze:done": (meta: NuxtAnalyzeMeta) => HookResult;
/**
* Called before generating the app.
* @param options GenerateAppOptions object
* @returns Promise
*/
"builder:generateApp": (options?: GenerateAppOptions) => HookResult;
/**
* Called at build time in development when the watcher spots a change to a file or directory in the project.
* @param event "add" | "addDir" | "change" | "unlink" | "unlinkDir"
* @param path the path to the watched file
* @returns Promise
*/
"builder:watch": (event: WatchEvent, path: string) => HookResult;
/**
* Called after page routes are scanned from the file system.
* @param pages Array containing scanned pages
* @returns Promise
*/
"pages:extend": (pages: NuxtPage[]) => HookResult;
/**
* Called after page routes have been augmented with scanned metadata.
* @param pages Array containing resolved pages
* @returns Promise
*/
"pages:resolved": (pages: NuxtPage[]) => HookResult;
/**
* Called when resolving `app/router.options` files. It allows modifying the detected router options files
* and adding new ones.
*
* Later items in the array override earlier ones.
*
* Adding a router options file will switch on page-based routing, unless `optional` is set, in which case
* it will only apply when page-based routing is already enabled.
* @param context An object with `files` containing an array of router options files.
* @param context.files Array of router options files
* @returns Promise
*/
"pages:routerOptions": (context: {
files: Array<{
path: string;
optional?: boolean;
}>;
}) => HookResult;
/**
* Called at setup allowing modules to extend sources.
* @param presets Array containing presets objects
* @returns Promise
*/
"imports:sources": (presets: Preset[]) => HookResult;
/**
* Called at setup allowing modules to extend imports.
* @param imports Array containing the imports to extend
* @returns Promise
*/
"imports:extend": (imports: Import[]) => HookResult;
/**
* Called when the [unimport](https://github.com/unjs/unimport) context is created.
* @param context The Unimport context
* @returns Promise
*/
"imports:context": (context: Unimport) => HookResult;
/**
* Allows extending import directories.
* @param dirs Array containing directories as string
* @returns Promise
*/
"imports:dirs": (dirs: string[]) => HookResult;
/**
* Called within `app:resolve` allowing to extend the directories that are scanned for auto-importable components.
* @param dirs The `dirs` option to push new items
* @returns Promise
*/
"components:dirs": (dirs: ComponentsOptions["dirs"]) => HookResult;
/**
* Allows extending new components.
* @param components The `components` array to push new items
* @returns Promise
*/
"components:extend": (components: Component[]) => HookResult;
/**
* Allows extending the routes to be pre-rendered.
* @param ctx Nuxt context
* @param ctx.routes Set of routes to be pre-rendered
* @returns Promise
*/
"prerender:routes": (ctx: {
routes: Set<string>;
}) => HookResult;
/**
* Called when an error occurs at build time.
* @param error Error object
* @returns Promise
*/
"build:error": (error: Error) => HookResult;
/**
* Called before @nuxt/cli writes `.nuxt/tsconfig.json` and `.nuxt/nuxt.d.ts`, allowing addition of custom references and declarations in `nuxt.d.ts`, or directly modifying the options in `tsconfig.json`
* @param options Objects containing `references`, `declarations`, `tsConfig`
* @param options.references Array of TypeScript references to add
* @param options.declarations Array of declaration strings to add
* @param options.tsConfig The Vue TypeScript config object
* @param options.nodeTsConfig The Node TypeScript config object
* @param options.nodeReferences Array of Node TypeScript references
* @param options.sharedTsConfig The shared TypeScript config object
* @param options.sharedReferences Array of shared TypeScript references
* @returns Promise
*/
"prepare:types": (options: {
references: TSReference[];
declarations: string[];
tsConfig: VueTSConfig;
nodeTsConfig: TSConfig;
nodeReferences: TSReference[];
sharedTsConfig: TSConfig;
sharedReferences: TSReference[];
}) => HookResult;
/**
* Called when the dev server is loading.
* @param listenerServer The HTTP/HTTPS server object
* @param listener The server's listener object
* @returns Promise
*/
"listen": (listenerServer: Server | Server$1, listener: any) => HookResult;
/**
* Allows extending default schemas.
* @param schemas Schemas to be extend
* @returns void
*/
"schema:extend": (schemas: SchemaDefinition$1[]) => void;
/**
* Allows extending resolved schema.
* @param schema Schema object
* @returns void
*/
"schema:resolved": (schema: Schema) => void;
/**
* Called before writing the given schema.
* @param schema Schema object
* @returns void
*/
"schema:beforeWrite": (schema: Schema) => void;
/**
* Called after the schema is written.
* @returns void
*/
"schema:written": () => void;
/**
* Allows to extend Vite default context.
* @param viteBuildContext The vite build context object
* @param viteBuildContext.nuxt The Nuxt instance
* @param viteBuildContext.config The Vite config object
* @returns Promise
*/
"vite:extend": (viteBuildContext: {
nuxt: Nuxt;
config: ViteConfig;
}) => HookResult;
/**
* Allows to extend Vite default config.
* @param viteInlineConfig The vite inline config object
* @param env Server or client
* @param env.isClient Whether the config is for the client build
* @param env.isServer Whether the config is for the server build
* @returns Promise
* @deprecated
*/
"vite:extendConfig": (viteInlineConfig: Readonly<ViteConfig>, env: {
isClient: boolean;
isServer: boolean;
}) => HookResult;
/**
* Allows to read the resolved Vite config.
* @param viteInlineConfig The vite inline config object
* @param env Server or client
* @param env.isClient Whether the config is for the client build
* @param env.isServer Whether the config is for the server build
* @returns Promise
* @deprecated
*/
"vite:configResolved": (viteInlineConfig: Readonly<ViteConfig>, env: {
isClient: boolean;
isServer: boolean;
}) => HookResult;
/**
* Called when the Vite server is created.
* @param viteServer Vite development server
* @param env Server or client
* @param env.isClient Whether the server is for the client build
* @param env.isServer Whether the server is for the server build
* @returns Promise
*/
"vite:serverCreated": (viteServer: ViteDevServer, env: {
isClient: boolean;
isServer: boolean;
}) => HookResult;
/**
* Called after Vite server is compiled.
* @returns Promise
*/
"vite:compiled": () => HookResult;
/**
* Called before configuring the webpack compiler.
* @param webpackConfigs Configs objects to be pushed to the compiler
* @returns Promise
*/
"webpack:config": (webpackConfigs: Configuration[]) => HookResult;
/**
* Allows to read the resolved webpack config
* @param webpackConfigs Configs objects to be pushed to the compiler
* @returns Promise
*/
"webpack:configResolved": (webpackConfigs: Readonly<Configuration>[]) => HookResult;
/**
* Called right before compilation.
* @param options The options to be added
* @param options.name The name of the compiler
* @param options.compiler The webpack compiler instance
* @returns Promise
*/
"webpack:compile": (options: {
name: string;
compiler: Compiler;
}) => HookResult;
/**
* Called after resources are loaded.
* @param options The compiler options
* @param options.name The name of the compiler
* @param options.compiler The webpack compiler instance
* @param options.stats The webpack compilation stats
* @returns Promise
*/
"webpack:compiled": (options: {
name: string;
compiler: Compiler;
stats: Stats;
}) => HookResult;
/**
* Called on `change` on WebpackBar.
* @param shortPath the short path
* @returns void
*/
"webpack:change": (shortPath: string) => void;
/**
* Called on `done` if has errors on WebpackBar.
* @returns void
*/
"webpack:error": () => void;
/**
* Called on `allDone` on WebpackBar.
* @returns void
*/
"webpack:done": () => void;
/**
* Called on `progress` on WebpackBar.
* @param statesArray The array containing the states on progress
* @returns void
*/
"webpack:progress": (statesArray: any[]) => void;
/**
* Called before configuring the webpack compiler.
* @param webpackConfigs Configs objects to be pushed to the compiler
* @returns Promise
*/
"rspack:config": (webpackConfigs: Configuration[]) => HookResult;
/**
* Allows to read the resolved webpack config
* @param webpackConfigs Configs objects to be pushed to the compiler
* @returns Promise
*/
"rspack:configResolved": (webpackConfigs: Readonly<Configuration>[]) => HookResult;
/**
* Called right before compilation.
* @param options The options to be added
* @param options.name The name of the compiler
* @param options.compiler The rspack compiler instance
* @returns Promise
*/
"rspack:compile": (options: {
name: string;
compiler: Compiler;
}) => HookResult;
/**
* Called after resources are loaded.
* @param options The compiler options
* @param options.name The name of the compiler
* @param options.compiler The rspack compiler instance
* @param options.stats The rspack compilation stats
* @returns Promise
*/
"rspack:compiled": (options: {
name: string;
compiler: Compiler;
stats: Stats;
}) => HookResult;
/**
* Called on `change` on WebpackBar.
* @param shortPath the short path
* @returns void
*/
"rspack:change": (shortPath: string) => void;
/**
* Called on `done` if has errors on WebpackBar.
* @returns void
*/
"rspack:error": () => void;
/**
* Called on `allDone` on WebpackBar.
* @returns void
*/
"rspack:done": () => void;
/**
* Called on `progress` on WebpackBar.
* @param statesArray The array containing the states on progress
* @returns void
*/
"rspack:progress": (statesArray: any[]) => void;
}
type NuxtHookName = keyof NuxtHooks;
interface ImportsOptions extends UnimportOptions {
/**
* Enable implicit auto import from Vue, Nuxt and module contributed utilities.
* Generate global TypeScript definitions.
*/
autoImport?: boolean;
/**
* Directories to scan for auto imports.
* @see https://nuxt.com/docs/4.x/directory-structure/app/composables#how-files-are-scanned
*/
dirs?: string[];
/**
* Enabled scan for local directories for auto imports.
* When this is disabled, `dirs` options will be ignored.
*/
scan?: boolean;
/**
* Assign auto imported utilities to `globalThis` instead of using built time transformation.
*/
global?: boolean;
transform?: {
exclude?: RegExp[];
include?: RegExp[];
};
/**
* Add polyfills for setInterval, requestIdleCallback, and others
*/
polyfills?: boolean;
}
interface ConfigSchema {
/**
* Configure Nuxt component auto-registration.
*
* Any components in the directories configured here can be used throughout your pages, layouts (and other components) without needing to explicitly import them.
*
* @see [`components/` directory documentation](https://nuxt.com/docs/4.x/directory-structure/app/components)
*/
components: boolean | ComponentsOptions | ComponentsOptions["dirs"];
/**
* Configure how Nuxt auto-imports composables into your application.
*
* @see [Nuxt documentation](https://nuxt.com/docs/4.x/directory-structure/app/composables)
*/
imports: ImportsOptions;
/**
* Configure the Nuxt compiler.
*/
compiler: NuxtCompilerOptions;
/**
* Whether to use the vue-router integration in Nuxt 3. If you do not provide a value it will be enabled if you have a `pages/` directory in your source folder.
*
* Additionally, you can provide a glob pattern or an array of patterns to scan only certain files for pages.
*
* @example
* ```js
* pages: {
* pattern: ['**\/*\/*.vue', '!**\/*.spec.*'],
* }
* ```
*/
pages: boolean | {
enabled?: boolean;
pattern?: string | string[];
};
/**
* Manually disable nuxt telemetry.
*
* @see [Nuxt Telemetry](https://github.com/nuxt/telemetry) for more information.
*/
telemetry: boolean | Record<string, any>;
/**
* Enable Nuxt DevTools for development.
*
* Breaking changes for devtools might not reflect on the version of Nuxt.
*
* @see [Nuxt DevTools](https://devtools.nuxt.com/) for more information.
*/
devtools: boolean | {
enabled: boolean;
[key: string]: any;
};
/**
* Vue.js config
*/
vue: {
transformAssetUrls: AssetURLTagConfig;
/**
* Options for the Vue compiler that will be passed at build time.
*
* @see [Vue documentation](https://vuejs.org/api/application#app-config-compileroptions)
*/
compilerOptions: CompilerOptions;
/**
* Include Vue compiler in runtime bundle.
*/
runtimeCompiler: boolean;
/**
* Enable reactive destructure for `defineProps`
*/
propsDestructure: boolean;
/**
* It is possible to pass configure the Vue app globally. Only serializable options may be set in your `nuxt.config`. All other options should be set at runtime in a Nuxt plugin.
*
* @see [Vue app config documentation](https://vuejs.org/api/application#app-config)
*/
config: Serializable<AppConfig$1>;
};
/**
* Nuxt App configuration.
*/
app: {
/**
* The base path of your Nuxt application.
*
* For example:
*
*
* @example
* ```ts
* export default defineNuxtConfig({
* app: {
* baseURL: '/prefix/'
* }
* })
* ```
*
* This can also be set at runtime by setting the NUXT_APP_BASE_URL environment variable.
*
* @example
* ```bash
* NUXT_APP_BASE_URL=/prefix/ NODE_ENV=production node .output/server/index.mjs
* ```
*/
baseURL: string;
/**
* The folder name for the built site assets, relative to `baseURL` (or `cdnURL` if set). This is set at build time and should not be customized at runtime.
*/
buildAssetsDir: string;
/**
* An absolute URL to serve the public folder from (production-only).
*
* For example:
*
* @example
* ```ts
* export default defineNuxtConfig({
* app: {
* cdnURL: 'https://mycdn.org/'
* }
* })
* ```
*
* This can be set to a different value at runtime by setting the `NUXT_APP_CDN_URL` environment variable.
*
* @example
* ```bash
* NUXT_APP_CDN_URL=https://mycdn.org/ NODE_ENV=production node .output/server/index.mjs
* ```
*/
cdnURL: string;
/**
* Set default configuration for `<head>` on every page.
*
* @example
* ```js
* app: {
* head: {
* meta: [
* // <meta name="viewport" content="width=device-width, initial-scale=1">
* { name: 'viewport', content: 'width=device-width, initial-scale=1' }
* ],
* script: [
* // <script src="https://myawesome-lib.js"><\/script>
* { src: 'https://awesome-lib.js' }
* ],
* link: [
* // <link rel="stylesheet" href="https://myawesome-lib.css">
* { rel: 'stylesheet', href: 'https://awesome-lib.css' }
* ],
* // please note that this is an area that is likely to change
* style: [
* // <style>:root { color: red }</style>
* { textContent: ':root { color: red }' }
* ],
* noscript: [
* // <noscript>JavaScript is required</noscript>
* { textContent: 'JavaScript is required' }
* ]
* }
* }
* ```
*/
head: NuxtAppConfig["head"];
/**
* Default values for layout transitions.
*
* This can be overridden with `definePageMeta` on an individual page. Only JSON-serializable values are allowed.
*
* @see [Vue Transition docs](https://vuejs.org/api/built-in-components#transition)
*/
layoutTransition: NuxtAppConfig["layoutTransition"];
/**
* Default values for page transitions.
*
* This can be overridden with `definePageMeta` on an individual page. Only JSON-serializable values are allowed.
*
* @see [Vue Transition docs](https://vuejs.org/api/built-in-components#transition)
*/
pageTransition: NuxtAppConfig["pageTransition"];
/**
* Default values for view transitions.
*
* This only has an effect when **experimental** support for View Transitions is [enabled in your nuxt.config file](https://nuxt.com/docs/4.x/getting-started/transitions#view-transitions-api-experimental).
* This can be overridden with `definePageMeta` on an individual page.
*
* @see [Nuxt View Transition API docs](https://nuxt.com/docs/4.x/getting-started/transitions#view-transitions-api-experimental)
*/
viewTransition: NuxtAppConfig["viewTransition"];
/**
* Default values for KeepAlive configuration between pages.
*
* This can be overridden with `definePageMeta` on an individual page. Only JSON-serializable values are allowed.
*
* @see [Vue KeepAlive](https://vuejs.org/api/built-in-components#keepalive)
*/
keepalive: NuxtAppConfig["keepalive"];
/**
* Customize Nuxt root element id.
*
* @deprecated Prefer `rootAttrs.id` instead
*/
rootId: string | false;
/**
* Customize Nuxt root element tag.
*/
rootTag: string;
/**
* Customize Nuxt root element id.
*/
rootAttrs: SerializableHtmlAttributes;
/**
* Customize Nuxt Teleport element tag.
*/
teleportTag: string;
/**
* Customize Nuxt Teleport element id.
*
* @deprecated Prefer `teleportAttrs.id` instead
*/
teleportId: string | false;
/**
* Customize Nuxt Teleport element attributes.
*/
teleportAttrs: SerializableHtmlAttributes;
/**
* Customize Nuxt SpaLoader element tag.
*/
spaLoaderTag: string;
/**
* Customize Nuxt SPA loading template element attributes.
*/
spaLoaderAttrs: SerializableHtmlAttributes;
};
/**
* Boolean or a path to an HTML file with the contents of which will be inserted into any HTML page rendered with `ssr: false`.
*
* - If it is unset, it will use `~/spa-loading-template.html` file in one of your layers, if it exists. - If it is false, no SPA loading indicator will be loaded. - If true, Nuxt will look for `~/spa-loading-template.html` file in one of your layers, or a
* default Nuxt image will be used.
* Some good sources for spinners are [SpinKit](https://github.com/tobiasahlin/SpinKit) or [SVG Spinners](https://icones.js.org/collection/svg-spinners).
*
* @example ~/spa-loading-template.html
* ```html
* <!-- https://github.com/barelyhuman/snips/blob/dev/pages/css-loader.md -->
* <div class="loader"></div>
* <style>
* .loader {
* display: block;
* position: fixed;
* z-index: 1031;
* top: 50%;
* left: 50%;
* transform: translate(-50%, -50%);
* width: 18px;
* height: 18px;
* box-sizing: border-box;
* border: solid 2px transparent;
* border-top-color: #000;
* border-left-color: #000;
* border-bottom-color: #efefef;
* border-right-color: #efefef;
* border-radius: 50%;
* -webkit-animation: loader 400ms linear infinite;
* animation: loader 400ms linear infinite;
* }
*
* @-webkit-keyframes loader {
* 0% {
* -webkit-transform: translate(-50%, -50%) rotate(0deg);
* }
* 100% {
* -webkit-transform: translate(-50%, -50%) rotate(360deg);
* }
* }
* @keyframes loader {
* 0% {
* transform: translate(-50%, -50%) rotate(0deg);
* }
* 100% {
* transform: translate(-50%, -50%) rotate(360deg);
* }
* }
* </style>
* ```
*/
spaLoadingTemplate: string | boolean | undefined | null;
/**
* An array of nuxt app plugins.
*
* Each plugin can be a string (which can be an absolute or relative path to a file). If it ends with `.client` or `.server` then it will be automatically loaded only in the appropriate context.
* It can also be an object with `src` and `mode` keys.
*
* @note Plugins are also auto-registered from the `~/plugins` directory
* and these plugins do not need to be listed in `nuxt.config` unless you
* need to customize their order. All plugins are deduplicated by their src path.
*
* @see [`plugins/` directory documentation](https://nuxt.com/docs/4.x/directory-structure/app/plugins)
*
* @example
* ```js
* plugins: [
* '~/plugins/foo.client.js', // only in client side
* '~/plugins/bar.server.js', // only in server side
* '~/plugins/baz.js', // both client & server
* { src: '~/plugins/both-sides.js' },
* { src: '~/plugins/client-only.js', mode: 'client' }, // only on client side
* { src: '~/plugins/server-only.js', mode: 'server' } // only on server side
* ]
* ```
*/
plugins: (NuxtPlugin | string)[];
/**
* You can define the CSS files/modules/libraries you want to set globally (included in every page).
*
* Nuxt will automatically guess the file type by its extension and use the appropriate pre-processor. You will still need to install the required loader if you need to use them.
*
* @example
* ```js
* css: [
* // Load a Node.js module directly (here it's a Sass file).
* 'bulma',
* // CSS file in the project
* '~/assets/css/main.css',
* // SCSS file in the project
* '~/assets/css/main.scss'
* ]
* ```
*/
css: string[];
/**
* An object that allows us to configure the `unhead` nuxt module.
*/
unhead: {
/**
* Enable the legacy compatibility mode for `unhead` module. This applies the following changes: - Disables Capo.js sorting - Adds the `DeprecationsPlugin`: supports `hid`, `vmid`, `children`, `body` - Adds the `PromisesPlugin`: supports promises as input
*
*
* @see [`unhead` migration documentation](https://unhead.unjs.io/docs/typescript/head/guides/get-started/migration)
*
* @example
* ```ts
* export default defineNuxtConfig({
* unhead: {
* legacy: true
* })
* ```
*/
legacy: boolean;
/**
* An object that will be passed to `renderSSRHead` to customize the output.
*
* @example
* ```ts
* export default defineNuxtConfig({
* unhead: {
* renderSSRHeadOptions: {
* omitLineBreaks: true
* }
* })
* ```
*/
renderSSRHeadOptions: RenderSSRHeadOptions;
};
/**
* The builder to use for bundling the Vue part of your application.
*
*/
builder: "vite" | "webpack" | "rspack" | {
bundle: (nuxt: Nuxt) => Promise<void>;
};
/**
* Configures whether and how sourcemaps are generated for server and/or client bundles.
*
* If set to a single boolean, that value applies to both server and client. Additionally, the `'hidden'` option is also available for both server and client.
* Available options for both client and server: - `true`: Generates sourcemaps and includes source references in the final bundle. - `false`: Does not generate any sourcemaps. - `'hidden'`: Generates sourcemaps but does not include references in the final bundle.
*/
sourcemap: boolean | {
server?: boolean | "hidden";
client?: boolean | "hidden";
};
/**
* Log level when building logs.
*
* Defaults to 'silent' when running in CI or when a TTY is not available. This option is then used as 'silent' in Vite and 'none' in Webpack
*
*/
logLevel: "silent" | "info" | "verbose";
/**
* Shared build configuration.
*/
build: {
/**
* If you want to transpile specific dependencies with Babel, you can add them here. Each item in transpile can be a package name, a function, a string or regex object matching the dependency's file name.
*
* You can also use a function to conditionally transpile. The function will receive an object ({ isDev, isServer, isClient, isModern, isLegacy }).
*
* @example
* ```js
* transpile: [({ isLegacy }) => isLegacy && 'ky']
* ```
*/
transpile: Array<string | RegExp | ((ctx: {
isClient?: boolean;
isServer?: boolean;
isDev: boolean;
}) => string | RegExp | false)>;
/**
* It is recommended to use `addTemplate` from `@nuxt/kit` instead of this option.
*
* @example
* ```js
* templates: [
* {
* src: '~/modules/support/plugin.js', // `src` can be absolute or relative
* dst: 'support.js', // `dst` is relative to project `.nuxt` dir
* }
* ]
* ```
*/
templates: NuxtTemplate<any>[];
/**
* Nuxt allows visualizing your bundles and how to optimize them.
*
* Set to `true` to enable bundle analysis, or pass an object with options: [for webpack](https://github.com/webpack/webpack-bundle-analyzer#options-for-plugin) or [for vite](https://github.com/btd/rollup-plugin-visualizer#options).
*
* @example
* ```js
* analyze: {
* analyzerMode: 'static'
* }
* ```
*/
analyze: boolean | {
enabled?: boolean;
} & ((0 extends 1 & BundleAnalyzerPlugin.Options ? Record<string, unknown> : BundleAnalyzerPlugin.Options) | PluginVisualizerOptions);
};
/**
* Build time optimization configuration.
*/
optimization: {
/**
* Functions to inject a key for.
*
* As long as the number of arguments passed to the function is lower than `argumentLength`, an additional magic string will be injected that can be used to deduplicate requests between server and client. You will need to take steps to handle this additional key.
* The key will be unique based on the location of the function being invoked within the file.
*
*/
keyedComposables: KeyedFunction[];
/**
* Factories for functions that should be registered for automatic key injection.
*
* @see keyedComposables
*/
keyedComposableFactories: KeyedFunctionFactory[];
/**
* Tree shake code from specific builds.
*/
treeShake: {
/**
* Tree shake composables from the server or client builds.
*
*
* @example
* ```js
* treeShake: { client: { myPackage: ['useServerOnlyComposable'] } }
* ```
*/
composables: {
server: Record<string, string[]>;
client: Record<string, string[]>;
};
};
/**
* Options passed directly to the transformer from `unctx` that preserves async context after `await`.
*/
asyncTransforms: TransformerOptions;
};
/**
* Extend project from multiple local or remote sources.
*
* Value should be either a string or array of strings pointing to source directories or config path relative to current config.
* You can use `github:`, `gh:` `gitlab:` or `bitbucket:`
*
* @see [`c12` docs on extending config layers](https://github.com/unjs/c12#extending-config-layer-from-remote-sources)
*
* @see [`giget` documentation](https://github.com/unjs/giget)
*/
extends: string | [string, SourceOptions?] | (string | [string, SourceOptions?])[];
/**
* Specify a compatibility dat