There are two types of Nuxt modules:Documentation Index
Fetch the complete documentation index at: https://mintlify.com/nuxt/nuxt/llms.txt
Use this file to discover all available pages before exploring further.
- Published modules are distributed on npm - you can see a list of some community modules on the Nuxt website.
- Local modules exist within a Nuxt project, either inlined in Nuxt config or within the
modulesdirectory.
Define Your Module
When using the starter, your module definition is available at
src/module.ts.Low-Level Function Definition
At a low level, a Nuxt module definition is a simple, potentially asynchronous, function accepting inline user options and anuxt object to interact with Nuxt.
Using defineNuxtModule Helper
You can get type hinting for this function using the higher-leveldefineNuxtModule helper provided by Nuxt Kit.
Recommended: Object Syntax with Meta
Instead, to define a module, we recommend using the object-syntax withmeta property to identify your module, especially when publishing to npm.
This helper makes writing Nuxt modules more straightforward by implementing many common patterns needed by modules, guaranteeing future compatibility and improving the experience for both module authors and users.
Benefits of defineNuxtModule
defineNuxtModule returns a wrapper function with the lower level (inlineOptions, nuxt) module signature. This wrapper function applies defaults and other necessary steps before calling your setup function:
- Support
defaultsandmeta.configKeyfor automatically merging module options - Type hints and automated type inference
- Ensure module gets installed only once using a unique key computed from
meta.nameormeta.configKey - Automatically register Nuxt hooks
- Automatically check for compatibility issues based on module meta
- Expose
getOptionsandgetMetafor internal usage of Nuxt - Ensuring backward and upward compatibility as long as the module is using
defineNuxtModulefrom the latest version of@nuxt/kit - Integration with module builder tooling
Add Runtime Code
When using the starter, the runtime directory is
src/runtime/.Runtime Assets
Inside the runtime directory, you can provide any kind of assets related to the Nuxt app:- Vue components
- Composables
- Nuxt plugins
- API routes
- Middlewares
- Nitro plugins
- Stylesheets
- 3D models
- Images
- etc.
Auto-Imports Limitation
Module Structure Summary
Here’s the typical structure of a Nuxt module:Next Steps
Now that you understand the module structure, learn how to add functionality to your module with recipes.Module Recipes
Add plugins, components, and more to your module