How to add and customize Bootstrap in Nuxt.js
Tags: javascript, bootstrap, nuxt, webdesign
Published: 2020-12-28 07:52:39

---
title: How to add and customize Bootstrap in Nuxt.js
published: true
date: 2020-12-28 07:07:11 UTC
tags: javascript,bootstrap,nuxt,webdesign
canonical_url: https://www.ravsam.in/blog/how-to-add-customize-bootstrap-in-nuxtjs/
---

#### Learn how to improve the look and feel of a Nuxt project by configuring the default Bootstrap behavior.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/cx4kt3rhzg0udbz99t9t.png)

> You can also read this article directly on [RavSam’s blog](https://www.ravsam.in/blog/how-to-add-customize-bootstrap-in-nuxtjs/). We publish our articles on Medium after a week.

Configuring things in any framework is always tricky especially when we are just starting. We will learn today that how can we add and customize Bootstrap in our Nuxt project. Once we go through this guide, we will get an overall idea of how to make things work in Nuxt. By learning how to setup Bootstrap, we can install Popper.js and JQuery as well which are peer dependencies for Bootstrap.

#### Installing Bootstrap

Before starting, let us install the required NPM packages. We will install [bootstrap](https://getbootstrap.com) and optionally [bootstrap-vue](https://bootstrap-vue.org) if we want to use Bootstrap Vue components.

Since we are going to create custom _SCSS_ files, we need to install some dev dependencies as well. In this case, we will install _sass-loader_ and _node-sass_.

```bash
npm install --save bootstrap bootstrap-vue
npm install --save-dev sass-loader node-sass
```

#### Creating a Custom SCSS

Let us now create a new _scss_ file in the assets/scss directory, and name it _custom.scss_. In this file, we need to import Bootstrap’s bootstrap.scss. Let us add the following styling to change the default color system of Bootstrap.

```sass
$theme-colors: (
  'primary': #145bea,
  'secondary': #833bec,
  'success': #1ce1ac,
  'info': #ff7d50,
  'warning': #ffbe0b,
  'danger': #ff007f,
  'light': #c0ccda,
  'dark': #001738,
);

@import '~/node_modules/bootstrap/scss/bootstrap.scss';
```

> We can import individual _scss_ files as well but as the project grows we need to use all the modules. It is of course a good idea to only import what is needed. So instead of worrying about increased module size, we can use [PurgeCSS](https://purgecss.com/guides/nuxt.html) plugin for Nuxt to remove unused CSS from our project when we build it for production.

#### Importing Bootstrap Vue

Using Bootstrap Vue in our project is really simple. We need to create a plugin and install it via Vue.use() to access Vue components globally in our project. Let us create a bootstrap.js file in the _plugins_ directory and add the following code:

```js
import Vue from 'vue'
import { BootstrapVue, IconsPlugin } from 'bootstrap-vue'
Vue.use(BootstrapVue)
Vue.use(IconsPlugin)
```

> Importing **IconsPlugin** is optional. We can skip it in case we prefer to use FontAwesome icons or any other icon library.

#### Configuring Nuxt Config

The final step is to configure some settings in nuxt.config.js. Let us change our config to look like this:

```js
export default {
  
  ...

  // add your custom sass file
  css: ['@/assets/scss/custom.scss', ...],

  // add your plugin
  plugins: ['~/plugins/bootstrap.js', ...],

  // add bootstrap-vue module for nuxt
  modules: ['bootstrap-vue/nuxt', ...],

  // specify module rules for css and scss
  module: {
    rules: [
      {
        test: /\.s[ac]ss$/i,
        use: ['style-loader', 'css-loader', 'sass-loader'],
      },
    ],
  },
  
  // use these settings to use custom css
  bootstrapVue: {
    bootstrapCSS: false,
    icons: true,
  },

  ...
}
```

That’s it. We have set up our Nuxt project to use customize the default Bootstrap settings. We can override any Bootstrap defaults and customize the look and feel of our project to our advantage. If you any doubts, let us know in the comments below.

#### About RavSam Web Solutions

We are helping businesses migrate their Single Page Applications to Server Side Rendered apps along with Client Side Rendering using Nuxt. Reach out to us to know more about our website development services, or anything else.

#### You might also enjoy reading

- [How to achieve a redesign of your website](https://www.ravsam.in/blog/redesigning-your-website/)
- [Use Humans.txt to credit your team for a project](https://www.ravsam.in/blog/use-humans-txt-to-credit-your-team-for-project/)

* * *