Santanu Biswas
Santanu Biswas

Reputation: 181

How to include Bootstrap-Vue in Laravel

How can I install/import/include Bootstrap Vue into my laravel project? I am new in Vue, I know how to install in a Vue JS application, but how can I add it laravel?

app.scss

// Fonts
@import url("https://fonts.googleapis.com/css?family=Nunito");

// Variables
@import "variables";

// Bootstrap
@import "~bootstrap/scss/bootstrap";

@import "node_modules/bootstrap/scss/bootstrap";
@import "node_modules/bootstrap-vue/src/index.scss";

.navbar-laravel {
    background-color: #fff;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.04);
}

app.js

    /**
     * First we will load all of this project's JavaScript dependencies which
     * includes Vue and other libraries. It is a great starting point when
     * building robust, powerful web applications using Vue and Laravel.
     */

    require("./bootstrap")

    window.Vue = require("vue")

    import BootstrapVue from "bootstrap-vue" //Importing

    Vue.use(BootstrapVue) // Teslling Vue to use this whole application

    /**
    * The following block of code may be used to automatically register your
    * Vue components. It will recursively scan this directory for the Vue
    * components and automatically register them with their "basename".
    *
    * Eg. ./components/ExampleComponent.vue -> <example-component></example-component>
    */

    // const files = require.context('./', true, /\.vue$/i);
    // files.keys().map(key => Vue.component(key.split('/').pop().split('.')[0], files(key).default));

    Vue.component(
        "example-component",
        require("./components/ExampleComponent.vue").default
    )

    /**
    * Next, we will create a fresh Vue application instance and attach it to
    * the page. Then, you may begin adding components to this application
    * or customize the JavaScript scaffolding to fit your unique needs.
    */

    const app = new Vue({
        el: "#app"
    })

Upvotes: 10

Views: 27104

Answers (4)

Vitaliy Maslyanko
Vitaliy Maslyanko

Reputation: 1

composer require laravel/ui
php artisan ui vue --auth
npm install
npm run dev
‍npm install bootstap-vue
@import 'node_modules/bootstrap-vue/src/index.scss';
import BootstrapVue from 'bootstrap-vue';
Vue.use(BootstrapVue);
npm run dev

look in this laravel 10 bootstrap vue vite

Upvotes: -3

Andrea Mauro
Andrea Mauro

Reputation: 842

Install your package with

npm install bootstrap-vue

or

yarn add bootstrap-vue

Then you can include globally your library by adding this row in your resources\js\app.js after window.Vue = require('vue');

Vue.use(require('bootstrap-vue'));

You can take a look to the official Vue documentation for plugins installation

Upvotes: 1

Karan Sadana
Karan Sadana

Reputation: 1373

You can do this simply by node and npm. install node in your system. and then open terminal from your project root directory like you do with laravel for running artisan commands.

when you open terminal. simply run

npm i bootstrap-vue // you can also give save falg to save in package.json file

Here am not installing vue .beacuse it's already installed in laravel if you check your app.js file, inside your resources directory and after successfully installing this you can import this in your app.js by

import BootstrapVue from 'bootstrap-vue' //Importing

Vue.use(BootstrapVue) // Telling Vue to use this in whole application

For css you can import this by simply

@import 'node_modules/bootstrap/scss/bootstrap';
@import 'node_modules/bootstrap-vue/src/index.scss';

in app.scss

After all configuration setup run

npm run dev //herewebpack do its work

or if you are in production, you can do this by

npm run production

Upvotes: 16

Manu
Manu

Reputation: 173

Just execute npm i vue bootstrap-vue bootstrap inside folder there you have package.json or manually change package.json. Then you have to add into ./resources/assets/js/bootstrap.js

import Vue from 'vue'
import BootstrapVue from 'bootstrap-vue'

Vue.use(BootstrapVue)

Upvotes: 2

Related Questions