Even after reading https://github.com/cloudhead/less.js/issues/212, I don’t understand the meaning of the @import-once statement.
Even after reading https://github.com/cloudhead/less.js/issues/212 , I don’t understand the meaning of the @import-once statement.
Share
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
@importyou have done between files, and that’s the reason behind@import-once, to avoid style duplication.When should I use
@import-onceinstead@import?Suppose you have
main.lesswhich imports other less files. And those files all importutils.lessthat contains useful mixins or variables. When you do this, the mixins get duplicated in the compiled code (css file). Once for each timeutils.lesswas 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-onceis removed and is now default behavior for@import.