I'm using vue-cli + bootstrap-vue. I can't figure out why and how bootstrap mixins not working at all despite I imported Bootstrap like this (in my main.js)
import 'bootstrap/scss/bootstrap-grid.scss'
import 'bootstrap-vue/dist/bootstrap-vue.css'
Vue.use(BootstrapVue);
And trying to use some mixins inside component
<style lang="scss" scoped>
.xxx {
@include media-breakpoint-up(md) {
display: none;
}
}
</style>
But if I import missing files everything will be fine:
<style lang="scss" scoped>
@import "~bootstrap/scss/functions";
@import "~bootstrap/scss/variables";
@import "~bootstrap/scss/mixins";
.xxx {
@include media-breakpoint-up(md) {
display: none;
}
}
</style>
How to avoid importing these file in every component?
I figure it out. In case youre using vue-cli:
Create file vue.config.js with content:
const path = require("path");
const loader = {
loader: 'sass-resources-loader',
options: {
resources: path.resolve(__dirname, './src/assets/scss/global.scss')
}
}
module.exports = {
configureWebpack: {
module: {
rules: [
{
test: /\.scss$/,
use: [
loader,
'sass-loader'
]
}
]
}
}
};
Don't forget to install sass-resources-loader:
yarn add sass-resources-loader -D
And restart dev server. So from now you can define/import variables, mixins and other stuff inside that global.scss and these variables/mixins will be available inside every component without import.