I have been working on passing data from my module options to a plugin. Here is an example of how I am doing it:
module.exports = function (moduleOptions) {
const options = {
...this.options.moduleName,
...moduleOptions
}
this.addPlugin({
src: resolve(__dirname, 'plugin.js'),
options
})
}
This is the plugin code:
import { createStore } from 'lib';
export default async ({ store, app }) => {
const settings = {
axios: app.$axios,
models: <% options.models %>
}
settings.axios = app.$axios;
createStore(settings).install()(store)
};
And here is the configuration file:
const { resolve } = require('path')
module.exports = {
rootDir: resolve(__dirname, '..'),
buildDir: resolve(__dirname, '.nuxt'),
srcDir: __dirname,
render: {
resourceHints: false
},
modules: [
'moduleName'
],
moduleName: {
{ models: require(resolve(__dirname, '../example/models')) }
}
}
While implementing this, I encountered an issue where the models were empty when accessed in the plugin:
axios: app.$axios,
7 | models:
> 8 | }
The models were not null or undefined, but just empty. However, using
<% console.log(options.models) %>
showed that the models were loaded properly. These models need to be configurable, so I am seeking advice on how to pass this data from my nuxt.config.js
through a module to the plugin.
Any help would be appreciated :)