Adding bootstrap to Vue CLI project

I was having the same issue and this is what I ended up with however, I didn’t use Bootstrap alpha since the beta has since been released.


  1. Install Bootstrap along with its dependencies, jQuery and Popper.js:
npm install bootstrap@4.0.0-beta popper.js jquery --save-dev
  1. Edit your /build/webpack.dev.conf.js file to add a plugin for jQuery and Popper.js to deal with dependencies (you can read more about that in the Bootstrap docs):
plugins: [
    // ...
    new webpack.ProvidePlugin({
        $: 'jquery',
        jQuery: 'jquery',
        'window.jQuery': 'jquery',
        Popper: ['popper.js', 'default'],
        // In case you imported plugins individually, you must also require them here:
        Util: "exports-loader?Util!bootstrap/js/dist/util",
        Dropdown: "exports-loader?Dropdown!bootstrap/js/dist/dropdown",
        // ...
    })
    // ...
]
  1. Edit /src/main.js to import Bootstrap into the app’s entry point:
import Vue from 'vue'
import App from './App'
import router from './router'
import 'bootstrap' // ←
  1. Edit the App.vue’ file’s <style> portion to import Bootsrap into your app’s root css:
<template>
  <div id="app">
    <img src="./assets/logo.png">
    <router-view></router-view>
  </div>
</template>

<script>
export default {
  name: 'app'
}
</script>

<style>
#app {
  font-family: 'Avenir', Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
}

@import'~bootstrap/dist/css/bootstrap.css'
</style>
  1. Run your Vue app from the CLI
npm start

Screenshot of the Vue.js project


I had to add the @import rule after the #app selector, otherwise the scoped styling
would be canceled out by the Bootstrap import. I think there is a better way to do this so I will update my answer once I figure it out.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)