What are Nuxt Modules?
When developing production-grade applications with Nuxt, you might find that the framework’s core functionality is not enough. Nuxt can be extended with configuration options and plugins, but maintaining these customizations across multiple projects can be tedious and time-consuming. Nuxt modules are async functions that sequentially run when starting Nuxt in development mode usingnuxt dev or building a project for production with nuxt build. They can:
- Override templates
- Configure webpack loaders
- Add CSS libraries
- Perform many other useful tasks
Why Use Modules?
Modules solve several common problems:- Reusability - Package and share functionality across projects
- Maintainability - Keep customizations organized and versioned
- Ecosystem - Leverage community-built integrations
- Best practices - Modules often include optimized configurations
Adding Modules
Once you’ve installed a module, you can add it to yournuxt.config.ts file under the modules property.
nuxt.config.ts
Nuxt modules are now build-time-only, and the
buildModules property used in Nuxt 2 is deprecated in favor of modules.Popular Nuxt Modules
The Nuxt ecosystem includes hundreds of modules for various purposes:Content Management
- @nuxt/content - File-based CMS for Nuxt
- @nuxtjs/strapi - Strapi integration
UI & Styling
- @nuxtjs/tailwindcss - Tailwind CSS integration
- @nuxt/ui - Fully styled and customizable components
- @nuxtjs/color-mode - Dark mode support
State & Data
- @pinia/nuxt - Official state management
- @nuxtjs/apollo - GraphQL client
SEO & Analytics
- @nuxtjs/seo - SEO utilities and meta management
- @nuxtjs/sitemap - Automatic sitemap generation
Development
- @nuxt/devtools - Enhanced development experience
- @nuxtjs/eslint - ESLint integration
Module Configuration
Many modules accept configuration options. You can pass these options in two ways:Inline Configuration
nuxt.config.ts
Top-Level Configuration
nuxt.config.ts
Disabling Modules
You can disable a module by setting its config key tofalse in your Nuxt config. This is particularly useful when you want to disable modules inherited from layers.
nuxt.config.ts
Creating Your Own Module
Everyone has the opportunity to develop modules and contribute to the ecosystem. Creating a module involves:- Setup - Use the module starter template
- Development - Implement your module logic
- Testing - Ensure your module works correctly
- Publishing - Share with the community via npm
Basic Module Structure
modules/example/index.ts
Module Best Practices
When using or creating modules:- Use official modules when available - They’re well-maintained and optimized
- Check compatibility - Ensure modules work with your Nuxt version
- Read documentation - Each module may have specific requirements
- Keep modules updated - Benefit from improvements and security fixes
- Test thoroughly - Especially when combining multiple modules
Exploring Modules
You can explore available Nuxt modules on the official modules page, which provides:- Searchable module directory
- Module descriptions and stats
- Installation instructions
- Links to documentation and source code