From 06d00014d39eeab1558e6d0497212221e1bb3f23 Mon Sep 17 00:00:00 2001 From: Andrey Yolkin Date: Sat, 29 Jul 2023 15:29:15 +0300 Subject: [PATCH] feat(docs): loadNuxt utility --- docs/3.api/4.advanced/2.kit.md | 73 ++++++++++++++++++++++++++++++++-- 1 file changed, 70 insertions(+), 3 deletions(-) diff --git a/docs/3.api/4.advanced/2.kit.md b/docs/3.api/4.advanced/2.kit.md index 06640abd3d..9156900346 100644 --- a/docs/3.api/4.advanced/2.kit.md +++ b/docs/3.api/4.advanced/2.kit.md @@ -74,9 +74,76 @@ export default defineNuxtModule({ [source code](https://github.com/nuxt/nuxt/blob/main/packages/kit/src/loader) -- `loadNuxt(loadOptions)` -- `buildNuxt(nuxt)` -- `loadNuxtConfig(loadOptions)` +Programmatic usage can be helpfull when you want to use Nuxt programmatically, for example, when building a CLI tool or test runner. + +### `loadNuxt` + +Load Nuxt programmatically + +#### Type + +```ts +async function loadNuxt (loadOptions?: LoadNuxtOptions): Promise + +interface LoadNuxtOptions extends LoadNuxtConfigOptions { + dev?: boolean + ready?: boolean + rootDir?: string + config?: LoadNuxtConfigOptions['overrides'] +} +``` + +#### Parameters + +loadNuxt uses [`c12`](https://github.com/unjs/c12/tree/main) under the hood, so it accepts the same options as `c12` with some additional options: + +##### `loadOptions` + +**Type**: `LoadNuxtOptions` + +**Default**: `{}` + +An object with the following properties: + +- `dev` (optional) + + **Type**: `boolean` + + **Default**: `false` + + If set to `true`, Nuxt will be loaded in development mode. + +- `ready` (optional) + + **Type**: `boolean` + + **Default**: `true` + + If set to `true`, Nuxt will be ready to use after the `loadNuxt` call. If set to `false`, you will need to call `nuxt.ready()` to make sure Nuxt is ready to use. + +- `rootDir` (optional) + + **Type**: `string` + + **Default**: `null` + + **Deprecated**: Use `cwd` option instead. + + The root directory of the Nuxt project. + +- `config` (optional) + + **Type**: `LoadNuxtConfigOptions['overrides']` + + **Default**: `{}` + + **Deprecated**: Use `overrides` option instead. + + Overrides for the Nuxt configuration. + +### `buildNuxt(nuxt)` + +### `loadNuxtConfig(loadOptions)` ## Compatibility