本文介绍了什么是LESS CSS语句@ import-once好?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

即使在阅读 https://github.com/cloudhead/less.js/issues/212,我不明白@ import-once语句的含义。

Even after reading https://github.com/cloudhead/less.js/issues/212, I don't understand the meaning of the @import-once statement.

推荐答案

少数文件(我喜欢12包括媒体查询,重置等),有时你不能控制你在文件之间做了多少 @import ,这就是 @ import-once 背后的原因,以避免样式重复。

When you work with LESS you can have few less files (I have like 12 including media-queries, resets, etc), and sometimes you don't have the control of how many @import you have done between files, and that's the reason behind @import-once, to avoid style duplication.

假设您有 main.less ,它会导入其他较少的文件。这些文件全部导入包含有用的mixins或变量的 utils.less 。当你这样做时,mixins在编译的代码(css文件)中重复。每次导入 utils.less 后,即使您的CSS文件应为1mb,而不是20kb。如果像这样,您应该使用 @ import-once

Suppose you have main.less which imports other less files. And those files all import utils.less that contains useful mixins or variables. When you do this, the mixins get duplicated in the compiled code (css file). Once for each time utils.less was imported, even your CSS file should be 1mb instead 20kb. In case like this one you should use @import-once.

EDIT:

正如@TJ所指出的,由于LESS 1.4.0, @ import-once @import 的行为。

As pointed by @TJ, since LESS 1.4.0, @import-once is removed and is now default behavior for @import.

这篇关于什么是LESS CSS语句@ import-once好?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!