Martin Carlin

How to Use Laravel Echo Without npm

in laravel, echo, pusher

Just a quick post about how to use Laravel Echo without the npm package.

The way I did it was to add it to my local project as per the docs:

npm install --save laravel-echo pusher-js

Then I copied the node_modules/laravel-echo/dist/echo.js file to my public/vendor directory.

Then I just updated my scripts partial to include the Echo js file and the Pusher library:

<!-- Echo -->
  var module = { };

<script src="{{ cached_asset('vendor/echo.js', true) }}"></script>

<!-- Pusher -->
<script src="{{ cached_asset('vendor/pusher.min.js', true) }}"></script>

  window.Echo = new Echo({
    broadcaster: 'pusher',
    key: '{{ config('broadcasting.connections.pusher.key') }}',
    cluster: 'eu',
    encrypted: true

The var module = { }; is needed because how it's meant to be used with webpack I think, I picked that up from a Stack Overflow answer.

comments powered by Disqus