Use Cases
Leverage layers for:- Configuration presets: Share reusable
nuxt.configandapp.configacross projects - Component libraries: Create shareable component libraries using the
app/components/directory - Utility libraries: Build composable and utility libraries using
app/composables/andapp/utils/ - Module presets: Create Nuxt module presets
- Standard setups: Share common configurations across projects
- Nuxt themes: Create and distribute Nuxt themes
- Modular architecture: Implement Domain-Driven Design (DDD) patterns in large-scale projects
Usage
Auto-Registration
Nuxt automatically registers any layers within your project in the~~/layers directory:
Layer auto-registration was introduced in Nuxt v3.12.0.
srcDir of each layer. For example, you can access the ~~/layers/test layer via #layers/test.
Named layer aliases were introduced in Nuxt v3.16.0.
Extending from Layers
Extend from a layer by adding theextends property to your nuxt.config file:
Private Repository Authentication
Pass an authentication token for private GitHub repositories:If you don’t specify a branch, Nuxt clones the
main branch by default.Custom Layer Aliases
Override a layer’s alias by specifying it in the options:Layer Priority
Understand the override order when using multiple layers. Layers with higher priority override layers with lower priority.Priority Order
From highest to lowest priority:- Your project files - Always have the highest priority
- Auto-scanned layers from
~~/layersdirectory - Sorted alphabetically (Z > A) - Layers in
extendsconfig - First entry has higher priority than second
Priority Example
Consider multiple layers defining the same component:- If only layers exist,
2.theme/Button.vueis used (higher alphabetically) - If
app/components/Button.vueexists in your project, it overrides all layers
Controlling Priority
Prefix layer directories with numbers to control the order:When to Use Each Method
~~/layersdirectory: Use for local layers that are part of your projectextends: Use for external dependencies (npm packages, remote repositories) or layers outside your project directory
Full Priority Example
~~/layers/custom in your project, the priority order is:
- Your project files (highest)
~~/layers/custom../base@my-themes/awesomegithub:my-themes/awesome#v1(lowest)
Layer Structure
A layer uses the same directory structure as a standard Nuxt application:Publishing Layers
You can publish layers as:- npm packages: Easiest to distribute and version
- Git repositories: Great for private layers or monorepos
- Local directories: Perfect for development and testing
Examples
Content Wind
A lightweight Nuxt theme to build a Markdown-driven website. Powered by Nuxt Content, TailwindCSS, and Iconify.
Best Practices
- Version your layers: Use semantic versioning for published layers
- Document layer features: Clearly document what your layer provides
- Keep layers focused: Each layer should have a single, clear purpose
- Test layer compatibility: Ensure your layer works with target Nuxt versions
- Use priority wisely: Structure your layers to take advantage of the priority system