question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can less variables be compiled to css custom properties? How to merge less code in components into one large .less file?

See original GitHub issue
div{
   @main-color: red;
   color: @main-color;
   border: 1px solid @main-color;
}

compiled out:

div{
    --main-color: red;
    color: var(--main-color);
    border: 1px solid var(--main-color);
}

I know that the variable of less can be used not only for the value of the property, but also for the key of the property. But if don’t consider the latter, because it is not used in my project, how to achieve the compilation from less variables to css custom properties? Thanks!

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:4
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

9reactions
Gervwykcommented, Jun 26, 2020

@hbshun did you manage to get this working? I’d be very interested to figure out how we can change less variable client side in libraries like antd. Any ideas?

1reaction
matthew-deancommented, May 7, 2019

If you want to do the latter, why not just write it that way? There’s no reason to use a Less var that’s not used in a Less function.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Features In-Depth | Less.js
Less extends CSS with dynamic behavior such as variables, mixins, operations and ... You can easily treat properties like variables using the $prop...
Read more >
How to combine less variables from multiple files into one file?
The answer to your question is "Yes". You can import all .less variable files in a single .less file and use that in...
Read more >
A Complete Guide to Custom Properties | CSS-Tricks
Custom properties can make code easier to maintain because you can update one value and have it reflected in multiple places.
Read more >
The difference between SASS/LESS variables and CSS ...
In CSS custom properties, you use double dash --variable-name , but you have to define the scope of the variable, similar to doing...
Read more >
Retrofitting Theming Into A Legacy App Using LESS CSS And ...
If a style is truly global, it should get codified in a global variable. However, if a CSS component has one-off styles specific...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found