如何停止使用 SASS 和 Midscape 多次导入文件? [英] How do I stop a file being imported more than once with SASS and Midscape?

查看:34
本文介绍了如何停止使用 SASS 和 Midscape 多次导入文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚学习 Sass 并使用了@import.我有以下情况...

I am just learning Sass and have used the @import. I have the following situation...

_master.scss <-- 这包含我所有的全局变量,如颜色

_master.scss <-- this contains all my global variables like color

_child1.scss <-- 这是我的一个子页面,但它需要来自 master 的东西

_child1.scss <-- this is for one of my child pages but it needs stuff from master

_child2.scss <-- 这是我的其他子页面之一,但它也需要来自 master 的东西

_child2.scss <-- this is for one of other my child pages but it also needs stuff from master

现在的问题是 _master 越来越大了.因此,当我使用 Visual Studio 2012 中的 Mindscape 工具保存我的 Scss 文件(子项)时,我注意到生成的 css 文件包含两个子项的主文件中的所有 css.

Now the problem is _master is getting quite big. So when I save my Scss files (the children) using Mindscape tools in Visual Studio 2012 I notice that the generated css files include ALL the css from the master file for both children.

基本上,每次我想用@import"引用主文件时,我都会得到重复的 css,这对性能不利.有什么办法可以避免这种情况吗?

Essentially I am getting duplicate css every time I want to reference the master file with '@import' which is not good for performance. Is there any way to avoid this?

推荐答案

如果我理解的话,听起来你真的可以从更好地使用 部分.如果您不想导入所有 _master.scss,您应该将其分解为组件,然后根据需要导入它们.

If I'm understanding, it sounds like you could really benefit from better use of partials. If You don't want all of _master.scss to be imported, you should break it apart into components and then import those as you need them.

例如,如果 master.scss 包含您网站上的所有字体、颜色和列布局,您可以将其分解为以下内容:

For example, if master.scss contains all the fonts on your site, the colors, and the column layout, you could break it down to something like the following:

_fonts.scss
_colors.scss
_column.scss

master.scss 中,您将导入每个.然后,您可以根据需要将这些较小的文件导入到 child1child2 中.

In master.scss, you'd import each. Then you could import these smaller files into child1 and child2 as you need them.

如果这不是您要找的内容,请尝试澄清您的问题,我可能会提供更多帮助.

If this isn't what you're looking for, please try clarifying your question and I might be able to help a bit more.

更新:在与 Imjared 讨论后,他说我应该只创建一个包含变量的文件.这似乎对我有用,所以我正在更新这个答案并将其标记为正确.

UPDATE: After discussing with Imjared he said that I should just create a file with variables in only. This would seem to work for me so I am updating this answer and marking it as correct.

这篇关于如何停止使用 SASS 和 Midscape 多次导入文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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