Skip to content

Commit 7bdf820

Browse files
authored
Vue 3 in Laravel 10
How To Install Vue 3 in Laravel 10 with Vite.
1 parent 2ae6fba commit 7bdf820

File tree

1 file changed

+126
-1
lines changed

1 file changed

+126
-1
lines changed

README.md

Lines changed: 126 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,127 @@
1-
# laravel-vue3-vite-config
1+
# Vue 3 in Laravel
2+
23
How To Install Vue 3 in Laravel 10 with Vite.
4+
5+
## Create project
6+
7+
```sh
8+
composer create-project --prefer-dist laravel/laravel:^10.0 laravel-vue
9+
cd laravel-vue
10+
```
11+
12+
## Install
13+
14+
```sh
15+
npm install
16+
npm install vue@next vue-loader@next
17+
npm install @vitejs/plugin-vue
18+
```
19+
20+
## Config
21+
22+
### vite.config.js
23+
24+
```js
25+
import { defineConfig } from 'vite';
26+
import laravel from 'laravel-vite-plugin';
27+
import vue from '@vitejs/plugin-vue'
28+
29+
export default defineConfig({
30+
base: '/', // Default route is /build directory
31+
plugins: [
32+
laravel({
33+
input: ['resources/css/app.css', 'resources/js/app.js'],
34+
refresh: true,
35+
}),
36+
vue({
37+
template: {
38+
transformAssetUrls: {
39+
base: null,
40+
includeAbsolute: false,
41+
},
42+
},
43+
}),
44+
],
45+
});
46+
```
47+
48+
### resources/js/app.js
49+
50+
```js
51+
require('./bootstrap');
52+
53+
import {createApp} from 'vue'
54+
55+
import App from './App.vue'
56+
57+
createApp(App).mount("#app")
58+
```
59+
60+
### resources/js/App.vue
61+
62+
```vue
63+
<template>
64+
How To Install Vue 3 in Laravel 10 with Vite.
65+
</template>
66+
<script setup></script>
67+
```
68+
69+
### welcome.blade.php
70+
71+
```html
72+
<!DOCTYPE html>
73+
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
74+
<head>
75+
<meta charset="utf-8">
76+
<meta name="viewport" content="width=device-width, initial-scale=1">
77+
<title>How To Install Vue 3 in Laravel 10 with Vite</title>
78+
79+
@vite('resources/css/app.css')
80+
</head>
81+
<body>
82+
<div id="app"></div>
83+
84+
@vite('resources/js/app.js')
85+
</body>
86+
</html>
87+
```
88+
89+
### .env
90+
91+
```sh
92+
APP_URL=http://localhost:8000
93+
```
94+
95+
### routes/web.php
96+
97+
```php
98+
<?php
99+
100+
// Last route
101+
Route::fallback(function() {
102+
return view('welcome');
103+
});
104+
```
105+
106+
## Build and run
107+
108+
```sh
109+
npm run build
110+
php artisan serve
111+
```
112+
113+
## Install optional packages
114+
115+
```sh
116+
npm install axios
117+
npm install pinia
118+
npm install vue-i18n@9
119+
npm install vue-router@4
120+
npm install @googlemaps/js-api-loader
121+
```
122+
123+
## Links
124+
125+
- <https://router.vuejs.org/guide>
126+
- <https://router.vuejs.org/guide/advanced/composition-api.html>
127+
- <https://pinia.vuejs.org/getting-started.html>

0 commit comments

Comments
 (0)