英文:
How to integrate bootstrap 5 in nuxtjs?
问题
首先,我尝试集成bootstrap-vue,但它支持bootstrap 4,而且还支持vue2。所以我正在尝试集成bootstrap 5,按照以下步骤进行,不做任何更改:
- 我安装了bootstrap包(通过npm)。
- 然后我将编辑nuxt.config.ts文件,将css文件添加到css数组中,并将脚本添加到插件入口。
这是最终结果:
export default defineNuxtConfig({
plugins: [
{
src: "~/node_modules/bootstrap/dist/js/bootstrap.bundle.min.js",
mode: "clients",
},
],
css: [
"~/node_modules/bootstrap/dist/css/bootstrap.min.css",
"@/assets/css/global.css",
],
});
现在css正常工作,问题仍然存在于js文件中。我不明白为什么,但没有任何动画效果都无法正常工作,从下拉菜单到轮播图都有问题。
英文:
First, I tried integrating bootstrap-vue, but that supports bootstrap 4, and worse vue2.
So I'm trying to integrate bootstrap 5 without any changes by following these steps:
- I install the bootstrap package (via npm).
- So I'm going to edit the nuxt.config.ts file, adding the css files in the css array and the script in the plugin entry.
This is the final result:
export default defineNuxtConfig({
plugins: [
{
src: "~/node_modules/bootstrap/dist/js/bootstrap.bundle.min.js",
mode: "clients",
},
],
css: [
"~/node_modules/bootstrap/dist/css/bootstrap.min.css",
"@/assets/css/global.css",
],
});
Now the css works fine, the problem remains with the js file.
I don't understand why, but nothing animated works, starting from dropdowns, to carousels.
答案1
得分: 1
I followed some older StackOverflow answers and managed (I think) to create working demo with newest Nuxt 3 and Bootstrap 5 like this:
https://stackblitz.com/edit/github-bebg1r-j6lqxm
The key things:
- In
package.json
add and install dependencies forbootstrap
,sass
, andsass-loader
- Create
.scss
file in/assets
folder containing@import 'bootstrap/scss/bootstrap';
- Load this file in
nuxt.config.ts
viacss: ['~/assets/main.scss']
- Plugin to load JS bundle in
/plugins/bootstrap.client.ts
英文:
I followed some older StackOverflow answers and managed (I think) to create working demo with newest Nuxt 3 and Bootstrap 5 like this:
https://stackblitz.com/edit/github-bebg1r-j6lqxm
The key things:
- In
package.json
add and install dependencies forbootstrap
,sass
andsass-loader
- Create
.scss
file in/assets
folder containg@import 'bootstrap/scss/bootstrap';
- Load this file in
nuxt.config.ts
viacss: ['~/assets/main.scss']
- Plugin to load JS bundle in
/plugins/bootstrap.client.ts
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论