Laravel Sail + Vue 3 best practice
I created my first Laravel Sail yesterday but I've a tiny problem with Vue because creating a frontend in a separated folder caused some headache to me. As there are two different package.json one in the project root and the other in frontend folder. So whenever I need to execute npm run dev I've to use --prefix for pointing to frontend folder. Same issue with npx I've to point to the frontend by selecting the workspace!!!
I definitely suspect there is something wrong with my practice. So may you please guide me to the best practice to use Laravel Sail + Laravel backend api + Vue frontend?
Steps I did to create my project structure:
-
curl -s https://laravel.build/example-app | bash - Added
alias sail='[ -f sail ] && bash sail || bash vendor/bin/sail'into~/.bashrc - executed
sail upfrom project's root -
sail npm init vite frontend -
cd ./frontend -
sail npm i---> ERROR because there is no sail in sub-folder -
cd .. -
sail npm i --prefix ./frontend -
sail npm run dev --prefix ./frontend---> ERROR because it hasn't--host - Modified
frontend/package.jsontodev": "vite --host" -
sail npm run dev --prefix ./frontend -
sail npm install --prefix ./frontend/ -D tailwindcss postcss autoprefixer -
sail npx --prefix ./frontend/ tailwindcss init -p---> ERRORnpxdoesn't accept--prefix -
sail npx -w ./frontend/ tailwindcss init -p---> ERROR there is no workspace configured! -
cd frontend/ -
ln -s ../vendor/laravel/sail/bin/sail sail -
./sail npx tailwindcss init -p -
rm ./sail -
cd ..
As you can see the calling --prefix really lame solution and the most stupid steps were 13... 18 because I needed to find a workaround by creating a symbolic link then delete it once again... really lame!
BTW, in 17. step although the current path is ./frontend but npx generates the entries in project's root package.json instead of frontend/package.json so I cut them manually from package.json to frontend/package.json !!!
Please or to participate in this conversation.