SASS 全局变量未传递给部分 [英] SASS global variables not being passed to partials
问题描述
基本上我有一个结构,它曾经在 3.0.x 中完美运行,现在它因 undefined variable
错误而中断.
Basically I have a structure that used to work perfectly in 3.0.x and now it breaks with undefined variable
errors.
- 部分
- _base.css.sass
- _header.css.sass
application.css.sass
://=require 'main'
main.css.sass
:@import 'partials/base' @import 'partials/header'
很简单的东西.
我在
_header.css.sass
上遇到错误因为它使用了一个定义在_base.css.sass
I get an error on
_header.css.sass
because it uses a variable defined on_base.css.sass
我之前没有遇到过这个错误,这对我来说毫无意义,因为我们在导入
_base.css.sass
的同一上下文中导入这些变量代码>_header.css.sass.I didn't have this error before, and it makes no sense to me, since we're importing those variables on the
_base.css.sass
in the same context we are importing the_header.css.sass
.我是否也必须在每个部分上导入
_base.css.sass
?如果main.css.sass
不能在您需要的自己的部分中使用,那么需要全局变量的意义何在?Am I going to have to import the
_base.css.sass
on every partial too? What is the point of themain.css.sass
requiring global variables if they cannot be used in the own partials you are requiring?如果我的结构完全错误,请给我一个替代方案,我很乐意提供建议.
If my structure is completely wrong, please give me an alternative, I'd love suggestions.
推荐答案
你不能使用
//=require
来包含动态"的 SASS 东西,比如 mixin 和变量,因为它只用于包括最静态"的东西(如纯 CSS).您必须@import
application.css.sass
中的所有文件.Railscasts 在 episode #268 中对此进行了很好的解释.You can't use
//=require
to include "dynamic" SASS stuff like mixins and variables, because that's used just for including the most "static" stuff (like pure CSS). You have to@import
all your files inapplication.css.sass
. Railscasts provides good explanation of this in episode #268.这篇关于SASS 全局变量未传递给部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!