Templates
Nuxt Kit provides a set of utilities to help you work with templates. These functions allow you to generate extra files during development and build time. Templates allow you to generate extra files during development and build time. These files will be available in virtual filesystem and can be used in plugins, layouts, components, etc.addTemplate
Renders given template during build into the virtual file system, and optionally to disk in the project buildDir.
Type
Parameters
template: 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 can have the following properties:
Usage
Creating a Virtual File for Runtime Plugin
In this example, we merge an object inside a module and consume the result in a runtime plugin.#build alias:
addTypeTemplate
Renders given template during build into the project buildDir, then registers it as types.
Type
Parameters
template: 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. Properties are the same as addTemplate.
context: Optional context object:
Usage
Adding Type Templates to the Nitro Context
By default,addTypeTemplate only adds the type declarations to the Nuxt context. To also add them to the Nitro context, set nitro to true.
addServerTemplate
Adds a virtual file that can be used within the Nuxt Nitro server build.
Type
Parameters
template: A template object with the following properties:
Usage
updateTemplates
Regenerate templates that match the filter. If no filter is provided, all templates will be regenerated.
Type
Parameters
options: Options object: