how could i pass function to plugin in module by module options? Is some way to extend nuxt app by global property to pass func in module file or something else?
Problem example:
nuxt.config.js
modules: [
[
'some-module',
{
foo: () => {
// Do something
}
}
]
]
module.js
module.exports = function (options) {
this.addPlugin({
src: path.resolve(__dirname, 'plugin.js'),
fileName: 'bar-plugin.client.js',
options,
});
}
plugin.js
const options = JSON.parse(`<%= JSON.stringify(options, null, 2) %>`); // <-- Here we pluck out all the options using Lodash templates and JSON.stringify() but func "foo" is undefined(?)
export default ({ app }, inject) => {
incject('somePluginName', handler(app, options)
}
I tried extend nuxt app in module hook modules:done like:
this.nuxt.hook('modules:done', moduleContainer => {
moduleContainer.nuxt.app.$foo = options.foo
})
But app is undefined :/