误报“未定义变量"编译SCSS时出错 [英] False positive "undefined variable" error when compiling SCSS

查看:56
本文介绍了误报“未定义变量"编译SCSS时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 ruby​​ compass gem 编译我的 SCSS 时收到错误消息.

Getting an error message when compiling my SCSS using the ruby compass gem.

run: /var/lib/gems/1.8/gems/compass-0.12.2/bin/compass compile
out: unchanged sass/partial/grid.scss
out:     error sass/partial/catalog.scss (Line 5: Undefined variable: "$paragraphFont".)
out:    create css/generated/partial/catalog.css 
out:    create css/generated/partial/base.css 
out: overwrite css/generated/screen.css

我的 screen.scss 像这样导入部分:

My screen.scss imports partials like this:

@import "partial/base";
@import "partial/catalog";

在我的 base 部分中,我定义了 $paragraphFont.

In my base partial I have the $paragraphFont defined.

$paragraphFont: 'Lucida Sans', arial;
$regularFontSize: 14px;

catalog.scss 中我使用它:

.product-view #price-block {
    p {
        font-weight: normal;
        font-family: $paragraphFont;
        ....
    }
}

奇怪的是 css 被编译得很好,并且 $paragraphFont 被正确填充.所以我不知道为什么编译器向我抱怨一个错误.

Weird thing is that the css gets compiled just fine, and the $paragraphFont is populated correctly. So I don't know why the compiler is complaining at me about an error.

推荐答案

您正在生成不需要生成的文件.

You're generating files that don't need to be generated.

  • screen.scss -> screen.css
  • base.scss -> base.css
  • catalog.scss -> catalog.css

目录文件正在自行编译.因为它没有导入 base.scss,所以没有设置变量.您的 screen.scss 文件会按照您的预期生成,因为它会导入所有必要的信息.

The catalog file is being compiled on its own. Since it is not importing base.scss, the variables are not set. Your screen.scss file generates as you expect because it is importing all of the necessary information.

您想要做的是重命名您的部分以以下划线开头,以防止它们被自己编译:

What you want to do is rename your partials to begin with an underscore to prevent them from being compiled on their own:

  • screen.scss -> screen.css
  • _base.scss(未编译)
  • _catalog.scss(未编译)

这篇关于误报“未定义变量"编译SCSS时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆