vue.jslaravel-echopusher-js

Install and Configure laravel-echo and pusher-js in VueJS


I'm using laravel-echo and pusher-js in a projetct with Laravel and VueJS and it works. But now I need to broadcast in a VueJS project without laravel (a pure VueJS project).
I don't know how to install and configure laravel-echo and laravel-pusher in a pure project VueJS.
I try to do llike this, but don't works:

import Echo from "laravel-echo";

window.Pusher = require("pusher-js");

window.Echo = new Echo({
  broadcaster: "pusher",
  key: "myappkey",
  cluster: "mt1",
  host: window.location.hostname + ":6001",
});

Vue.use(Echo);

The 2 packages are in my package.json:

"laravel-echo": "^1.11.2",
"pusher-js": "^7.0.3",

Solution

  • Pusher is not just a Laravel plug in. You should be able to use the pusher-js library directly and can get up and running by following the quick start.

    You will need to trigger events and can do so using one of the many server libraries detailed on the Pusher site.