我发现自己在 assets:precompile
的奇怪行为面前任务,或者至少在我不完全理解的事情面前。
所以,我在我的 Web 应用程序中使用 Rails 3.1.3、Sprockets 2.0.3、Less 2.0.11,再加上我依赖 Bootstrap 进行布局,所以我也在使用 less-rails 2.1.8 和 less-rails-bootstrap 2.0.8。
我已经像他们说的那样定制了样式here .
我的 Assets 配置是:
stylesheets
|--application.css.scss
|--custom-style/
|--variables.less
|--mixins.less
|--buttons.less
|--custom-style.css.less
在 application.css.scss 我做
//=require custom-style
我做的定制风格
@import "twitter/bootstrap/reset";
//@import "twitter/bootstrap/variables"; // Modify this for custom colors, font-sizes, etc
@import "custom-style/variables";
//@import "twitter/bootstrap/mixins";
@import "custom-style/mixins";
// And all the other standar twitter/bootstrap imports...
// Other custom-style files to import
@import "custom-style/buttons"
//...
// And other rules here
//...
终于在
buttons.less
我使用了variables.less
中定义的一些变量和mixin。和 mixins.less
Bootstrap 文件,@white
和 .buttonBackground
更具体。如果我启动
bundle exec rake assets:precompile
使用上述配置,任务失败,我收到此错误:$ bundle exec rake assets:precompile
/usr/local/rvm/rubies/ruby-1.9.3-p0/bin/ruby /usr/local/rvm/gems/ruby-1.9.3-p0/bin/rake assets:precompile:all RAILS_ENV=production RAILS_GROUPS=assets
rake aborted!
.buttonBackground is undefined
但是,如果我这样做会改变
buttons.less --> buttons.css.less
@import "buttons" --> @import "buttons.css.less"
一切正常!!
使用嵌套导入时,它与较少变量和函数的范围有关吗?或者与较少的解析器或 Sprockets 处理导入树的顺序有关?
我是否错过了什么或以错误的方式做某事?
谢谢 :)
注:即使使用原始变量和 mixins 文件,我也会收到错误消息,因此它与对它们进行的覆盖无关。
最佳答案
我现在可以想到两种可能性之一:
1)您应该将 application.css.scss 更改为 application.css.less 并使用:@import "custom-style";
而不是 sprockets //= require ...
2) LESS 编译器对分号非常挑剔。我注意到你有@import "custom-style/buttons"
- 应该是 @import "custom-style/buttons";
不知道问题是否真的那么简单,但这是一个开始。
关于ruby-on-rails - Rails Assets :precompile strange behavior,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9751853/