I have a global.less file which calls a variables.less file and then a component.less file.
I want to have default variables set-up inside the component file and be able to override them in the variables file.
But the component file comes after the less file so the default component variables will override the variables set in the variables.less file.
Is there any option in Less I can use like Sass's !default keyword?
The solution as stated by @seven-phases-max is to move the variables.less file after my components file. e.g.
Files
Inside the global.less file call the two files in the following order
@import "component.less";
@import "variables.less";
Inside the component.less file you can have a default variable @color: red and the following css
body {
background-color: @color
}
If you compile the previous code, the body will have a background color of red - as it has used the default variable in the component file.
Inside the variables.less file you can override the variable @color: blue
Now when the less files get compiled, the background color of the body tag will be blue, not red - redeclaring the variable @color inside the variables.less file overrides the default @color variable in the components.less file
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With