Even after reading https://github.com/cloudhead/less.js/issues/212, I don't understand the meaning of the @import-once statement.
相关问题
- Adding a timeout to a render function in ReactJS
-
Why does the box-shadow property not apply to a
- Add animation to jQuery function Interval
- jQuery hover to slide?
- Issue with star rating css
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 importutils.less
that contains useful mixins or variables. When you do this, the mixins get duplicated in the compiled code (css file). Once for each timeutils.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
.@import-once
simply means "If it was already imported before, don't import it again". It's done to prevent duplication of CSS styles.