问题描述
我有一个以以下内容开头的 scss 文件:
I have a scss file starting with:
@import "styles";
@import url("http://lctools.lundbeckconsulting.no/SASS/STATIC/lct.public.scss");
包含媒体规则:
@media (max-width: $media-small-width) { //code }
但是在 Visual Studio 中编译文件时,我收到一个错误消息,指出 $media-small-width 是一个 未声明的变量,即使它存在于 中从外部站点导入的 lct.public.scss.
But when compiling the file in Visual Studio I get an error saying that $media-small-width is an Undeclared Variable, even though it exists in lct.public.scss that's imported from the external site.
使用 styles.scss(本地文件)中的变量按预期工作
Using variables from styles.scss (local file) works as expected
推荐答案
发生这种情况是因为导入函数只会将外部文件作为 CSS 导入规则导入 - 它实际上不会将该外部文件中的 SCSS 导入到其余文件中您的代码.
This is happening because the import function will only import external files as a CSS import rule - it will not actually import the SCSS from that external file into the rest of your code.
您需要在本地文件中声明变量.(这可能不是您希望的答案.抱歉!)
You will need to declare your variables inside your local files. (This might not be the answer you were hoping for. Sorry!)
从 SASS 导入的文档:http://sass-lang.com/documentation/file.SASS_REFERENCE.html#_import__import
Documentation on import from SASS: http://sass-lang.com/documentation/file.SASS_REFERENCE.html#_import__import
这篇关于从外部站点导入 SASS 文件时的变量问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!