2022-12-05 10:44:28 +00:00
---
2023-10-18 10:59:43 +00:00
title: 'Layers'
2022-12-05 10:44:28 +00:00
description: Nuxt provides a powerful system that allows you to extend the default files, configs, and much more.
2024-09-17 15:33:49 +00:00
navigation.icon: i-ph-stack
2022-12-05 10:44:28 +00:00
---
2024-06-30 10:11:16 +00:00
One of the core features of Nuxt 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.
2023-03-23 13:25:44 +00:00
2023-10-18 10:59:43 +00:00
## Use Cases
2022-12-05 10:44:28 +00:00
- Share reusable configuration presets across projects using `nuxt.config` and `app.config`
2023-10-18 10:59:43 +00:00
- Create a component library using [`components/` ](/docs/guide/directory-structure/components ) directory
- Create utility and composable library using [`composables/` ](/docs/guide/directory-structure/composables ) and [`utils/` ](/docs/guide/directory-structure/utils ) directories
2022-12-05 10:44:28 +00:00
- Create Nuxt module presets
- Share standard setup across projects
2023-12-08 09:39:24 +00:00
- Create Nuxt themes
2024-03-14 13:59:36 +00:00
- Enhance code organization by implementing a modular architecture and support Domain-Driven Design (DDD) pattern in large scale projects.
2023-10-18 10:59:43 +00:00
## Usage
2022-12-05 10:44:28 +00:00
2024-07-12 12:24:31 +00:00
By default, any layers within your project in the `~/layers` directory will be automatically registered as layers in your project
2024-07-20 08:20:52 +00:00
::note
Layer auto-registration was introduced in Nuxt v3.12.0
::
2024-07-12 12:24:31 +00:00
In addition, you can extend from a layer by adding the [extends ](/docs/api/nuxt-config#extends ) property to your [`nuxt.config` ](/docs/guide/directory-structure/nuxt-config ) file.
2022-12-05 10:44:28 +00:00
2024-03-06 13:46:28 +00:00
```ts [nuxt.config.ts]
2022-12-05 10:44:28 +00:00
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
]
})
```
2024-03-06 13:25:23 +00:00
You can also pass an authentication token if you are extending from a private GitHub repository:
2024-03-06 13:40:32 +00:00
```ts [nuxt.config.ts]
2024-03-06 13:25:23 +00:00
export default defineNuxtConfig({
extends: [
// per layer configuration
['github:my-themes/private-awesome', { auth: process.env.GITHUB_TOKEN }]
]
})
```
Nuxt uses [unjs/c12 ](https://c12.unjs.io ) and [unjs/giget ](https://giget.unjs.io ) for extending remote layers. Check the documentation for more information and all available options.
2023-10-18 10:59:43 +00:00
::read-more{to="/docs/guide/going-further/layers"}
Read more about layers in the **Layer Author Guide** .
::
2022-12-05 10:44:28 +00:00
2024-09-17 15:33:49 +00:00
::tip{icon="i-ph-video" to="https://www.youtube.com/watch?v=lnFCM7c9f7I" target="_blank"}
2024-04-30 08:25:35 +00:00
Watch a video from Learn Vue about Nuxt Layers.
::
2024-09-17 15:33:49 +00:00
::tip{icon="i-ph-video" to="https://www.youtube.com/watch?v=fr5yo3aVkfA" target="_blank"}
2024-04-30 08:25:35 +00:00
Watch a video from Alexander Lichter about Nuxt Layers.
2023-10-18 10:59:43 +00:00
::
2022-12-05 10:44:28 +00:00
## Examples
2023-12-08 09:39:24 +00:00
::card-group
::card
---
icon: i-simple-icons-github
title: Content Wind Theme
to: https://github.com/Atinux/content-wind
target: _blank
ui.icon.base: text-black dark:text-white
---
A lightweight Nuxt theme to build a Markdown driven website. Powered by Nuxt Content, TailwindCSS and Iconify.
::
::