Replies: 2 comments
-
Can anyone confirm if these are the tools Nuxt currently use to load packages? To me it looks like they are and looks cool! |
Beta Was this translation helpful? Give feedback.
0 replies
-
Any updates? 👀 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Background
When creating Nuxt modules, it's common to keep a consistent directory structure for your files.
For the runtime directory, the convention is to follow paths similar to how you would set up a Nuxt app.
To register the above, we need to do something like the following:
As you can see, compared to the Nuxt DX itself, this is quite tedious and verbose.
There are also some other concerns with this approach:
Having the freedom to modify Nuxt however you want in a module is powerful and it shouldn't change.
But for many modules, sticking with whatever the convention is makes life easier for the author and the end-user. As it stands though, there is little in the way of guide-rails to make sure you're following the conventions.
The Nuxt core does not strictly use the kit utilities, this leads to duplicate code that has slightly different behavior. One example is file name modifiers which don't work with the addComponent utility.
Proposal
We introduce a
@nuxt/kit
functionautoSetupDir
that will load the entire contents of the runtime folder automatically, following the same behavior as the Nuxt core.This is strictly opt-in to avoid potential breaking changes. In this, we also introduce the convention of an
app
folder for modules (TBC) that wish to use this feature.Where appropriate we use namespaces automatically, setting a convention.
Consider the directory structure below:
The server API endpoint would be set up as:
Further considerations may need to be made for other folders such as pages, plugins, server, etc.
Final remarks
A simple version of this could be implemented fairly straight forward leveraging existing kit utilities.
Ideally, though, we'd share the logic that the Nuxt core uses to scan and load in these directories. This would mean layers, modules and Core Nuxt would all be using the same logic. This is a much larger piece of work though and may not make sense to try and tackle initially.
Beta Was this translation helpful? Give feedback.
All reactions