Run Laravel Vite Vue.js build on production without Artisan
I am a newbie learning Vue.js and I am using it with Laravel. I have decent experience with Laravel. Previously, without any frontend setup, I simply used to go to http://localhost/my-project/public and my Laravel homepage would display as everything used to be in the public directory.
Now I am using Vue with Vite as my build tool. The build assets by Vite are placed inside public\build directory. I run the dev environment using npm run dev and php artisan server and I can access the app on http://localhost:8000 but how do I access my app without using Artisan. How do I deploy my Laravel-Vue app on production without any dev servers running?
@tykus Yes. It builds and places the assets inside public\build directory. Now how do I run my app without using artisan? When I try to access the app using url http://localhost/my-project/public there is an error in the console saying [Vue Router warn]: No match found for location with path "/my-project/public/"
My routes/web.php file content is:
Route::any('/', function () {
return view('welcome');
});
Route::any('/{slug}', function () {
return view('welcome');
})->where('slug', '([A-z\d\-\/_.]+)?');
I am using vue-router to manage my frontend routes.
@tykus I am not trying to run dev server on production. Instead, I wanted a way to run my production build without using any dev servers.
I am using xampp on my local environement right now. I will be using an Apache server on my production server as well. I wanted a way to run my app without using any dev server commands directly on port 80 with URL like http://localhost/my-project
Check your resources/views/app.blade.php file. You should have @vite(['resources/js/app.js']) in the head section of the file. Remove any unnecessary extras.
Delete the public/hot file.
Run the following command:
npm run dev
You can deploy as normal. Do NOT include the 'node_modules' folder.