A Webpack plugin for automatic BootstrapVue components and directives importing, mainly for treeshaking
npm install bootstrap-vue-loaderExample of chunks distribution between build with global BoostrapVue import and build with the plugin:
!With global import
!With loader
npm install -D bootstrap-vue-loader
yarn add -D bootstrap-vue-loader
vue.config.js
``javascript`
const BootstrapVueLoader = require('bootstrap-vue-loader')
module.exports = {
configureWebpack: {
plugins: [ new BootstrapVueLoader() ]
}
}
Remember to REMOVE global BootstrapVue import!
`javascript`
// import BootstrapVue from 'bootstrap-vue'
// Vue.use(BootstrapVue)dev/vue-cli
Check example configured project: .`$3
nuxt.config.jsjavascript
import BootstrapVueLoader from 'bootstrap-vue-loader'
export default {
css: [
'bootstrap/dist/css/bootstrap.min.css',
'bootstrap-vue/dist/bootstrap-vue.css'
],
build: {
plugins: [
new BootstrapVueLoader()
]
}
}
``
With above config there is no need for global BootstrapVue module.
Remove it if you already have it configured: `
modules: [
// 'bootstrap-vue/nuxt',
],dev/nuxt
Check example configured project: .
* If you use only some of the available BoostrapVue components and don't want to take care of manual importing but still you want to minimize the bundle size (smaller bundle == faster page).
* If you have a big project with a lot of pages, and you want to achieve a better distribution of chunks size (no one wants to ship to the user components that are not used on the current page)
javascript
import { ModalPlugin } from 'bootstrap-vue'
Vue.use(ModalPlugin)
`$3
nuxt.config.js
`javascript
import BootstrapVueLoader from 'bootstrap-vue-loader' export default {
modules: [
'bootstrap-vue/nuxt',
],
bootstrapVue: {
componentPlugins: ['BVModalPlugin'],
},
build: {
plugins: [
new BootstrapVueLoader()
]
}
}
`Want to play with it?
Just go to /dev directory, install dependencies (yarn) and run yarn serve`.