N
Nuxt8mo ago
Tirius

How to read custom module options that defined in nuxt.config from module plugin ?

// nuxt.config
export default defineNuxtConfig({
ui: {
hello: 'world'
}
});
// nuxt.config
export default defineNuxtConfig({
ui: {
hello: 'world'
}
});
You can read module options in module.ts like this
// module
export default defineNuxtModule<ModuleOptions>({
meta: {
name: 'ui',
configKey: 'ui',
},
setup(options, nuxt) {
// options - module options

// Add plugin
addPlugin(resolve('./runtime/plugin'));
}
});
// module
export default defineNuxtModule<ModuleOptions>({
meta: {
name: 'ui',
configKey: 'ui',
},
setup(options, nuxt) {
// options - module options

// Add plugin
addPlugin(resolve('./runtime/plugin'));
}
});
But how to read module options in plugin ?
// /runtime/plugin
export default defineNuxtPlugin((nuxt) => {
// How to access module options here ?
});
// /runtime/plugin
export default defineNuxtPlugin((nuxt) => {
// How to access module options here ?
});
2 Replies
IsraelOrtuno
IsraelOrtuno8mo ago
I think this may help https://nuxt.com/docs/guide/going-further/modules#exposing-options-to-runtime you have to manually add those options to the nuxt config object
IsraelOrtuno
IsraelOrtuno8mo ago
GitHub
nuxt-fathom/src/module.ts at main · valgeirb/nuxt-fathom
Fathom Analytics integration for Nuxt. Contribute to valgeirb/nuxt-fathom development by creating an account on GitHub.
Want results from more Discord servers?
Add your server