I am new to Laravel and I start my Laravel project using php artisan serve
but I found that I also have to load Vite from another command prompt using npm run dev
in order to make Laravel project run properly is there any method to autoload Vite when I do php artisan serve
when Vite is loaded my code works correctly
scripts in package.json
"scripts": {
"dev": "vite",
"build": "vite build"
},
Cause of Problem:
In older versions of
Laravel
we were usinglaravel-mix
package but nowlaravel
js compiling engine is shifted tovite
and it is much more faster.In the case of
mix
engine whenever we runnpm run dev
generate compiled js code inpublic/js
directory. and due to it we need to refresh page manually everytime.But now In
vite
when you runnpm run dev
it just starts avite server
that continuously monitor your changes and reflect those changes on screen immediately. but it’s not generatecompiled js
files inpublic/js
directorySo, when your
vite
server not running it shows above error.Solution:
If you want to run
laravel
without runingvite server
bynpm run dev
you will need to runnpm run build
. It will generatecompiled js
files inpublic/js
directory so then you will not have need to runvite server
.