问题描述
在SASS中,是否可以从其他目录导入文件?例如,如果我有这样的结构:
In SASS, is it possible to import a file from another directory? For example, if I had a structure like this:
- root_directory
- sub_directory_a
- _common.scss
- template.scss
- sub_directory_b
- more_styles.scss
template.scss可以使用 @importcommon
导入_common.scss,但是more_styles.scss可以导入_common.scss吗?我尝试了一些不同的东西,包括 @import../ sub_directory_a / common
和 @import../ sub_directory_a / _common.scss
但似乎没有任何效果。
template.scss could import _common.scss using @import "common"
but is it possible for more_styles.scss to import _common.scss? I tried a few different things including @import "../sub_directory_a/common"
and @import "../sub_directory_a/_common.scss"
but nothing seems to work.
推荐答案
看起来SASS的一些变化使你的成就成为可能最初尝试过:
Looks like some changes to SASS have made possible what you've initially tried doing:
@import "../subdir/common";
我们甚至将其用于位于 c中的一些完全不相关的文件夹: \projects\sass
:
We even got this to work for some totally unrelated folder located in c:\projects\sass
:
@import "../../../../../../../../../../projects/sass/common";
只需添加足够的 ../
即可确定你最终会到达驱动器根目录并且你很高兴。
Just add enough ../
to be sure you'll end up at the drive root and you're good to go.
当然,这个解决方案远非漂亮,但我无法得到一个从一个完全不同的文件夹导入工作,既不使用我c:\ project] \ sass
也不设置环境变量 SASS_PATH
(来自:)相同的价值。
Of course, this solution is far from pretty, but I couldn't get an import from a totally different folder to work, neither using I c:\projects\sass
nor setting the environment variable SASS_PATH
(from: :load_paths reference) to that same value.
这篇关于使用SASS时如何从其他目录导入文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!