To Receiving Broadcasts notifications in laravel 5.3, I needed to include laravel-echo and pusher-js files into my blade templates.
I know that it is possible via npm package manager as has been explained in official laravel docs like this :
npm install --save laravel-echo pusher-js
And then in resouces/assets/js/app.js
file import it like this :
import Echo from "laravel-echo"
window.Echo = new Echo({
broadcaster: 'pusher',
key: 'your-pusher-key-here'
});
But I have a simple js file that all my scripts are Inside it and I did not use npm in my project and all my javascript files are as .js.
I went to laravel-echo github page But I did not find any js formatted file that I can use in my pages.
Is there any way other than npm to include laravel-echo?
Update:
I found that above codes are based on Typescript.I'm not familiar with Typescript. only I know that it can compile to pure javascript files. I am looking for laravel-echo as a js file that I could include it to my page and use included functions and methods. is it posibble?
By default, Laravel uses NPM to install both of these frontend packages.
laravel-echo - Libraries - cdnjs - The #1 free and open source CDN built to make life easier for developers.
Laravel Echo is a JavaScript library that makes it painless to subscribe to channels and listen for events broadcast by your server-side broadcasting driver. You may install Echo via the NPM package manager. In this example, we will also install the pusher-js package.
Pusher Channels acts as a realtime layer between your client and server events, maintaining persistent connections to the clients.
I don't know if it's actually possible, but I had the same question as you. I was wirthing my .js files into the public folder. When I tried to add echo, everything went wrong. So, this is my solution, but you will still need to use npm.
resources\assets\js
resources\assets\js\app.js
and add require(./filename.js);
npm install
npm run dev
app.js
file into my layout.That way I managed to keep one js file into my code and use laravel-echo.
Maybe there is another solution, but I did not tried it.
npm install
webpack.mix.js
the following way:mix.js('resources/assets/js/app.js', 'public/js').extract(['echo']);
public/js/vendor.js
file to your actual project.Theorically, this is all the script echo need to be functional. At this point, I think you will need to modify/delete some lines to make it work without the webpack initialisation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With