feat(docs): describe addTemplate

This commit is contained in:
Andrey Yolkin 2023-08-30 12:52:25 +03:00
parent c197617f65
commit cd30650aad
No known key found for this signature in database
GPG Key ID: 4A2899263001EA49

View File

@ -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<string, any>
getContents?: (data: Record<string, any>) => string | Promise<string>
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<string>`
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