问题描述
我正在开发一个包含 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
不应该由 bootstrap 定义吗?我错过了什么?
解决方法
在您的 application.scss 文件中 添加这一行
@import "bootstrap-variables";
希望这对你有用。 谢谢。