【问题标题】:Unboud variable using sass使用 sass 的未绑定变量
【发布时间】:2015-03-18 18:25:50
【问题描述】:

我使用 https://github.com/Swiip/generator-gulp-angular 来样板化我的 angularjs 应用程序。

我发现 bootswatch 主题很平坦,想使用它并从 [http://bootswatch.com/flatly/][2] 两个文件下载,_variables.scss 和 _bootswatch.scss。

我将这两个文件添加到我的 vendor.scss

$icon-font-path: "../../bower_components/bootstrap-sass-official/assets/fonts/bootstrap/";

@import '../../bower_components/bootstrap-sass-official/assets/stylesheets/bootstrap';

@import "flatly/variables";
@import "flatly/bootswatch";

使用gulp serve,我构建了我的应用程序并在控制台上显示了它。

project developer$ gulp serve
[21:28:41] Using gulpfile /Volumes/Developer/angularjs/project/gulpfile.js
[21:28:41] Starting 'styles'...
[21:28:42] gulp-inject 2 files into index.scss.

stream.js:94
      throw er; // Unhandled stream error in pipe.
            ^
Error: /Volumes/Developer/angularjs/project/src/app/flatly/_bootswatch.scss:16: error: unbound variable $navbar-default-bg 

  [1]: https://github.com/Swiip/generator-gulp-angular
  [2]: http://bootswatch.com/flatly/

为什么unbound variable $navbar-default-bg 但$navbar-default-bg 存在于_variables.scss 文件中。

$navbar-default-bg: $brand-primary;

我的项目结构:

【问题讨论】:

    标签: css angularjs twitter-bootstrap sass


    【解决方案1】:

    在您的自定义 index.scss 开头导入 _variables.scss 文件:

    @import '../../../bower_components/bootstrap-sass-official/assets/stylesheets/bootstrap/variables';
    

    另一种方法是遵循这些说明>>https://github.com/Swiip/generator-gulp-angular/issues/379。不过我没试过。

    【讨论】:

      【解决方案2】:

      尝试按此顺序导入变量、引导程序、引导程序 https://github.com/thomaspark/bootswatch/blob/gh-pages/global/build.scss

      @import "flatly/variables";
      @import '../../bower_components/bootstrap-sass-official/assets/stylesheets/bootstrap';
      @import "flatly/bootswatch";
      

      样板文件会尝试编译 src 文件夹中的所有 .scss 文件(当它应该忽略以 _ 开头的 scss 文件时)。

      在 /src 之外移动使其表现如

      @import "../../flatly/variables";
      @import '../../bower_components/bootstrap-sass-official/assets/stylesheets/bootstrap';
      @import "../../flatly/bootswatch";
      

      【讨论】:

      • 这似乎是 github.com/Swiip/generator-gulp-angular 样板的问题。它编译 _xxx.scss 文件时不应该这样做
      • 样板文件尝试编译 src 文件夹中的所有 .scss 文件(当它应该忽略以 _ 开头的 scss 文件时)。
      • 用解决方法更新了我的答案......可能是一种更好的方法,但我不熟悉 gulp。可能值得在这里记录一个问题github.com/Swiip/generator-gulp-angular/issues
      猜你喜欢
      • 2020-11-11
      • 2021-04-29
      • 2012-10-30
      • 2012-04-12
      • 1970-01-01
      • 2021-04-03
      • 1970-01-01
      • 2022-12-10
      • 1970-01-01
      相关资源
      最近更新 更多