Dynamically changing less variables

Marvin,
I wrote a function that does exactly what you’re looking for, last night.

I have created a fork on Github;
https://github.com/hbi99/less.js/commit/6508fe89a6210ae3cd8fffb8e998334644e7dcdc

Take a look at it. Since this is a recent addition, I’d like to hear your comments on the addition. This solution fits my needs perfectly and I think it will do the same for you.

Here is a basic sample;

Sample LESS:

@bgColor: black;
@textColor: yellow;
body {background: @bgColor; color: @textColor;}

From JS:

less.modifyVars({
  '@bgColor': 'blue',
  '@textColor': 'red'
});

Leave a Comment