I followed the following guide:
https://getbootstrap.com/docs/5.2/getting-started/vite/
and I still get all sorts of errors, sometimes file is not found or sometimes I just don't see the bootstrap design.
I installed Bootstrap using npm:
npm install bootstrap@5.2.2
Then I installed scss using npm:
npm i --save-dev sass
Then I added the following to vite.config.js
:
resolve: {
alias: {
'~bootstrap': path.resolve(__dirname, 'nodes_modules/bootstrap'),
}
}
Also added the following to /resources/app.js
:
import '/resources/scss/styles.scss'
import * as bootstrap from 'bootstrap';
I also created a new scss
folder in /resources
and placed the following styles.scss
file inside:
// Import all of Bootstrap's CSS
@import "~bootstrap/scss/bootstrap";
But when I use npm run dev
or build
, the Bootstrap styling don't show up, or I'm getting error about files not existing, for example:
[plugin:vite:css] [sass] ENOENT: no such file or directory, open '/var/www/myapp/nodes_modules/bootstrap/scss/bootstrap
Install Bootstrap 5 in Laravel 9 with Vite
npm i bootstrap sass @popperjs/core --save-dev
import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';
export default defineConfig({
plugins: [
laravel({
input: ['resources/css/app.scss', 'resources/js/app.js'],
refresh: true,
}),
],
});
In the resources/css/app.scss file import Bootstrap by adding the following line of code
@import 'bootstrap/scss/bootstrap';
In the file resources/js/bootstrap.js add the following lines
...
import * as Popper from '@popperjs/core'
window.Popper = Popper
import 'bootstrap'
...
In the resources/views/welcome.blade.php file, paste the following code before the closing tag:
...
@vite(['resources/js/app.js', 'resources/css/app.scss'])
</head>
<body>
...
npm run dev
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.