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
Feature request: new option for import directive: "optional" #2145
This is a fairly simple option which I'd like to see in less.js.
It would look like this: @import (optional) "filename";
or @import-optional (reference) "filename"; (this way it can be combined to other import options)
If less does not find the file marked as optional, it won't fail and just continue the compiling process.
The use case is the following:
Less.js is part of a build process. (grunt based)
During this process, there are specific cases when we want to override the default styles. There are already variables than can be overridden for example.
If we don't do that, less will fail when overridden-variables.lessis not there.
It would be much easier to mark some files as optional that won't cause a problem if they are not present and this simplifies the build process.
It would work, yes, but it was a simplified example. There are more files concerned and the build is more complex so I didn't think of creating an empty less file for each of them. You are right but it would be nice for less to not fail the whole compiling process just because one file/import is not always needed.
Do you realise that variables can be over-ridden by definitions after they are used.. e.g. you could have one import right at the end.. does that simplify things?
I know the current possibilities so I'll describe what I am doing with more details. We are using less to build skins which can be children of one another for a given product. A child can override its parent variables, mixins or styles directly, then a second level of customisation during the build is offered, when again, it's possible to override the skins variables, etc to adapt the product to the website where it will be. This, is also based on Twitter Bootstrap from which we import some of the less files. It is actually a nice way to rapidly create and deploy new variations and it's easy to fix something in the parent skin for the benefit of all the children. But, we don't need to import everything all the time. So it would be easier to just indicate an import as optional in our case. As SomMeri said, we could put empty less files everywhere but it would be a lot of useless files.
I've added ready for implementation because it seems like it would be quite a simple addition to add and would have some benefit. If any of the core team disagree please feel free to substitute with NeedsDecision and add a comment. @AoDev would you be prepared to contribute this feature?
Hi,
I am really happy you consider this feature :) @lukeapage Sure, I will help. (I am not familiar with less.js source code or parsers yet).
Is there some steps I should follow to start working on it?
I'd like to discuss what would be the best syntax for this.
I'd like to discuss what would be the best syntax for this.
There's no choice in this case. All other import options are used like this: @import (less, reference, multiple) "file";
So optional goes the same way (in fact you don't need to add any special code for the @import syntax, just add the new keyword somewhere around here and the code to handle it ... hmm, probably around here)
Yep, because I suspect that (since v2 is coming and it would not be a good idea to come up with new-feature-v1.x-release) if you make a PR for this to the 1.x branch the efforts needed to move it to v2 later will overweight the efforts needed to code the feature itself (though @lukeapage will correct me if I'm wrong :)
What's the current status on this feature? Is someone working on it? I've been looking for a way to import a .less file that will ignore the import if the specified file doesn't exist, but haven't been able to find a solution that doesn't include using conditional variables (which eliminates the purpose since I have to set the variable anyway and might as well just set the @import).
@import (optional) would be awesome to have. I just checked the version history for the latest releases but couldn't find any mention of this.
Activity
SomMeri commentedon Aug 13, 2014
Cant you just create an empty
overridden-variables.lessfile if you do not need to override anything?AoDev commentedon Aug 13, 2014
It would work, yes, but it was a simplified example. There are more files concerned and the build is more complex so I didn't think of creating an empty less file for each of them. You are right but it would be nice for less to not fail the whole compiling process just because one file/import is not always needed.
lukeapage commentedon Aug 14, 2014
Do you realise that variables can be over-ridden by definitions after they are used.. e.g. you could have one import right at the end.. does that simplify things?
AoDev commentedon Aug 14, 2014
I know the current possibilities so I'll describe what I am doing with more details. We are using less to build skins which can be children of one another for a given product. A child can override its parent variables, mixins or styles directly, then a second level of customisation during the build is offered, when again, it's possible to override the skins variables, etc to adapt the product to the website where it will be. This, is also based on Twitter Bootstrap from which we import some of the less files. It is actually a nice way to rapidly create and deploy new variations and it's easy to fix something in the parent skin for the benefit of all the children. But, we don't need to import everything all the time. So it would be easier to just indicate an import as optional in our case. As SomMeri said, we could put empty less files everywhere but it would be a lot of useless files.
lukeapage commentedon Sep 3, 2014
I've added ready for implementation because it seems like it would be quite a simple addition to add and would have some benefit. If any of the core team disagree please feel free to substitute with NeedsDecision and add a comment.
@AoDev would you be prepared to contribute this feature?
AoDev commentedon Sep 15, 2014
Hi,
I am really happy you consider this feature :)
@lukeapage Sure, I will help. (I am not familiar with less.js source code or parsers yet).
Is there some steps I should follow to start working on it?
I'd like to discuss what would be the best syntax for this.
@import-optional [(reference | ...)]@import [(optional)] [(reference | ...)]seven-phases-max commentedon Sep 15, 2014
There's no choice in this case. All other import options are used like this:
@import (less, reference, multiple) "file";So
optionalgoes the same way (in fact you don't need to add any special code for the@importsyntax, just add the new keyword somewhere around here and the code to handle it ... hmm, probably around here)AoDev commentedon Sep 15, 2014
@seven-phases-max Thanks I'll check it. (although I see that your links points to 2.0.0 branch)
seven-phases-max commentedon Sep 15, 2014
Yep, because I suspect that (since v2 is coming and it would not be a good idea to come up with new-feature-v1.x-release) if you make a PR for this to the 1.x branch the efforts needed to move it to v2 later will overweight the efforts needed to code the feature itself (though @lukeapage will correct me if I'm wrong :)
vtamm commentedon Dec 15, 2014
What's the current status on this feature? Is someone working on it? I've been looking for a way to import a .less file that will ignore the import if the specified file doesn't exist, but haven't been able to find a solution that doesn't include using conditional variables (which eliminates the purpose since I have to set the variable anyway and might as well just set the
@import).@import (optional)would be awesome to have. I just checked the version history for the latest releases but couldn't find any mention of this.AoDev commentedon Dec 15, 2014
@Villeman I said I would help but haven't done anything yet. I'm a bit overloaded with my own stuff. I don't think someone else is working on this.
optional imports