From 01f8bd1268fc9ab398be725b53a92d1f848cdeb1 Mon Sep 17 00:00:00 2001 From: George Chitechi Date: Thu, 23 Jan 2025 05:58:01 +0300 Subject: [PATCH] Update to Livewire 3 --- README.md | 6 +- composer.json | 9 +- config/config.php | 4 + resources/install/package.json.stub | 26 ++-- resources/install/resources/js/app.js.stub | 6 +- .../install/resources/js/bootstrap.js.stub | 15 +-- .../install/resources/sass/app.scss.stub | 9 +- .../resources/views/home.blade.php.stub | 2 +- .../views/layouts/app.blade.php.stub | 39 +++--- .../resources/views/welcome.blade.php.stub | 2 +- resources/install/vite.config.js.stub | 17 +++ src/Commands/LivewireCrudGenerator.php | 39 +----- src/Commands/LivewireGeneratorCommand.php | 35 +++--- src/Commands/LivewireInstall.php | 116 +++++++++--------- src/ModelGenerator.php | 12 +- src/stubs/Livewire.stub | 82 ++++++------- src/stubs/views/form-field.stub | 8 +- src/stubs/views/modals.stub | 22 ++++ src/stubs/views/view.stub | 43 +++---- 19 files changed, 244 insertions(+), 248 deletions(-) create mode 100644 resources/install/vite.config.js.stub create mode 100644 src/stubs/views/modals.stub diff --git a/README.md b/README.md index 91522fc..b824943 100644 --- a/README.md +++ b/README.md @@ -25,9 +25,9 @@ php artisan crud:install ``` **This command will perfom below actions: - * Compile css/js based on `bootstrap and fontawesome/free`. - * Run `npm install && run dev` - * Flush *node_modules* files from you folder. + * Compile css/js based on `bootstrap and bootstrap-icons`. + * Run `npm install && run build` + * Flush *node_modules* files from your folder. If you choose to scaffold authentication this command will run `php artisan ui:auth` to generate Auth scaffolds using `laravel/ui` package. You can skip this step if your app has authentication already. diff --git a/composer.json b/composer.json index d602d06..f03a8e4 100644 --- a/composer.json +++ b/composer.json @@ -17,9 +17,9 @@ ], "require": { "php": "^7|^8", - "laravel/framework": "^6|^7|^8|<9.19", - "laravel/ui": "^2|^3|^4", - "livewire/livewire": "^2" + "laravel/framework": ">=9.19", + "laravel/ui": "^4", + "livewire/livewire": "^3" }, "require-dev": {}, "autoload": { @@ -35,7 +35,6 @@ "scripts": { "test": "vendor/bin/phpunit", "test-coverage": "vendor/bin/phpunit --coverage-html coverage" - }, "config": { "sort-packages": true @@ -50,4 +49,4 @@ } } } -} +} \ No newline at end of file diff --git a/config/config.php b/config/config.php index 0b733ec..72657e5 100644 --- a/config/config.php +++ b/config/config.php @@ -46,4 +46,8 @@ 'namespace' => 'App\Http\Controllers', ], + 'livewire' => [ + 'namespace' => 'App\Livewire', + ], + ]; diff --git a/resources/install/package.json.stub b/resources/install/package.json.stub index db1c209..38f6c1d 100644 --- a/resources/install/package.json.stub +++ b/resources/install/package.json.stub @@ -1,25 +1,19 @@ { "private": true, + "type": "module", "scripts": { - "dev": "npm run development", - "development": "mix", - "watch": "mix watch", - "watch-poll": "mix watch -- --watch-options-poll=1000", - "hot": "mix watch --hot", - "prod": "npm run production", - "production": "mix --production" + "dev": "vite", + "build": "vite build" }, "devDependencies": { + "@popperjs/core": "^2.11", "axios": "^1.7", - "bootstrap": "^4.6", + "bootstrap": "^5.3", "bootstrap-icons": "^1.11", - "cross-env": "^7.0", - "jquery": "^3.7.1", - "laravel-mix": "^6.0", - "lodash": "^4.17.21", - "popper.js": "^1.16.1", - "resolve-url-loader": "^5.0.0", - "sass": "^1.77.8", - "sass-loader": "^14.2.1" + "laravel-vite-plugin": "^1.0", + "lodash": "^4.17", + "postcss": "^8.4", + "sass": "1.76.0", + "vite": "^6.0" } } \ No newline at end of file diff --git a/resources/install/resources/js/app.js.stub b/resources/install/resources/js/app.js.stub index c8b4b8d..616fcad 100644 --- a/resources/install/resources/js/app.js.stub +++ b/resources/install/resources/js/app.js.stub @@ -1 +1,5 @@ -require('./bootstrap'); \ No newline at end of file +//Import Bootstrap File +import './bootstrap'; + +// Import our custom CSS +import '../sass/app.scss' \ No newline at end of file diff --git a/resources/install/resources/js/bootstrap.js.stub b/resources/install/resources/js/bootstrap.js.stub index df472b0..fcd82bf 100644 --- a/resources/install/resources/js/bootstrap.js.stub +++ b/resources/install/resources/js/bootstrap.js.stub @@ -1,11 +1,12 @@ -window._ = require('lodash'); +import _ from 'lodash'; +window._ = _; -try { - window.Popper = require('popper.js').default; - window.$ = window.jQuery = require('jquery'); - require('bootstrap'); -} catch (e) {} +// Import all of Bootstrap's JS +import * as bootstrap from 'bootstrap' +window.bootstrap = bootstrap; -window.axios = require('axios'); +// Import Axios +import axios from 'axios'; +window.axios = axios; window.axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest'; \ No newline at end of file diff --git a/resources/install/resources/sass/app.scss.stub b/resources/install/resources/sass/app.scss.stub index b5b18b1..5edfc70 100644 --- a/resources/install/resources/sass/app.scss.stub +++ b/resources/install/resources/sass/app.scss.stub @@ -1,10 +1,11 @@ // Fonts @import url('https://fonts.bunny.net/css?family=Nunito'); + +// Variables @import 'variables'; -@import '~bootstrap/scss/bootstrap'; +// Bootstrap +@import 'bootstrap/scss/bootstrap'; // Bootstrap Icons -@import '~bootstrap-icons/font/bootstrap-icons.css'; - -@import '../css/app.css'; \ No newline at end of file +@import 'bootstrap-icons/font/bootstrap-icons.css'; \ No newline at end of file diff --git a/resources/install/resources/views/home.blade.php.stub b/resources/install/resources/views/home.blade.php.stub index 9dea863..e2d9f68 100644 --- a/resources/install/resources/views/home.blade.php.stub +++ b/resources/install/resources/views/home.blade.php.stub @@ -5,7 +5,7 @@
-
@yield('title')
+
@yield('title')
Hi {{ Auth::user()->name }}, {{ __('You are logged in to ') }}{{ config('app.name', 'Laravel') }}

diff --git a/resources/install/resources/views/layouts/app.blade.php.stub b/resources/install/resources/views/layouts/app.blade.php.stub index 6f20c89..495f629 100644 --- a/resources/install/resources/views/layouts/app.blade.php.stub +++ b/resources/install/resources/views/layouts/app.blade.php.stub @@ -7,18 +7,14 @@ - @hasSection('title') @yield('title') | @endif {{ config('app.name', 'Laravel') }} - - - + @hasSection('title') @yield('title') | @endif {{ config('app.name', 'Laravel') }} - + - - - @livewireStyles + + @vite(['resources/js/app.js'])
@@ -27,7 +23,7 @@ {{ config('app.name', 'Laravel') }} - @@ -38,9 +34,9 @@ @endauth() - + -