【问题标题】:'SassError undefined variable' with Angular 9 and Bootstrap 4 out-of-the-boxAngular 9 和 Bootstrap 4 开箱即用的“SassError 未定义变量”
【发布时间】:2020-07-11 21:42:27
【问题描述】:

以前我使用 Angular 8 和 Bootstrap 4,并使用这个出色的答案来访问 Bootstrap 变量。 https://stackoverflow.com/a/40070580/1061602.

我似乎无法在 Angular 9 中使用它。

步骤:

  1. 使用 Angular CLI 生成一个新项目,选择 SCSS
  2. 通过 npm 安装 Bootstrap 4、JQuery、Popper.js
  3. 在 styles.scss 中,输入以下内容:
    html { background: $success-bg; }

  4. 运行ng b 进行构建

你现在得到SassError: Undefined variable

问:在 SCSS 级别导入 Bootstrap 4 需要什么导入,并且还可以使用变量

我尝试了以下组合:

@import "~bootstrap/scss/bootstrap";

@import "~bootstrap/scss/_variables";

@import "~bootstrap/scss/_variables.scss";

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

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

例如

我尝试设置 StackBlitz,但找不到设置 Angular 9、SCSS、Bootstrap 4 的方法,它抱怨的是 CSS 而不是 SCSS。

一般来说,Bootstrap 有效。实用程序类工作。我可以使用混合。我可以毫无问题地重新定义变量。我只是不能以这种方式使用现有的 BS4 变量。

【问题讨论】:

    标签: angular twitter-bootstrap sass bootstrap-4


    【解决方案1】:

    使用前要导入变量,我使用如下设置

    // Required Bootstrap partials
    @import "node_modules/bootstrap/scss/functions";
    @import "node_modules/bootstrap/scss/variables";
    @import "node_modules/bootstrap/scss/mixins";
    
    html { background: $success-bg; }
    
    // Optional (Add components according to your use)
    @import "node_modules/bootstrap/scss/reboot";
    @import "node_modules/bootstrap/scss/alert";
    @import "node_modules/bootstrap/scss/buttons";
    
    

    【讨论】:

    • 对不起,这对我不起作用,我附上了一张截图,显示了我添加的所有导入
    猜你喜欢
    • 2022-07-30
    • 2021-12-19
    • 2021-08-10
    • 2020-06-06
    • 2017-09-09
    • 2022-08-02
    • 2019-10-16
    • 2020-08-18
    • 2021-02-19
    相关资源
    最近更新 更多