-
Notifications
You must be signed in to change notification settings - Fork 11.9k
Closed
Description
I tried to ask this on Stackoverflow, but did not get any response yet. My question:
I'm trying to use Twitter Bootstrap with Angular 2, SCSS and the scaffold generated by angular-cli
I want to apply the best practice to not litter my markup with Bootstrap-specific CSS classes. Instead I want to apply/use them via @extend or as mixins:
.mybutton {
@extend .btn;
}
My problem:
- The SASS compiler throws an error, because it does not know about
.btn - If I add
@import "bootstrap";to my.scss-File, it will render the full Bootstrap-CSS in every component css
Any clues for me how this can be matched with the Angular 2 / Angular-CLI approach of handling styles?
What I've done so far
-
add
@import "bootstrap";to myapp.component.scss -
Apply
ViewEncapsulation.Noneto theAppComponent, so Angular 2 does not apply Shadow DOM emulation and the Bootstrap CSS applies to the whole application@Component({ encapsulation: ViewEncapsulation.None }) -
Include the following block into
angular-cli-build.js, so relative@importwill worksassCompiler: { cacheExclude: [/\/_[^\/]+$/], includePaths: [ 'node_modules/bootstrap-sass/assets/stylesheets' ] }, vendorNpmFiles: [ ... 'bootstrap-sass/assets/**/*' ]
silentHoo, ayyfish, cwagner22, calbear47, harryjubb and 15 more