diff --git a/docs/3.api/4.advanced/2.kit.md b/docs/3.api/4.advanced/2.kit.md index 5bb6353dda..07227d2c75 100644 --- a/docs/3.api/4.advanced/2.kit.md +++ b/docs/3.api/4.advanced/2.kit.md @@ -1812,9 +1812,74 @@ export default defineNuxtPlugin((nuxtApp) => { [source code](https://github.com/nuxt/nuxt/blob/main/packages/kit/src/template.ts) -- `addTemplate(templateOptions)` -- `addTypeTemplate(templateOptions)` -- `updateTemplates({ filter?: ResolvedNuxtTemplate => boolean })` +### `addTemplate` + +Renders given template using lodash template during build into the project buildDir. + +#### Type + +```ts +function addTemplate (template: NuxtTemplate | string): NuxtTemplate + +interface NuxtTemplate { + src?: string + filename?: string + dst?: string + options?: Record + getContents?: (data: Record) => string | Promise + write?: boolean +} +``` + +#### Parameters + +##### `template` + +**Type**: `NuxtTemplate | string` + +**Required**: `true` + +A template object or a string with the path to the template. If a string is provided, it will be converted to a template object with `src` set to the string value. If a template object is provided, it must have the following properties: + +- `src` (optional) + + **Type**: `string` + + Path to the template. If `src` is not provided, `getContents` must be provided instead. + +- `filename` (optional) + + **Type**: `string` + + Filename of the template. If `filename` is not provided, it will be generated from the `src` path. In this case, the `src` option is required. + +- `dst` (optional) + + **Type**: `string` + + Path to the destination file. If `dst` is not provided, it will be generated from the `filename` path and nuxt `buildDir` option. + +- `options` (optional) + + **Type**: `Options` + + Options to pass to the template. + +- `getContents` (optional) + + **Type**: `(data: Options) => string | Promise` + + A function that will be called with the `options` object. It should return a string or a promise that resolves to a string. If `src` is provided, this function will be ignored. + +- `write` (optional) + + **Type**: `boolean` + + If set to `true`, the template will be written to the destination file. Otherwise, the template will be used only in virtual filesystem. + +### `addTypeTemplate(templateOptions)` + +### `updateTemplates({ filter?: ResolvedNuxtTemplate => boolean })` ## Nitro