Skip to content

Commit 79b377b

Browse files
authored
Vueon - Vue z Vite w Laravel
Instalcja Vue z Vite w Laravelu w wybranym katalogu (vue-project).
1 parent 1ef62bb commit 79b377b

File tree

5 files changed

+161
-2
lines changed

5 files changed

+161
-2
lines changed

README.md

Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,66 @@
1-
# vueon
2-
Instalcja Vue z Vite w Laravelu w wybranym katalogu (vue-project).
1+
# Vueon
2+
3+
Laravelu instalcja Vue z Vite w wybranym katalogu (vue-project).
4+
5+
### Project Laravela
6+
7+
```sh
8+
composer create-project laravel/laravel:^9.0 demo
9+
```
10+
11+
### Dodaj pakiet atomjoy/vueon
12+
13+
```sh
14+
cd demo
15+
composer require atomjoy/vueon 1.0.*
16+
composer update
17+
composer dump-autoload -o
18+
```
19+
20+
### Utwórz projekt Vue w Laravel
21+
22+
```sh
23+
npm init vue@latest
24+
cd vue-project
25+
npm install
26+
cd ..
27+
```
28+
29+
### Konfiguracja Vite
30+
31+
```sh
32+
# Laravel root dir
33+
php artisan vendor:publish --tag=vueon-config --force
34+
```
35+
36+
### Dodaj routes
37+
38+
```php
39+
<?php
40+
// Laravel routes
41+
Route::get('/welcome', function () {
42+
return view('welcome');
43+
});
44+
45+
// Laravel login auth redirect url
46+
Route::get('/login', function () {
47+
return view('vueon::vue');
48+
})->name('login');
49+
50+
// Vue all routes
51+
Route::fallback(function () {
52+
return view('vueon::vue');
53+
});
54+
```
55+
56+
### Uruchom aplikację
57+
58+
demo/vue-project
59+
60+
```sh
61+
cd vue-project
62+
# Vue build
63+
npm run build
64+
# Php Laravel server
65+
php ../artisan serve
66+
```

composer.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"name": "atomjoy/vueon",
3+
"description": "Vue custom directory in Laravel",
4+
"type": "library",
5+
"license": "MIT",
6+
"authors": [
7+
{
8+
"name": "Atomjoy",
9+
"email": "atomjoy.official@gmail.com"
10+
}
11+
],
12+
"minimum-stability": "dev",
13+
"require": {
14+
"openpayu/openpayu": "2.3.*"
15+
},
16+
"autoload": {
17+
"classmap": [
18+
"src/"
19+
]
20+
},
21+
"extra": {
22+
"laravel": {
23+
"providers": [
24+
"Vueon\\VueonServiceProvider"
25+
]
26+
}
27+
}
28+
}

resources/views/vue.blade.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@vueon()

src/VueonServiceProvider.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
namespace Vueon;
4+
5+
use Illuminate\Support\ServiceProvider;
6+
use Illuminate\Support\Facades\Blade;
7+
8+
class VueonServiceProvider extends ServiceProvider
9+
{
10+
/**
11+
* Register services.
12+
*
13+
* @return void
14+
*/
15+
public function register()
16+
{
17+
}
18+
19+
/**
20+
* Bootstrap services.
21+
*
22+
* @return void
23+
*/
24+
public function boot()
25+
{
26+
$this->loadViewsFrom(__DIR__ . '/../resources/views', 'vueon');
27+
28+
if ($this->app->runningInConsole()) {
29+
$this->publishes([
30+
__DIR__ . '/../vite' => base_path('vue-project')
31+
], 'vueon-config');
32+
33+
$this->publishes([
34+
__DIR__ . '/../resources/views' => resource_path('views/vendor/vueon'),
35+
], 'vueon-views');
36+
}
37+
38+
Blade::directive('vueon', function () {
39+
return file_get_contents(base_path() . '/public/index.html');
40+
});
41+
}
42+
}

vite/vite.config.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { fileURLToPath, URL } from 'node:url'
2+
3+
import { defineConfig } from 'vite'
4+
import vue from '@vitejs/plugin-vue'
5+
6+
// https://vitejs.dev/config/
7+
export default defineConfig({
8+
plugins: [vue()],
9+
resolve: {
10+
alias: {
11+
'@': fileURLToPath(new URL('./src', import.meta.url)),
12+
},
13+
},
14+
build: {
15+
outDir: '../public',
16+
rollupOptions: {
17+
output: {
18+
assetFileNames: 'vue/[ext]/[name][extname]',
19+
chunkFileNames: 'vue/chunks/[name].[hash].js',
20+
entryFileNames: 'vue/js/[name].[hash].js',
21+
},
22+
},
23+
},
24+
})

0 commit comments

Comments
 (0)