0.0.1 • Published 2 months ago

@tdv_layer/transfers v0.0.1

Weekly downloads
-
License
-
Repository
-
Last release
2 months ago

Nuxt 3 Layers Architecture

Nuxt 3 introduces layers, a powerful feature for structuring your codebase into reusable and composable units. This is ideal for:

  • Design systems or UI kits
  • Multisite applications
  • Shared logic between projects
  • White-labeling

šŸš€ What is a Nuxt Layer?

A layer is essentially a Nuxt project that can be extended by another. You can define layouts, components, plugins, stores, etc., inside a base layer and reuse them across multiple Nuxt apps.

Your app (consumer) imports and extends the base layer (provider) via extends: ['./features/transfers'] in nuxt.config.ts.


🧠 Key Concepts

  • A layer is just another Nuxt project (with its own nuxt.config.ts).
  • You can override anything from the base layer in your consuming app.
  • Layers support TypeScript, Pinia, composables, middleware, and more.

šŸ“ Folder Structure Example

my-app/
ā”œā”€ā”€ app.config.ts
ā”œā”€ā”€ nuxt.config.ts      # <-- extends ./features/transfers
ā”œā”€ā”€ layers/
│   └── transfers/
│       ā”œā”€ā”€ app.config.ts
│       ā”œā”€ā”€ nuxt.config.ts
│       ā”œā”€ā”€ components/
│       ā”œā”€ā”€ layouts/
│       ā”œā”€ā”€ pages/
│       ā”œā”€ā”€ plugins/
│       └── stores/
ā”œā”€ā”€ pages/
ā”œā”€ā”€ components/
└── ...

šŸ“š Official Documentation

  • šŸ“˜ Nuxt Layers — Learn how to create and use Nuxt layers to organize your project or create reusable modules.
  • šŸ“¦ Nuxt extends in nuxt.config.ts — How to extend another Nuxt app, layer, or configuration.
  • šŸ“ Nuxt Directory Structure — Understand how Nuxt organizes files like components/, pages/, layouts/, etc.
  • šŸ“š Nuxt Extend Concepts — Dive deeper into how Nuxt extensions work and advanced use cases.

Nuxt Layer Starter

Create Nuxt extendable layer with this GitHub template.

Setup

Make sure to install the dependencies:

pnpm install

Working on your layer

Your layer is at the root of this repository, it is exactly like a regular Nuxt project, except you can publish it on NPM.

The .playground directory should help you on trying your layer during development.

Running pnpm dev will prepare and boot .playground directory, which imports your layer itself.

Distributing your layer

Your Nuxt layer is shaped exactly the same as any other Nuxt project, except you can publish it on NPM.

To do so, you only have to check if files in package.json are valid, then run:

npm publish --access public

Once done, your users will only have to run:

npm install --save your-layer

Then add the dependency to their extends in nuxt.config:

defineNuxtConfig({
  extends: 'your-layer'
})

Development Server

Start the development server on http://localhost:3000

npm dev

Checkout the deployment documentation for more information.