【问题标题】:Error in rake app:assets:precompile when using a bootstrap sass variable in a rails engine在 Rails 引擎中使用引导 sass 变量时,rake app:assets:precompile 出错
【发布时间】:2021-05-11 19:08:15
【问题描述】:

我正在开发一个包含 bootstrap-sass 的 Rails 引擎。我正在尝试在我的样式中使用引导变量,但出现错误。我正在尝试遵循此处的文档:
https://www.rubydoc.info/gems/bootstrap-sass/3.4.1

# test_engine.gemspec

# ...

  s.add_dependency "rails", ">= 5"
  s.add_dependency 'sassc-rails'
  s.add_dependency 'bootstrap-sass'
# ...

application.scss:

/*
 * This is a manifest file that'll be compiled into application.css, which will include all the files
 * listed below.
 *
 * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
 * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
 *
 * You're free to add application-wide styles to this file and they'll appear at the bottom of the
 * compiled file so the styles you add here take precedence over styles defined in any styles
 * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
 * file per style scope.
 *
 */

@import "bootstrap-sprockets";
@import "bootstrap";
@import "bootstrap-variables";

我已经为运行 rake 任务的虚拟应用程序定义了一个清单文件:
test/dummy/app/assets/config/manifest.js

//= link_tree ../images
//= link_directory ../javascripts .js
//= link_directory ../stylesheets .css
//= link test_engine_manifest.js

还有我的引擎的清单文件:
app/assets/config/test_engine_manifest.js

//= link_directory ../javascripts/test_engine .js
//= link_directory ../stylesheets/test_engine .css

这是我尝试使用该变量的文件:

// _thing.scss

.thing {
  color: $brand-primary;
}

以及 rake app:assets:precompile 的输出

> ❯❯❯ rake app:assets:precompile                                                                                                            

rake aborted!
SassC::SyntaxError: Error: Undefined variable: "$brand-primary".
        on line 2:10 of app/assets/stylesheets/test_engine/_thing.scss
>>   color: $brand-primary;

   ---------^

$brand-primary 不应该由引导程序定义吗?我错过了什么?

【问题讨论】:

    标签: ruby-on-rails sass rails-engines bootstrap-sass


    【解决方案1】:

    在您的 application.scss 文件中 添加这一行

    @import "bootstrap-variables";

    希望这对你有用。 谢谢。

    【讨论】:

    • 感谢您的建议,但它并没有解决我的问题。不过我确实注意到了一些事情:如果我包含一个@import 声明,它引用了我知道不存在的东西,例如@import "xyz-variables";,我会得到同样的错误(而不是一个错误说它找不到导入)。所以也许我错过了包含 application.scss 的步骤
    猜你喜欢
    • 2015-02-02
    • 2014-06-13
    • 2014-03-05
    • 1970-01-01
    • 1970-01-01
    • 2023-02-16
    • 2018-05-07
    • 2011-11-17
    • 1970-01-01
    相关资源
    最近更新 更多