In this tutorial, you are going to learn How To Install and Configure Vue 3 Application in Laravel 10 using Vite 3. You will get step by step guidance from scratch. At the end of this tutorial, you will be able to create and setup a basic Vue 3 application in laravel 10.
Vite is a Next Generation Frontend Development Tool for Modern Web Applications that focuses on speed and performance by improving the development experience. Vite leverages new advancements in its ecosystem by using native browser ES import to enable support for modern browsers without a build process.
Follow the below mentioned steps to install and setup Vue 3 app in Laravel 10 with the help of Vite:
Now, we will go through all the above steps one by one to achieve our goal.
First of all, lets install a fresh laravel 10 application. Open your terminal and run the following command:
composer create-project laravel/laravel l10vue3vite3app
Next, lets install all the required node packages by using NPM. Run below command in the terminal to do so:
npm install
Next, we need to install vue 3 and vue loader 3 for our application.
What is Vue Loader?
Vue Loader is a loader for webpack that allows you to define Vue components in a format called Single-File Components.
Run the following command in terminal to install vue and vue loader:
npm install vue@next vue-loader@next
Next, we have to install vitejs/plugin-vue package in our application. This package offers required dependencies to run vuejs application on vite. The vitejs/plugin-vue compiles the <template> blocks in SFCs. It also converts any encountered asset URLs into ESM imports.
Run the following command in terminal to install vitejs/plugin-vue:
npm install @vitejs/plugin-vue
Next, we have to setup vite configuration. Open vite.config.js and copy below code in it:
import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';
import vue from '@vitejs/plugin-vue';
export default defineConfig({
plugins: [
vue(),
laravel({
input: ['resources/css/app.css', 'resources/js/app.js'],
refresh: true,
}),
],
});
Next, we need to create a file resources/js/components/App.vue and copy below code in it:
<template>
<main>
<div class="container text-center">
<h1>How To Install and Configure Vue 3 App in Laravel 10 with Vite 3 - W3TechPoint</h1>
<blockquote class="text-center h5">Hi friends, in this tutorial you have learnt that how to install and configure a basic Vue 3 application in Laravel 10 using Vite 3.<br>To learn more, please visit our <strong><a href="https://www.laravelclick.com/category/laravel">Recommended Laravel Tutorials</a></strong> and improvise yourself.</blockquote>
</div>
</main>
</template>
Next, we have to import resources/js/components/App.vue inside resources/js/app.js file as follows:
import './bootstrap';
import {createApp} from 'vue';
import App from './components/App.vue';
createApp(App).mount("#app");
Next, we have to connect our Vue 3 component with a laravel blade file. Under resources/views folder, create a blade file app.blade.php and copy below code in it:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>How To Install and Configure Vue 3 Application in Laravel 10 using Vite 3</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css">
@vite('resources/css/app.css')
</head>
<body>
<div id="app"></div>
@vite('resources/js/app.js')
</body>
</html>
Next, we have to modify routes/web.php file as follows:
<?php
use Illuminate\Support\Facades\Route;
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider and all of them will
| be assigned to the "web" middleware group. Make something great!
|
*/
Route::get('/', function () {
return view('app');
});
Next, we need to setup APP_URL in .env file as follows:
APP_URL=http://127.0.0.1:8000
Welldone, now we have to start our development server to test our application.
Run below command in terminal to start vite development server:
npm run dev
Run below command in terminal to start laravel development server:
php artisan serve
Open below url in browser:
http://127.0.0.1:8000/
In this simplified tutorial, you will learn the simplest way to create a REST API application in Laravel 9 that will be authenticated using Laravel Sanctum.
In this simple and comprehensive tutorial you are going to learn how to install Laravel 10 and create a New Laravel 10 CRUD Application.
This tutorial will show you How To Install and Configure a Simple React 18 Application in Laravel 10 with Vite 3.