This article will share with you the following experience of using the front-end workflow under Laravel 9.x. I used Laravel Mix before, but now This time we will use the officially recommended vite tool and continue to use bootstrap 5. This will not only facilitate course scholars to master the latest front-end workflow, but also adjust their favorite styles with a low threshold. The most important thing is not to affect the learning progress and rhythm of the tutorial. [Recommended: laravel video tutorial]
Write in front
##Development environment:
Operation method
First of all, it is assumed that the reader has already learned the chapter "4.2. Style Beautification", and unfortunately is stuck. Secondly, both my Windows computer and Homestread environment can run Node.js. If Node.js is not installed under Windows, you can search and download it through a search engine. The installation process is fool-proof and I won’t go into details. First we do the following step according to the tutorial, but don’t execute it yetcomposer require laravel/ui:3.4.5 --dev
composer require laravel/ui // 发文时最新的版本是 4.0.1,对不住了版主,我自己偷摸的上到最新的版本惹 php artisan ui bootstrap
npm config set registry=https://registry.npm.taobao.org npm i
import { defineConfig } from 'vite'; import laravel from 'laravel-vite-plugin'; import path from 'path' export default defineConfig({ plugins: [ laravel([ 'resources/js/app.js', ]), ], resolve: { alias: { '~bootstrap': path.resolve(__dirname, 'node_modules/bootstrap'), } }, });
import './bootstrap'; // 以下为新增部分 import '../sass/app.scss' import * as bootstrap from 'bootstrap'
<link rel="stylesheet" href="{{ mix('css/app.css') }}"> <script src="{{ mix('js/app.js') }}"></script>
@vite(['resources/js/app.js'])
@yield('title', 'Weibo App') - Laravel 入门教程 @vite(['resources/js/app.js']) <--- here!@yield('content')
npm run build // 或者 npm run dev
Project deployment
After our code is uploaded to the remote git repository and then pulled to the production environment, vite uses the css and js files generated by npm run build They will not be included in git management, that is, you cannot include them with local git add -A. We need to find the .gitignore file in the root directory of the local development project and comment or delete the /public/build line, as follows/node_modules # /public/build <-- here /public/hot /public/storage /storage/*.key /vendor .env .env.backup .phpunit.result.cache Homestead.json Homestead.yaml auth.json npm-debug.log yarn-error.log /.idea /.vscode
Other tips
bootstrap 5 has deleted the original Jumbotron component of version 4, so you cannot see the corresponding style, which is normal. If you want to change it, please use your imagination and write one yourself. Regarding the chapter 4.4. Browser cache issues, if you use vite's front-end workflow, after the build is completed, the suffix will be automatically added to the style file, so you can ignore this chapter and use vite to work. This problem does not exist in the model, skip and continue learning. If you find that there are some places in this article where you can come up with your own methods, that would be best. My answer is not perfect. It would be best if everyone can come up with their own independent thinking questions or solutions during the learning process. As a result, everyone is welcome to explore solutions that suit you.Final Thoughts
Then compared to the method in the moderator's tutorial that lets us use a specific version to learn laravel, but I still like to follow the official documentation instructions, try to use native methods to achieve relevant effects, and use the latest version in all aspects, which is also considered a version. I would like to recommend a "rebellious and evil way" based on the standardization idea. I also need to solve the new version compatibility issues I encounter from time to time. In short, I hope this article can provide a new idea for beginners. After all, we are in the learning stage, not production environment development. The more we learn, the better.
Compared with my previous 8.x experience sharing, this one is about learning and adapting new technologies. I was also stumped when I encountered the new version content for the first time. Study on your own, find solutions, and then solve problems. Learning ideas is more important than learning methods. I believe that the later versions of 10.x and 100.x will have more new content and changes. Everyone must master the ideas for solving problems and be rigid Learning methods will not work. I hope all beginners on the learning journey will not give up this beautiful framework. It would be a pity!
The above is the detailed content of Detailed explanation of how to quickly install Bootstrap in Laravel9.x. For more information, please follow other related articles on the PHP Chinese website!