是否可以使用@import 在 sass 中导入整个目录? [英] Is it possible to import a whole directory in sass using @import?

查看:31
本文介绍了是否可以使用@import 在 sass 中导入整个目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 SASS 部分模块化我的样式表,如下所示:

I am modularizing my stylesheets with SASS partials like so:

@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

有没有办法像@import compass 之类的那样包含整个部分目录(它是一个充满 SASS 部分的目录)?

is there a way to include the whole partials directory(it's a directory full of SASS-partials) like @import compass or something?

推荐答案

如果你在 Rails 项目中使用 Sass,sass-rails gem,https://github.com/rails/sass-rails,具有全局导入功能.

If you are using Sass in a Rails project, the sass-rails gem, https://github.com/rails/sass-rails, features glob importing.

@import "foo/*"     // import all the files in the foo folder
@import "bar/**/*"  // import all the files in the bar tree

在另一个答案中回答这个问题如果你导入一个目录,你如何确定导入顺序?没有办法不引入一些新的复杂程度."

To answer the concern in another answer "If you import a directory, how can you determine import order? There's no way that doesn't introduce some new level of complexity."

有些人会争辩说,将文件组织到目录中可以降低复杂性.

Some would argue that organizing your files into directories can REDUCE complexity.

我组织的项目是一个相当复杂的应用程序.17 个目录中有 119 个 Sass 文件.这些大致对应于我们的视图,主要用于调整,繁重的工作由我们的自定义框架处理.对我来说,几行导入的目录比 119 行导入的文件名要简单一些.

My organization's project is a rather complex app. There are 119 Sass files in 17 directories. These correspond roughly to our views and are mainly used for adjustments, with the heavy lifting being handled by our custom framework. To me, a few lines of imported directories is a tad less complex than 119 lines of imported filenames.

为了解决加载顺序,我们将需要首先加载的文件——mixin、变量等——放在一个早期加载目录中.否则,加载顺序是并且应该是无关紧要的...如果我们正确地做事.

To address load order, we place files that need to load first – mixins, variables, etc. — in an early-loading directory. Otherwise, load order is and should be irrelevant... if we are doing things properly.

这篇关于是否可以使用@import 在 sass 中导入整个目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆