mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-30 01:17:16 +00:00
feat(docs): describe addTemplate
This commit is contained in:
parent
c197617f65
commit
cd30650aad
@ -1812,9 +1812,74 @@ export default defineNuxtPlugin((nuxtApp) => {
|
|||||||
|
|
||||||
[source code](https://github.com/nuxt/nuxt/blob/main/packages/kit/src/template.ts)
|
[source code](https://github.com/nuxt/nuxt/blob/main/packages/kit/src/template.ts)
|
||||||
|
|
||||||
- `addTemplate(templateOptions)`
|
### `addTemplate`
|
||||||
- `addTypeTemplate(templateOptions)`
|
|
||||||
- `updateTemplates({ filter?: ResolvedNuxtTemplate => boolean })`
|
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
|
## Nitro
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user