Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Less: `modifyVars` on files loaded after document loaded

My page uses Less files that are compiled on the client side. I want to load some of those files after page finished loading.

I tried the "Less in the browser" way, but it seems to only work for files that were originally declared in the head part of the page. Declarations I add later (from Javascript) are not processed by the Less...

Another way I tried was "Programmatic Usage", but in this case I have to inject the CSS code myself. It means I cannot use less.modifyVars() any more to change styling later (or I have to trigger recompilation myself and then replace the generated CSS, which I want to avoid).

I like the first way more, but I don't know how to load files after page finished initial loading. Maybe there is a function to load Less file?

Thank you!

like image 247
Andrej Avatar asked Oct 31 '22 10:10

Andrej


1 Answers

I think I found solution:

less.registerStylesheets().then(
        function () {
            less.refresh();
        }
);

First function will reread declarations. The second one will recompile all files (actually not very good).

like image 74
Andrej Avatar answered Nov 09 '22 14:11

Andrej