Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

196
Views
How to pass function through module options to plugin

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 :/

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!