Variant 1. Add it to nuxt.config.ts
import { defineNuxtConfig } from 'nuxt'
export default defineNuxtConfig({
app: {
head: {
link: [
{ rel: 'stylesheet', href: 'https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css', integrity: 'sha384-0evHe/X+R7YkIZDRvuzKMRqM+OrBnVFBL6DOitfPri4tjfHxaWutUpFmBp4vmVor', crossorigin: 'anonymous' }
],
script: [
{ src: 'https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js', integrity: 'sha384-pprn3073KE6tl6bjs2QrFaJGz5/SUsLqktiwsUTF55Jfv3qYSDhgCecCxMW52nD2', crossorigin: 'anonymous' }
]
}
}
})
Downside: needs manual version control, you can't use SASS features.
Variant 2.
- Install bootstrap alongside @popperjs/core
yarn add bootstrap @popperjs/core
- Create
plugins/useBootstrap.client.ts file
import bootstrap from 'bootstrap/dist/js/bootstrap.bundle'
export default defineNuxtPlugin(nuxtApp => {
nuxtApp.provide('bootstrap', bootstrap)
})
No need to import it manually, since Nuxt3 will do it for you. Bootstrap JS should be available in your components/pages through
const { $bootstrap } = useNuxtApp()
- Create
assets/styles/main.scss file
@import 'bootstrap/scss/bootstrap';
- Add it to
nuxt.config.ts
import { defineNuxtConfig } from 'nuxt'
export default defineNuxtConfig({
css: ['~/assets/styles/main.scss']
})