简体   繁体   English

在Compass项目目录结构中使用Sass partials的子文件夹

[英]Using subfolders for Sass partials in Compass project directory structure

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. 我有一个指南针项目,并在src目录中运行scss文件,这些文件被编译为sttylesheets目录作为css。 This is all fine and I'm able to use the sass @import command no problem. 这一切都很好,我可以使用sass @import命令没问题。

However, I'd like to bring a bit of organisation to my sass partials and place them into relevant folders within the src directory. 但是,我想为我的部分内容添加一些组织,并将它们放入src目录中的相关文件夹中。 However, when I try to do this the @import command fails. 但是,当我尝试这样做时,@ import命令失败。

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. 更新:我在指南针文档中发现我可以将add_import_path添加到我的配置文件中,但我无法使其工作。 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! 有人请帮忙,不能这么难!

I had the same problem. 我有同样的问题。 Actually I was migrated from rails + sprockets project to standalone one. 实际上我是从rails + sprockets项目迁移到独立项目。

I don't know why, but Compass doesn't work with sprockets-style filenames, like screen.css.scss . 我不知道为什么,但Compass不能使用sprockets风格的文件名,比如screen.css.scss I renamed all my files just to screen.scss and all partials worked as expected. 我将所有文件重命名为screen.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 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: 在我的main.scss中,我确实使用了@import,如:

@import "subfolder1/partial.scss" @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. 一旦我将文件重命名为_partial1.scss和_partial2.scss,一切都没有问题。

例如,如果你在src / partials目录中放置了部分内容 - 只需在sass / scss文件中使用@import "partials/name"来导入它们。

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). 我发现在我使用指南针/ sass的webby静态项目中,我必须明确设置要使用的基本sass路径,以便它获取sass导入(除导入之外一切正常)。

So I ended up doing something like this in the compass config block: config.sass_dir = File.join('content', 'css') 所以我最终在罗盘配置块中做了类似的事情: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. 我想这是因为我使用的不是默认的sass路径,所以当我在@import中查看它的默认路径而不是实际路径时。

Hope that helps. 希望有所帮助。

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. 这样,文件夹结构就会复制到我的样式表或CSS文件夹中,而不仅仅是在源文件夹中。 Now everything is working as it should! 现在一切都正常运作!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM