-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
import a file but override and merge the selectors and properties #772
Comments
Not sure this would work, but might be a temporary work around for what you're trying to do:
Granted you end up with some duplicate code, but it uses the css cascade so |
I really like the concept of @extend. It seems like it would really help keep your file sizes to a minimum. Mobile sites could benefit from this tremendously. |
We are extending Twitter Bootstrap a lot too and a lot of code gets duplicated and is not needed. Have you considered changed less behavior so:
Would became:
Instead of:
Note the Would be a really nice thing, what do you think? |
We run our LESS scripts through a build process, so I can definitely see how @extend would be better suited for a build based LESS project. Does your suggestion mean you manually remove the duplicate styles or are you doing it another way? |
@sethaldridge For now we are just letting the duplicate code as the browser will do the hard work of not using it, but we know its a waste of bytes and processing time. I sugest that there is no need for using |
This sounds good in theory, but CSS inheritence can be quite complex. Consider this
How are these re-written? Maybe it's easier than it looks, but it seems like there's a lot of opportunity to get it wrong for a very small benefit (or no perceivable performance benefit). |
@MatthewDL Your point is valid, but i think this optimization should be used only for simple cases like the one we pointed out cause the objective is to extend a library (twitter bootstrap in my case), so most of the cases would be a direct replacement. Your case illustrates the simple cases: .brother and .father div.brother should not be touched in this case, unless there was a div.brother rule defined before that would be replaced (the attributes).
|
I agree with @ricardovf. All replacements would be one to one. |
I don't think that you'd need to introduce a new keyword for this - what you're really asking for is a CSS optimiser, and that would be a great thing to roll into LESS. That said, I've not seen one that goes as far as eliminating overridden properties or repeated definitions. |
@Synchro Agree. Can you point me to one of this tools that you saw? |
There are quite a few, such as http://www.cleancss.com/ and http://www.codebeautifier.com/ but nearly all seem to use CSSTidy: http://csstidy.sourceforge.net/ |
I think CSSO needs a mention here. |
We can't eliminate properties because this is quite often used where a browser supports one version of a property but not another.. we don't want to remove that that case. |
We hope #1210 to solve this use-case when you use that with |
We are doing some pretty heavy overwrites to a framework that uses LESS and we've found that in order to customize the library we have to import their code and then add our code to the bottom of it, which allows us to update the base library without overwriting our own changes.
However this adds a lot of extra code we don't need.
What I'm proposing woud be an additional method to how @import works. @extend would allow you to make changes to a specific file and it would overwrite the default options with your changes.
Example:
Updated based on comments to better illustrate usage
myFirstFile.less:
mySecondFile.less
Output file mySecondFile.css
This would make our files much smaller while allowing us to decouple our changes from the main .LESS files.
Sorry if this is not the preferred way to suggest this change.
The text was updated successfully, but these errors were encountered: