The layers/ directory allows you to organize and share reusable code, components, composables, and configurations across your Nuxt application. Any layers within your project in the layers/ directory will be automatically registered.
layers/ directory auto-registration is available in Nuxt v3.12.0+.Each subdirectory within layers/ is treated as a separate layer. A layer can contain the same structure as a standard Nuxt application.
nuxt.config.ts file to be recognized as a valid layer, even if it's empty.-| layers/
---| base/
-----| nuxt.config.ts
-----| app/
-------| components/
---------| BaseButton.vue
-------| composables/
---------| useBase.ts
-----| server/
-------| api/
---------| hello.ts
---| admin/
-----| nuxt.config.ts
-----| app/
-------| pages/
---------| admin.vue
-------| layouts/
---------| admin.vue
Named layer aliases to the srcDir of each layer are automatically created. You can access a layer using the #layers/[name] alias:
// Access the base layer
import something from '#layers/base/path/to/file'
// Access the admin layer
import { useAdmin } from '#layers/admin/composables/useAdmin'
Each layer can include:
nuxt.config.ts - Layer-specific configuration that will be merged with the main configapp.config.ts - Reactive application configurationapp/components/ - Vue components (auto-imported)app/composables/ - Vue composables (auto-imported)app/utils/ - Utility functions (auto-imported)app/pages/ - Application pagesapp/layouts/ - Application layoutsapp/middleware/ - Route middlewareapp/plugins/ - Nuxt pluginsserver/ - Server routes, middleware, and utilitiesshared/ - Shared code between app and serverWhen multiple layers define the same resource (component, composable, page, etc.), the layer with higher priority wins. Layers are sorted alphabetically, with later letters having higher priority (Z > A).
To control the order, prefix directories with numbers: 1.base/, 2.features/, 3.admin/.