Plugins
Nuxt Kit provides a set of utilities to help you create and use plugins. You can add plugins or plugin templates to your module using these functions. Plugins are self-contained code that usually add app-level functionality to Vue. In Nuxt, plugins are automatically imported from theapp/plugins/ directory.
addPlugin
Registers a Nuxt plugin and adds it to the plugins array.
Type
Parameters
plugin: A plugin object or a string with the path to the plugin. If a string is provided, it will be converted to a plugin object with src set to the string value.
If a plugin object is provided, it must have the following properties:
Warning: Avoid using
order unless necessary. Use append if you simply need to register plugins after Nuxt defaults.
options: Optional object:
Usage
addPluginTemplate
Adds a template and registers as a nuxt plugin. This is useful for plugins that need to generate code at build time.
Type
Parameters
pluginOptions: A plugin template object:
Warning: Prefer using
getContents for dynamic plugin generation. Avoid setting order unless necessary.
options: Optional object (same as addPlugin).
Usage
Generate plugin with different options
UseaddPluginTemplate when you need to generate plugin code dynamically at build time. This allows you to generate different plugin contents based on the options passed to it.