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.
nuxt.config and app.configapp/components/ directoryapp/composables/ and app/utils/ directoriesBy default, any layers within your project in the ~~/layers directory will be automatically registered as layers in your project.
In addition, named layer aliases to the srcDir of each of these layers will automatically be created. For example, you will be able to access the ~~/layers/test layer via #layers/test.
In addition, you can extend from a layer by adding the extends property to your nuxt.config file.
export default defineNuxtConfig({
extends: [
// Extend from a local layer
'../base',
// Extend from an installed npm package
'@my-themes/awesome',
// Extend from a git repository
'github:my-themes/awesome#v1',
],
})
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 }],
],
})
export default defineNuxtConfig({
extends: [
[
'github:my-themes/awesome',
{
meta: {
name: 'my-awesome-theme',
},
},
],
],
})
Nuxt uses unjs/c12 and unjs/giget for extending remote layers. Check the documentation for more information and all available options.
When using multiple layers, it's important to understand the override order. Layers with higher priority override layers with lower priority when they define the same files or components.
The priority order from highest to lowest is:
~~/layers directory - sorted alphabetically (Z has higher priority than A)extends config - first entry has higher priority than secondextends - Use for external dependencies (npm packages, remote repositories) or layers outside your project directory~~/layers directory - Use for local layers that are part of your project~/layers/1.z-layer, ~/layers/2.a-layer. This way 2.a-layer will have higher priority than 1.z-layer.export default defineNuxtConfig({
extends: [
// Local layer outside the project
'../base',
// NPM package
'@my-themes/awesome',
// Remote repository
'github:my-themes/awesome#v1',
],
})
If you also have ~~/layers/custom, the priority order is:
~~/layers/custom../base@my-themes/awesomegithub:my-themes/awesome#v1 (lowest)This means your project files will override any layer, and ~~/layers/custom will override anything in extends.
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.
Prerendering
Nuxt allows pages to be statically rendered at build time to improve certain performance or SEO metrics