如何仅在罗盘中导入scss文件? [英] How to import scss file in compass only if it exists?

查看:70
本文介绍了如何仅在罗盘中导入scss文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要有一个特殊的scss文件,该文件对于项目的每次安装都是不同的,因此我不想将其包含在git存档中。但是,即使该文件不存在,一切也应该可以使用。

I need to have special scss file that is different for every installation of the project, so I don't want to include it in git archive. But everything should work even if this file doesn't exist.

有没有办法@import scss文件,只要它存在,忽略文件未找到错误?

Is there any way to @import scss file only if it exists, ignoring file not found error?

推荐答案

您需要使用 import-path选项执行此操作,其中您要导入的路径包含要导入的后备文件(在我们的示例中,想要一个空文件)。

You'll need to make use of the "import-path" option to do this, where the path you're importing contains the fallback files you want to import (in our case, we want an empty file).

文件结构

├── fallback
    ├── _example.scss // <-- our blank file
├── _example.scss // <-- the file for the user to customize (optional)
├── style.scss

在style.scss中:

@import "example";
/* the rest of our styles */

当您运行sass命令时,您会会这样写:

When you run your sass command, you would write it like this:

sass --watch ./css:./sass --load-path ./sass/fallback

请注意,fallback目录不必位于您的sass目录中,它可以位于您喜欢的文件系统。

Note that the fallback directory does not have to be inside your sass directory, it be anywhere on the filesystem you like.

另请参见: SCSS如何定位局部?

您可能会发现如果您在多个项目中使用此技术,则指南针扩展会更方便一些。它将自动为您设置加载路径。您可以在此处了解有关创建扩展程序的更多信息: http://compass-style.org/help/教程/扩展名/

You may find that creating a Compass extension is a little more convenient if you're using this technique in multiple projects. It will automatically setup the load-path for you. You can learn more about creating extensions here: http://compass-style.org/help/tutorials/extensions/

这篇关于如何仅在罗盘中导入scss文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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