Closed PolanskiPol closed 2 months ago
Hi there, isn't this a problem you will have with all plugins that you install more than one time?
I don't see how the Nuxt API Party module should detect multiple usages. I'd rather recommend you move your configuration from the module options to the runtime config. So instead of passing the endpoints
to Nuxt API Party, add it to your runtime config:
// Nuxt module 2
export default defineNuxtModule({
meta: {
name: 'module2',
configKey: 'configKey',
},
defaults: {},
async setup(options, nuxt) {
await installModule('nuxt-api-party');
},
});
// Nuxt project config
export default defineNuxtConfig({
...
modules : [
"module1", // This module will be installed and its endpoints and composables will be available
"module2", // This module will be installed but its endpoints and composables will not be available
],
runtimeConfig: {
apiParty: {
endpoints: {}
}
}
});
Or you can add new items to the endpoints from inside your modules, which merges the configs:
await installModule('nuxt-api-party')
nuxt.options.runtimeConfig.apiParty = defu(
nuxt.options.runtimeConfig.apiParty,
{
endpoints: {
newApi: {}
}
},
)
Hello,
isn't this a problem you will have with all plugins that you install more than one time?
Yeah, this could be the case in the future now that you mention it, but as of now, it has only happened to us using Nuxt Api Party, and I'm not aware of any other modules being used the same way as we're using this one.
I'd rather recommend you move your configuration from the module options to the runtime config
We've found a similar solution for the problem that seems to fit our needs, many thanks for your recommendation!
Thank you for your time once again! 😊
Glad you've found a viable solution. 🙂
Describe the feature
Issue
We are using Nuxt Api Party in the company that I'm working at, but we've found a limitation when installing it programatically using
installModule('nuxt-api-party', { ... })
inside of modules instead of installing it directly in thenuxt.config.ts
file of a project.Right now, if I add more than one module to
nuxt.config.ts
that installs Nuxt Api Party using Nuxt'sawait installModule('nuxt-api-party', { ... })
, only the first module in-line options will be applied, and only the first module composables will be correctly auto-imported to the project.This is affecting our workflow as we intended to modularize the installation of various Api Party endpoints into the same project by separating them in different Nuxt modules.
Minimal example
Doing the previous example, Nuxt Api Party will be correctly installed in the project, and both modules will be installed too. However, only the configuration from module1 will be applied, and only the composables
$module1
anduseModule1Data
will be auto-imported into the project.Proposal
We propose to allow Nuxt Api Party to be installed from different modules at the same time, such as the example given allow, joining all the in-line configurations into a single one that implements the endpoints from all modules and auto-imports the composables from all modules.
Thank you for your time! 😊
Additional information
Final checks