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.

modifyVars not being passed on

See original GitHub issue

I have an index.less file that decides what variables file to load in by a variable like so:

@theme-variant: "a-theme.less";

@import "./@{theme-variant}";

I have less files that load in that index file:

@import "~theme-variant-variables";

I am setting a value for the variable in my webpack.config.js file:

lessOptions.modifyVars = {
   "theme-variant": `"${v}-theme.less"`
}

If I move the contents of the index.less file into a directly imported less file everything works as I expect, I can switch the variables file chosen based on the webpack config logic, sadly if I try and centralize those two lines of less into a file that the directly imported less files import themselves it stops working. I see less loader calls less with the expected config so I’m guessing the less compiler doesn’t propagate variables/options to imported less files. Is that expected?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
seven-phases-maxcommented, Feb 25, 2018

I’ll close this then as it’s more like an expected (defined as “undefined/unspecified” in this case) behaviour rather than an issue that could be actually fixed somehow. Though any improvement ideas and especially PRs are always welcome… I don’t think anybody is going to get into this in a foreseeable future.

1reaction
seven-phases-maxcommented, Feb 23, 2018

By the way. For your use-case (if the “*-theme.less” is only about variables/mixins for a specific theme), you could try something like:

  • Leave the default @import "a-theme.less"; to be expicit there (i.e. w/o any interpolation) or remove it completely.
  • With modifyVars set the importing statement itself (e.g. @import "custom-theme.less"; directly).

Note that while modifyVars pretends it’s only about variables bla-bla-bla - in fact it does nothing but appending an arbitrary text to the end of the root file. I.e. in case of lessc it’s realy just --modify-vars="whatever-less-code foo {bar: baz;}". I don’t know though what formats webpack’s less-loader can pass through, hmm… lessOptions.modifyVars = "an arbitrary code"; maybe?

That’s obviously a hack but in fact it is quite predictable hack (as it abuses only modifyVars format and not the language itself like the initial combo does).

Read more comments on GitHub >

github_iconTop Results From Across the Web

ModifyVars issue when trying to change variables one by one
I want to be able to modify each variable from my LESS file in the browser when a value is added in the...
Read more >
Customize Theme
In ConfigProvider, we pass context through DesignTokenContext . When theme is undefined , a layer of Provider will not be set, so React...
Read more >
Theming Ant Design: A Detailed Step by Step Guide
Ant Design styles rely on the CSS post-processor less. It's made clear that the correct way to theme Ant Design is to override...
Read more >
LESS - Using Less In The Browser
useFileCache − Uses per session file cache. The cache in less files is used to call the modifyVars where all the less files...
Read more >
How to use the customize-cra.addLessLoader function in ...
addLessLoader examples, based on popular ways it is used in public projects. ... Use Snyk Code to scan source code in minutes -...
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