You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Cannot put import by reference inside of a mixin #2162
I have been working on a complex importing strategy where I set all of my paths in a config file, and then use a mixin to import various different components as needed.
This approach doesn't seem to work well with files imported by reference, however. It seems that importing a file by reference inside of a mixin in this way causes it to output all of the contents of the file, and not just what is used.
To give you a very simplified example, I have something like this:
// config.less
// Normally the sub-mixin calls would be controlled by variables passed in, but for simplicity, let's say both get called always
.importer(){
.import-certain-file();
.import-last-file();
}
.import-certain-file(){
@import "certain-file";
}
.import-last-file(){
@import (reference) "last-file";
}
.import-last-file();
So, certain-file.less contains a rule setting h1 to be black, but I want to override that in my main less file.. using a class name that was specifically made to be extended (imported by reference so that the original class name of ._color-white is not output into my code)
But that messes with the (reference) import, giving me this final output:
Which technically works, but means I've got extra unwanted selectors being dropped into my code.. which is especially bad when in reality, my last-file.less is a big file full of "extension" classes, many of which don't even get used on every project.
I believe the problem lies in the fact that importing by reference inside of a mixin causes all styles inside that file to be output, rather than just when they are used.
changed the title [-]Cannot import by reference after an import through a mixin[/-][+]Cannot put import by reference after an import through a mixin (precedence problem)[/+]on Aug 24, 2014
I think I may have rushed the logic on this a bit, as I'm now realizing that the order of me calling the mixin and importing the file does make sense the way it is, as I am calling the mixin after the original import call. That's what I get for staring at it for too long. I think the focus of this issue should be shifted to the fact that I can't put the (reference) import inside of the mixin without losing the reference functionality. I'm going to edit the text a bit to reflect this.
changed the title [-]Cannot put import by reference after an import through a mixin (precedence problem)[/-][+]Cannot put import by reference inside of a mixin[/+]on Aug 24, 2014
Alright, I've adjusted the issue to take out the parts related to my original misconceptions. Your note about the mixin being able to be called before it is defined is actually a really useful point, which could solve my problem completely, regardless of the issue that's now highlighted in this case, but I still think this issue could be a potential problem in some other use-cases.
Ah, I guess this way it becomes similar to #1896 (not exactly the same but internally it's identical stuff I guess) but probably it's better to keep open just to have more test examples for reference when worked out (I'm assigning same lables as in #1896).
Activity
[-]Cannot import by reference after an import through a mixin[/-][+]Cannot put import by reference after an import through a mixin (precedence problem)[/+]blakemann commentedon Aug 24, 2014
I think I may have rushed the logic on this a bit, as I'm now realizing that the order of me calling the mixin and importing the file does make sense the way it is, as I am calling the mixin after the original import call. That's what I get for staring at it for too long. I think the focus of this issue should be shifted to the fact that I can't put the (reference) import inside of the mixin without losing the reference functionality. I'm going to edit the text a bit to reflect this.
[-]Cannot put import by reference after an import through a mixin (precedence problem)[/-][+]Cannot put import by reference inside of a mixin[/+]blakemann commentedon Aug 24, 2014
Alright, I've adjusted the issue to take out the parts related to my original misconceptions. Your note about the mixin being able to be called before it is defined is actually a really useful point, which could solve my problem completely, regardless of the issue that's now highlighted in this case, but I still think this issue could be a potential problem in some other use-cases.
Sorry for the confusion!
seven-phases-max commentedon Aug 24, 2014
Ah, I guess this way it becomes similar to #1896 (not exactly the same but internally it's identical stuff I guess) but probably it's better to keep open just to have more test examples for
referencewhen worked out (I'm assigning same lables as in #1896).Fixing import by reference
Created separate test case for less#2162
SomMeri commentedon Dec 7, 2015
This should be fixed by #2729 .