Deploy Vue CLI to Laravel 8

Before we start:

You should have the compiled version of your Vue js SPA from Vue CLI

Lets start…

# create a new Laravel project
> laravel new laravel-cli
> cd laravel-cli
# delete the following files and folders:
package.json
webpack.mix.js
public/.htaccess
public/favicon.ico
public/robots.txt
public/web.config
resources/js folder
resources/css folder
# public folder may contains the following files/folders:
index.php
index.html
css folder
img folder
js folder
favicon.ico
***Note: this can be different from your compiled files
# remove the default route:
Route::get('/', function () {
return view('welcome');
});
# add the following route:
Route::any('{all}', function () {
return File::get(public_path() . '/index.html');
})->where('all', '^(?!api).*$');
*** The new route will return our index.html file back to the request
# add the following route:
Route::get('/test', function (Request $request) {
return ['mode' => 'test'];
});
> php artisan servedefault url: http://127.0.0.1:8000
# access http://127.0.0.1:8000/api/test
# our API should return the following json:
{"mode":"test"}

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store