Less.js: less.modifyVars does not work with less-loader

Created on 12 Sep 2017  路  10Comments  路  Source: less/less.js

I am using webpack and less-loader in order to output my bundle. Providing following works:

use: ['less-loader?{"modifyVars":{"@my-color":"red"}}']

This on other hand does not:

const less = require('less')

less.modifyVars({
    '@my-color': 'red'
})
less.refreshStyles()

But I actually need the latter one, as I would like to change the variables dynamically by user.

consider closing question stale

Most helpful comment

@lxwbr @deepika-Gopala
Did you guys solved this?
I have the same problem.

All 10 comments

Hi @zunder , any update on this , i have the same requirement and the styles doesnt seems to work , problem is its not recompiling again as the reference in the browser is text/css instead of text/less

Wouldn't this be more of a less-loader question?

Exactly , so the already compiles less file is not taking the recent values and recompiling to the new style.css in the browser, plus the new styles that are to be reflected are authentication specific and dynamic from the api result. so as known its not great to call api in the webconfig.js.

...

less.modifyVars({
    '@my-color': 'red'
})
less.refreshStyles()

Both are browser-script specific functions. In the node version the modifyVars stuff should be passed as an option (just like any other option/parameter see below) - for example see lessc code:

Technically there's no modifying/set/do-something functions in the node version at all except the only official render.

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@lxwbr @deepika-Gopala
Did you guys solved this?
I have the same problem.

Same problem here

Anything?

Anything?

AFAICT, this hasn't changed as this is still a less-loader issue, not a less issue, unless someone can demonstrate otherwise. This team does not maintain less-loader.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

papandreou picture papandreou  路  7Comments

awebdev picture awebdev  路  4Comments

xblakestone picture xblakestone  路  3Comments

seven-phases-max picture seven-phases-max  路  6Comments

BrianMulhall picture BrianMulhall  路  4Comments