问题描述
我刚刚学习 Sass 并使用了@import.我有以下情况...
I am just learning Sass and have used the @import. I have the following situation...
_master.scss <-- 这包含我所有的全局变量,如颜色
_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
中,您将导入每个.然后,您可以根据需要将这些较小的文件导入到 child1
和 child2
中.
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 多次导入文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!