LazyCodet

a

17:03:55 27/5/2024 - 1 views -
Programming

Hot Reload in Laravel

When you change your source code and switch to the browser to press Refresh, it is so bad, that I will guide you to set up the project to make the browser automatically refresh when you press Ctrl + S. Get started.

​Get started

Install the dependency packages.

npm install --save-dev laravel-mix
npm install browser-sync browser-sync-webpack-plugin@^2.3.0 --save-dev --legacy-peer-deps

​Create a file named webpack.mix.cjs and put the content

const mix =require('laravel-mix');
mix.browserSync('127.0.0.1:8000');

​In package.json, add the following line inside scripts:

"watch": "mix watch"

​Usage

​Now you can serve your server

php artisan serve

​Open another terminal and run

npm run watch

​Now you can try to test, change any content in your code, and save to see the browser refresh automatically