This is a Q-n-A for my talk Layers Unwrapped
at Nuxt Nation 2023.
Q: Could layers be used to implement multiple interfaces (separate applications) that use a lot of common code underneath?
Yes, layers can be used to implement multiple interfaces. The demo project discussed in my talk uses /apps
directory. /apps
directory can have more than one Nuxt app, (i.e. separate applications) that uses the layers coming from the /packages
.
If your Nuxt projects & layers are not in the same repo, you can publish common Nuxt Layers (such as theme, UI, auth, data-provider, etc.) as NPM packages. That way you can extend them to other Nuxt projects.
Q: Do you know of any examples where this architecture has been used in production?
I have been following this project ever since it was in Nuxt 2. This is an Australian State Government project. They have recently converted the majority of their Nuxt modules into Nuxt Layers. Their framework now uses Nuxt 3 with layered architecture. Nuxt fetches data from the headless CMS and then server-renders multiple websites. These websites are kind of similar (i.e. belong to the same organisation) but for different departments.
This project also answers the first question above. They are creating multiple different websites using - or I should say 'reusing' - the same set of base Nuxt Layers.
Q: Are there any drawbacks to the layers architecture?
Barrier to entry for Nuxt Layers is quite low. Anyone who knows basic Nuxt can start creating layers from the get-go. But you and the project team should carefully plan and scope out layer-able parts. Layers may become hard to maintain if they are not well thought out.
Q: Do you have any other tips you’d like to share with us about layers?
app.config
to customise Nuxt projects at app level. app.config
is layer-able, so you can provide default app settings. And also have the power to override it when needed.prefix
your components in layer's nuxt.config
if your layers have two components with the same name.Checkout
layer can hold components & composable for gift message, shipping, billing and payment. Checkout
layer can also include Checkout
pages that use the unique Nuxt layout.