Nuxt Layers
Nuxt Layers are a powerful mechanism to share configuration, components, and logic across multiple projects. It's like having a full Nuxt application inside your application!
https://nuxt.com/docs/guide/going-further/layers
Concept
A "Layer" is simply a directory (local, git, or npm) containing a nuxt.config.ts file.
Your application can "extend" this layer. It will then inherit:
- Configuration (
nuxt.config.ts) - Components (
components/) - Composables (
composables/) - Plugins (
plugins/) - Pages (
pages/) - And more...
This is ideal for creating a "Design System" or a base configuration for your company.
Overriding
The main application always has priority.
- If you define a config in your
nuxt.config.ts, it overrides the layer's config. - If you create a
components/AppAlert.vuefile, it will replace the layer's file (if it exists at the same path).
Challenge
In this exercise, we have prepared a base-layer folder that contains a configuration with runtimeConfig values.
- Open
nuxt.config.tsand extend the local layer./base-layer. - Look at
app.vue, theappNameandappVersionvalues should now display. - (Optional) Add your own
runtimeConfig.public.appNamein the mainnuxt.config.tsto see how it overrides the layer's config.