ruby-on-rails - Rails Assets :precompile strange behavior

标签 ruby-on-rails twitter-bootstrap less sprockets

我发现自己在 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/

相关文章:

ruby-on-rails - 如何将 Bootstrap 按钮放入 haml/html 文件中

javascript - bootstrap.min.js :6 Uncaught Error: Bootstrap dropdown require Popper. js

ruby-on-rails - 冲突delayed_job/sidekiq

ruby-on-rails - Rails 助手在哪里可用?

css - Bootstrap - 流体导航栏元素

css - LESS 以类型的每个元素为目标,除非它在某个 div 中

css - 解析 LESS 客户端

ruby-on-rails - 更新 LESS 代码后,Less 编译器不会更新 css 文件

ruby-on-rails - Heroku Assets 预编译

ruby-on-rails - 如何使用 simple_form 和嵌套表单通过关联为 has_many 创建嵌套表单?