在 Compass 项目目录结构中使用 Sass 部分子文件夹

发布于 2024-10-16 02:58:50 字数 327 浏览 2 评论 0原文

我已经启动了一个指南针项目,并在 src 目录中使用 scss 文件运行,这些文件正在作为 css 编译到 sttylesheets 目录中。这一切都很好,我可以使用 sass @import 命令没有问题。

但是,我想对我的 sass 部分进行一些组织,并将它们放入 src 目录中的相关文件夹中。但是,当我尝试执行此操作时,@import 命令失败。

有办法做到这一点吗?

更新:我在指南针文档中发现我可以将 add_import_path 添加到我的配置文件中,但我也无法让它工作。我尝试了目录的完整路径和相对于项目的路径,但没有任何反应。

有人请帮忙,这不可能这么难!

I've got a compass project up and running with scss files in a src directory which are being compiled into a sttylesheets directory as css. This is all fine and I'm able to use the sass @import command no problem.

However, I'd like to bring a bit of organisation to my sass partials and place them into relevant folders within the src directory. However, when I try to do this the @import command fails.

Is there a way of doing this?

UPDATE: I found in the compass docs that I can add add_import_path to my configuration file, but I can't get this to work either. I've tried a full path to the directory and a path relative to the project but nothing is happening.

Someone please help, it can't be this hard!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

帅的被狗咬 2024-10-23 02:58:50

例如,如果您将部分放在 src/partials 目录中 - 只需在 sass/scss 文件中使用 @import "partials/name" 即可导入它们。

If you placed partials, for example, in src/partials directory — just use @import "partials/name" in sass/scss files to import them.

复古式 2024-10-23 02:58:50

我发现在一个使用 compass / sass 的 webby 静态项目中,我必须明确设置要使用的基本 sass 路径,以便它能够获取 sass 导入(除了导入之外,一切正常)。

所以我最终在罗盘配置块中做了类似的事情:
config.sass_dir = File.join('content', 'css')

我想这是因为我使用的是默认 sass 路径以外的东西,所以当我 @import 时,它是在它的默认路径而不是实际路径中查找。

希望有帮助。

I found that in a webby static project where I was using compass / sass I had to explcitly set the base sass path to be used in order for it to pick up sass imports (everything worked except for imports).

So I ended up doing something like this in the compass config block:
config.sass_dir = File.join('content', 'css')

I imagine this is because I'm using something other than the default sass paths, so when I @import it was looking within it's default path instead of the actual path.

Hope that helps.

世态炎凉 2024-10-23 02:58:50

结果证明我处理事情的方式是错误的。在使用指南针做任何事情之前,我试图提高效率并组织我的文件夹结构。我意识到我需要先设置指南针来观看项目,然后创建文件夹结构。这样,文件夹结构就会复制到我的样式表或 CSS 文件夹中,而不仅仅是位于源文件夹中。现在一切都正常了!

So it turned out I was going about things the wrong way. I was trying to be efficient and organise my folder structure before doing anything with compass. I realised that I needed to set compass to watch the project first and then create a folder structure. That way the folder structure gets replicated in my stylesheets or CSS folder instead of just being in the source folder. Now everything is working as it should!

花伊自在美 2024-10-23 02:58:50

我也有同样的问题。实际上,我是从 Rails + sprockets 项目迁移到独立项目的。

我不知道为什么,但 Compass 无法使用链轮样式的文件名,例如 screen.css.scss。我将所有文件重命名为 screen.scss,并且所有部分文件都按预期工作。

I had the same problem. Actually I was migrated from rails + sprockets project to standalone one.

I don't know why, but Compass doesn't work with sprockets-style filenames, like screen.css.scss. I renamed all my files just to screen.scss and all partials worked as expected.

椵侞 2024-10-23 02:58:50

我有类似的问题。我真是太愚蠢了——但话又说回来,编程中的大多数问题都是如此。我的问题是,尽管我已经正确设置了独立的所有内容,根据:

https://github.com/ twbs/bootstrap-sass

我使用的是这样的子文件夹结构:

project
-- stylesheets
-- bootstrap
-- sass
---- main.scss
------- subfolder1
----------- partial.scss
------- subfolder2
----------- partial2.scss

在我的 main.scss 中,我确实正确使用了 @import,例如:

@import "subfolder1/partial.scss"

问题是这样的:
如果文件名以下划线开头,Compass 只能正确看到部分内容!

将文件重命名为 _partial1.scss 和 _partial2.scss 后,一切都正常工作。

I had a similar problem. It was very stupid of me - but then again, most problems in programming are. My problem was that, although I had everything setup correctly for standalone, according to:

https://github.com/twbs/bootstrap-sass

I was using a subfolder structure like this:

project
-- stylesheets
-- bootstrap
-- sass
---- main.scss
------- subfolder1
----------- partial.scss
------- subfolder2
----------- partial2.scss

And in my main.scss, I did use @import correctly, like:

@import "subfolder1/partial.scss"

The problem was this:
Compass only sees partials correctly if the filenames start with underscores!

Once I renamed the files to _partial1.scss and _partial2.scss, everything worked without a problem.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文