#Is it possible to register layers inside module?

4 messages · Page 1 of 1 (latest)

leaden hare
#

I want to create a module that includes other modules and layers
for modules it's easy to do with moduleDependencies
for layers I have try with nuxt.options.extends but it's not work

one solution for me now is extends target layer directly to app separate from module
back to my question, is it possible to register layers inside module?

ps. sorry for my bad english

marsh flaxBOT
#

Hi @leaden hare. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

Short answer: there’s no documented, supported way for a Nuxt module to “register” layers (i.e., extend other Nuxt apps) at runtime.

Details:

  • Layers are defined/loaded via the project’s extends in nuxt.config, or via auto-scanned local layers in ~/layers, and can also come from npm/git sources. These are evaluated as part of configuration loading, not during a module’s setup. [Layers getting started; Authoring layers]
  • Modules can alter Nuxt configuration in code (nuxt.options), but the docs don’t show a supported pattern to add to extends from inside a module, and the layer system is resolved early by c12/giget before module execution order would ensure correct behavior. The knowledge sources do not explicitly mention a reliable way to mutate extends from a module so that it’s applied. [Altering configuration; Going deeper]
  • If you’re writing a module that needs to “work across layers,” you can inspect layers (paths and order) from a module using getLayerDirectories or nuxt.options._layers to implement custom logic per layer, but that’s for reading/handling, not for registering new layers. [Kit layers API; Multi-layer support for modules]
#

Recommended approaches:

So, registering layers from a module isn’t supported by the docs; have consumers extend the layer in nuxt.config instead.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: