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
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/**/*' ]