Delay evaluation of @import / allow custom handling of @import directives
I've outlined what I'm trying to accomplish in great detail in this SO question.
Basically, I'm looking for more control over how @import directives are handled.
My goal is to parse a large number of LESS files in one pass, then selectively merge their ASTs (based on what's @imported) before I output CSS.
Something to get you started...
use 1.4.0 beta and set processImports to false
https://github.com/cloudhead/less.js/blob/master/lib/less/parser.js#L479
That will leave all imports in the AST.
You could then alter the import visitor / proxy it or something and run it yourself after altering the AST.
Ah -- I had noticed there was a processImports option, but when I tried it, it just threw "cannot read property 'rules' of undefined", so I moved on. I didn't realize it was throwing because i was calling tree.toCSS() without doing anything with the import nodes.
This is in node right?
another option would be to override the fileloader
https://github.com/cloudhead/less.js/blob/1.4.1-wip/lib/less/index.js#L105
that is easier in 1.4.1 (I refactored out the parsing.. in 1.4.0 its a less parser, not a file loader).. and if a file fails, try a directory up.
feel free to continue asking here but closing since this isn't actually a bug, more a request for help.
What has changed since the 1.4.1 WIP? fileLoader doesn't seem to exist in the 1.4.2 release.
@daguej I renamed it 1.5.0 wip since it was not a bugfix release.
That makes sense. Thanks.
I just came across this myself. In my case I want less to ignore the imports in both phases, the parse and evaluation phase. I set processImport to false, the parse works, but evaluate produces the following error.
TypeError: Cannot read property 'rules' of undefined at Object.tree.Import.eval (/git/less/lib/less/tree/import.js:106:54) at Object.tree.Ruleset.eval (/git//less/lib/less/tree/ruleset.js:85:53) at Object.toCSS (/git//less/lib/less/parser.js:453:46)
This is in version 1.5.0-b4. Is there any workaround I can do to have processImport work on the eval phase as well?