Is there a way to compile my custom bootstrap SCSS file into a CSS file that only includes the classes I created in my custom file?
For example, I want to eliminate the extra CSS classes added to my HTML code.
Instead of including unnecessary classes like:
<h4 class="border-bottom p-2 mb-4">
Blah Blah
<span class="badge badge-secondary badge-pill float-right">100</span>
</h4>
I would prefer to write (without any class attributes):
<h4>
Blah Blah
<span>100</span>
</h4>
To achieve this, I have created a custom.scss file with specific content:
@import "bootstrap/scss/functions";
@import "bootstrap/scss/variables";
@import "bootstrap/scss/mixins";
@import "bootstrap/scss/utilities/borders";
@import "bootstrap/scss/utilities/spacing";
@import "bootstrap/scss/utilities/float";
@import "bootstrap/scss/badge";
h4 {
@extend .border-bottom;
@extend .p-2;
@extend .mb-4;
}
h4 span {
@extend .float-right;
@extend .badge;
@extend .badge-pill;
@extend .badge-secondary;
}
After compiling, the CSS file contains over 1000 lines. Why is this happening? How can I remove all the unnecessary styles and only keep what I specified in my custom.scss file?
The desired result should be something like this:
h4 {
border-bottom: 1px solid #dee2e6 !important;
margin-bottom: 1.5rem !important;
padding: 0.5rem !important;
}
h4 span {
float: right !important;
// Other specific styles here
}
But it's not turning out that way.
Edit:
If I modify my custom.scss as follows:
@import "bootstrap/scss/functions";
@import "bootstrap/scss/variables";
@import "bootstrap/scss/mixins";
$theme-colors: (
"secondary": $secondary,
);
h4 {
border-bottom: $border-width solid $border-color;
padding: map_get($spacers, 2);
margin-bottom: map_get($spacers, 4);
}
@import "bootstrap/scss/badge";
h4 span {
@include float-right;
@extend .badge;
@extend .badge-pill;
@extend .badge-secondary;
}
The resulting CSS will mostly include the necessary styles. However, I originally anticipated it would be easier to rely on bootstrap classes rather than manually searching through the SCSS files. Is there a simpler way to accomplish this?