Detailed explanation of how to quickly install Bootstrap in Laravel9.x
Elegantly and easily install the Bootstrap framework in Laravel 9.x (vite article)
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:
- The general environment is Windows 10/11 Homestead, both of which are the latest stable versions
- Node.js is installed on both platforms
- Laravel version is 9.x (I am using the latest 9.38.0 when posting). For other things not mentioned, follow the 9.x version tutorial.
- Do not use Laravel Mix, use the officially recommended new front-end packaging tool vite to complete the style modification tasks in the tutorial.
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
- dev can be adjusted at any time when it is suitable for development. Your modifications will take effect in real time and automatically. It is recommended to keep it open during development. Just hang a window in the background.
- build will be processed in one step and output css and js files. It will only be executed once and will not be automatic. It is suitable for the final release stage.
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!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



How to use Bootstrap to get the value of the search bar: Determines the ID or name of the search bar. Use JavaScript to get DOM elements. Gets the value of the element. Perform the required actions.

Using Bootstrap in Vue.js is divided into five steps: Install Bootstrap. Import Bootstrap in main.js. Use the Bootstrap component directly in the template. Optional: Custom style. Optional: Use plug-ins.

There are two ways to create a Bootstrap split line: using the tag, which creates a horizontal split line. Use the CSS border property to create custom style split lines.

Use Bootstrap to implement vertical centering: flexbox method: Use the d-flex, justify-content-center, and align-items-center classes to place elements in the flexbox container. align-items-center class method: For browsers that do not support flexbox, use the align-items-center class, provided that the parent element has a defined height.

To adjust the size of elements in Bootstrap, you can use the dimension class, which includes: adjusting width: .col-, .w-, .mw-adjust height: .h-, .min-h-, .max-h-

To set up the Bootstrap framework, you need to follow these steps: 1. Reference the Bootstrap file via CDN; 2. Download and host the file on your own server; 3. Include the Bootstrap file in HTML; 4. Compile Sass/Less as needed; 5. Import a custom file (optional). Once setup is complete, you can use Bootstrap's grid systems, components, and styles to create responsive websites and applications.

There are several ways to insert images in Bootstrap: insert images directly, using the HTML img tag. With the Bootstrap image component, you can provide responsive images and more styles. Set the image size, use the img-fluid class to make the image adaptable. Set the border, using the img-bordered class. Set the rounded corners and use the img-rounded class. Set the shadow, use the shadow class. Resize and position the image, using CSS style. Using the background image, use the background-image CSS property.

How to use the Bootstrap button? Introduce Bootstrap CSS to create button elements and add Bootstrap button class to add button text
