nuxt-community / laravel-echo-module

Laravel Echo for Nuxt 2
MIT License
86 stars 31 forks source link

[Issue] Usage in plugin #7

Closed eliasrenman closed 4 years ago

eliasrenman commented 4 years ago

Hi there is currently a issue with importing and using the echo module in a plugin, a temporary workaround suggested by @ricardogobbosouza is to use the hook builder:extendPlugins. A code example of this would look like the following:

// nuxt.config.js
modules: [
  '@nuxtjs/laravel-echo',

  { handler: function() {
    this.nuxt.hook('builder:extendPlugins', (plugins) => {
      plugins.push('~/plugins/extend-echo.js')
    })
  }}
]

// ~/plugins/extend-echo.js
export default function ({ $echo }) {
  // Echo should be defined here  
  console.log($echo)
}