我用SASS部分模块化我的样式表,就像这样:

@import partials/header
@import partials/viewport
@import partials/footer
@import partials/forms
@import partials/list_container
@import partials/info_container
@import partials/notifications
@import partials/queues

有没有办法包括整个partials目录(它是一个充满sas -partials的目录),比如@import compass之类的?


当前回答

This feature will never be part of Sass. One major reason is import order. In CSS, the files imported last can override the styles stated before. If you import a directory, how can you determine import order? There's no way that doesn't introduce some new level of complexity. By keeping a list of imports (as you did in your example), you're being explicit with import order. This is essential if you want to be able to confidently override styles that are defined in another file or write mixins in one file and use them in another.

有关更详细的讨论,请查看此封闭功能请求:

其他回答

This feature will never be part of Sass. One major reason is import order. In CSS, the files imported last can override the styles stated before. If you import a directory, how can you determine import order? There's no way that doesn't introduce some new level of complexity. By keeping a list of imports (as you did in your example), you're being explicit with import order. This is essential if you want to be able to confidently override styles that are defined in another file or write mixins in one file and use them in another.

有关更详细的讨论,请查看此封闭功能请求:

你可以使用一些变通方法,在你想导入的文件夹中放置一个sass文件,然后像这样导入该文件中的所有文件:

当前文件路径:主要/ / _current.scss

@ import“占位符”; @ import“颜色”;

在下一个dir级别的文件中,你只需使用import for file导入该dir级别的所有文件:

文件路径:主要/ main.scss

@ import“EricMeyerResetCSSv20”; @ import“clearfix”; @ import“当前”;

这样你就有了相同数量的文件,就像你导入了整个目录。注意顺序,最后出现的文件将覆盖匹配的斯蒂尔。

http://sass-lang.com/docs/yardoc/file.SASS_REFERENCE.html#import

看起来不像。

如果这些文件中的任何一个总是需要其他文件,那么让它们导入其他文件,并且只导入顶级文件。如果它们都是独立的,那么我认为你将不得不像现在这样继续做下去。

你可能想要保留源顺序,那么你可以使用这个。

@import
  'foo',
  'bar';

我更喜欢这个。

通过定义要导入的文件,可以使用所有文件夹的通用定义。

因此,@import "style/*"将编译style文件夹中的所有文件。

更多关于Sass的导入特性,你可以在这里找到。