Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use bootstrap mixins in angular-cli

I tried using a mixin in my styles.scss but it says it is not defined. I've tried:

  1. Using it in styles.scss
@include media-breakpoint-up(sm) {
  .some-class {
    display: block;
  }
}

result:

@include media-breakpoint-up(sm) {
        ^
      No mixin named media-breakpoint-up
  1. importing bootstrap again:

    @import "../node_modules/bootstrap/scss/bootstrap.scss";

Now it works but bootstrap is included twice if I look in styles.bundle.js. Bootstrap is already included in angular-cli.json.

like image 466
gyozo kudor Avatar asked Nov 24 '17 12:11

gyozo kudor


People also ask

What is bootstrap mixin?

The @mixin directive lets you create CSS code that is to be reused throughout the website. The @include directive is created to let you use (include) the mixin.

Does bootstrap support SASS variables and Mixins?

Bootstrap includes a handful of Sass maps, key value pairs that make it easier to generate families of related CSS. We use Sass maps for our colors, grid breakpoints, and more. Just like Sass variables, all Sass maps include the ! default flag and can be overridden and extended.


Video Answer


1 Answers

I've the same problem with all components in theirs own folder projects/<prj>/src/app/navbar/navbar.scss:

and I've fixed temporary adding manually

   @import '~bootstrap/scss/functions';
   @import '~bootstrap/scss/variables';
   @import '~bootstrap/scss/mixins';

I know for sure that isn't beautiful but resolve it ...

My packages versions below

Angular CLI: 7.0.6
Node: 9.10.1
OS: darwin x64
Angular: 7.0.4
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router

Package                            Version
------------------------------------------------------------
@angular-devkit/architect          0.10.6
@angular-devkit/build-angular      0.10.6
@angular-devkit/build-ng-packagr   0.10.7
@angular-devkit/build-optimizer    0.10.6
@angular-devkit/build-webpack      0.10.6
@angular-devkit/core               7.0.6
@angular-devkit/schematics         7.0.6
@angular/cli                       7.0.6
@angular/fire                      5.1.0
@ngtools/json-schema               1.1.0
@ngtools/webpack                   7.0.6
@schematics/angular                7.0.6
@schematics/update                 0.10.6
ng-packagr                         4.4.5
rxjs                               6.3.3
typescript                         3.1.6
webpack                            4.19.1
like image 68
miticojo Avatar answered Oct 18 '22 11:10

miticojo