简体   繁体   English

变量是SASS全局变量,而不是SCSS

[英]Variables are global with SASS but not SCSS

I have my application.css.scss set like this: 我将我的application.css.scss设置如下:

@import "base/variables";
@import "./application/application";

Like the documentation says I am not using Sprockets' directives ( require , require_tree , and require_self ) at all so I expect my variables defined inside of base/_variables.scss to be globals and available for my /application/application.scss file but it's not the case: 就像文档说的那样,我根本没有使用Sprockets的指令( requirerequire_treerequire_self ),因此我希望在base/_variables.scss内定义的变量是全局变量,可用于我的/application/application.scss文件,但是并非如此:

#content {
  margin-top: $big;
}

Will return the error Undefined variable: "$big" . 将返回错误的Undefined variable: "$big"

I've tried the same thing with SASS by naming by files application.css.sass and /application/application.sass and while the variables now do seems to be globals I'll like to keep using the SCSS syntax, I've tried that by setting config.sass.preferred_syntax = :scss but I'm still being asked for Sass. 我已经通过使用文件application.css.sass/application/application.sass命名来尝试使用SASS进行相同的操作,虽然现在变量似乎确实是全局变量,但我想继续使用SCSS语法,但是我尝试过通过设置config.sass.preferred_syntax = :scss但是我仍然被要求提供Sass。

Of course I could just import my variables file everytime I need my variables but that would go against the DRY principle. 当然,每次需要变量时,我都可以导入变量文件,但这会违背DRY原则。

Is that possible to use the SCSS syntax while making my variables globally available? 在使变量全局可用时,可以使用SCSS语法吗? What am I missing here? 我在这里想念什么? Thanks in advance. 提前致谢。

我的application/application.scss已通过旧规则使用通配符进行了预编译(在assets.rb ),但我错过了,现在可以正常使用了。

What versions of sprockets , rails and sass-rails gems do you have? 您有哪些版本的sprocketsrailssass-rails宝石? There were some problems around undefined variables, maybe try to bump up sass-rails and sprockets (if possible). 未定义的变量周围存在一些问题 ,可能尝试提高sass-railssprockets (如果可能)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM