In my Vue 2 project I installed Bootstrap 5.3 using NPM, but my custom CSS stylesheet in the index.html code is not overriding Bootstrap's CSS.
I had no problems when getting Bootstrap via CDN. Also, my custom CSS added directly in the components are correctly overriding Bootstrap's CSS. It's just my global stylesheet in index.html that is being overridden.
My main.js looks like this:
import { BootstrapVue, IconsPlugin } from 'bootstrap-vue'
let Bootstrap = require('bootstrap')
import 'bootstrap/dist/css/bootstrap.css'
import 'bootstrap-vue/dist/bootstrap-vue.css'
import Vue from 'vue'
import App from './App.vue'
import router from './router'
import Vuex from 'vuex'
import store from './store'
import VueI18n from 'vue-i18n'
Vue.use(Vuex)
Vue.use(VueI18n)
Vue.use(Bootstrap)
Vue.use(BootstrapVue)
Vue.use(IconsPlugin)
new Vue({
store: store,
router,
i18n,
beforeCreate() { this.$store.commit('initialiseStore');},
render: h => h(App),
}).$mount('#app')
And my index.html looks like this:
<!DOCTYPE html>
<html lang="pt-br">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="icon" href="<%= BASE_URL %>favicon.ico">
<link rel="stylesheet" href="<%= BASE_URL %>media/css/layout.css?v2">
<link rel="stylesheet" href="<%= BASE_URL %>media/css/mobile.css?v1">
I was able to make it work by removing my stylesheet reference from index.html and inserting the code below in the App.vue:
<style lang="scss">
@import '/media/css/layout.css';
@import '/media/css/mobile.css';
</style>
But I don't know if calling my custom stylesheet in App.vue is the correct way to do this. And should I still have to reference Bootstrap in index.html if it is installed by NPM? If yes, how can I do this if its folder is in node_modules?