Layers
Nuxt provides a powerful system that allows you to extend the default files, configs, and much more.
One of the core features of Nuxt 3 is the layers and extending support. You can extend a default Nuxt application to reuse components, utils, and configuration. The layers structure is almost identical to a standard Nuxt application which makes them easy to author and maintain.
Use Cases
- Share reusable configuration presets across projects using
nuxt.config
andapp.config
- Create a component library using
components/
directory - Create utility and composable library using
composables/
andutils/
directories - Create Nuxt module presets
- Share standard setup across projects
- Create Nuxt themes
Usage
You can extend a layer by adding the extends property to the nuxt.config.ts
file.
export default defineNuxtConfig({
extends: [
'../base', // Extend from a local layer
'@my-themes/awesome', // Extend from an installed npm package
'github:my-themes/awesome#v1', // Extend from a git repository
]
})
You can also pass an authentication token if you are extending from a private GitHub repository:
export default defineNuxtConfig({
extends: [
// per layer configuration
['github:my-themes/private-awesome', { auth: process.env.GITHUB_TOKEN }]
]
})
Nuxt uses unjs/c12 and unjs/giget for extending remote layers. Check the documentation for more information and all available options.
Examples
Server
Build full-stack applications with Nuxt's server framework. You can fetch data from your database or another server, create APIs, or even generate static server-side content like a sitemap or a RSS feed - all from a single codebase.
Deployment
Learn how to deploy your Nuxt application to any hosting provider.