Does anyone know if there is a way to run the code changes in a Laravel project without refreshing the page every time.
I know that to see the changes I need to
php artisan serve
but I do it every time and it is kind of frustrating.
Thank you anyways.
You can achieve this with Laravel Mix.
According to this part of the documentation, you need to edit your webpack.mix.js
file, and add this to the end:
mix.browserSync('127.0.0.1:8000');
It needs to match to the output of the php artisan serve
command, where you found a line something like this:
Laravel development server started: <http://127.0.0.1:8000>
After this, you have to run the php artisan serve
, and the npm run watch
command simultaneously. You must leave to run both commands while you edit your files.
Note: The first time you run the npm run watch
, it installs additional components. But the command output is quite clear on that. If everything is in order, Laravel Mix automatically opens your browser with http://localhost:3000
, or something like this.
add in webpack.max.js file in laravel
mix.browserSync('127.0.0.1:8000');
then run this command
> npm install browser-sync [email protected] --save-dev --production=false
after this run npm run watch
> Browsersync automatic run your port 3000
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