what is the LESS CSS statement @import-once good for?

六月ゝ 毕业季﹏ 提交于 2019-12-21 07:04:33

问题


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


回答1:


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.

When should I use @import-once instead @import?

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:

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




回答2:


@import-once simply means "If it was already imported before, don't import it again". It's done to prevent duplication of CSS styles.



来源:https://stackoverflow.com/questions/13759301/what-is-the-less-css-statement-import-once-good-for

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!