less-docs
less-docs copied to clipboard
`@plugin` documentation
This is a general call for documentation for the use of @plugin
at http://lesscss.org/usage/#plugins. (See less/less.js#2416, and pull requests less/less.js#2479 & less/less.js#2522).
Yeah, this needs to happen. It's probably Less's coolest new feature that has yet to be known about.
edit
Seems to be working, though getting "less" inside your plugin is a bit annoying
test.js
// Following line is a bit unintuitive:
var less = process.mainModule.children[2].exports;
less.functions.functionRegistry.add("myfunction", function() {
console.log("here!", arguments);
return new less.tree.Color("ff0000");
});
something.less
@plugin "test.js";
test {
color: myfunction();
}
Test it like this: lessc something.less
I think for simple js plugins with no node command, the "less" should be given as a global to the local plugin.
Or alternatively the require
should be available in simple local plugins.
I'm with @Ciantic, there needs to be an easier way to get to Less from a plugin.
Actually, it works like this:
test.js
functions.add('myfunction', function() {
return new tree.Color('ff0000');
});
The variables functions
and tree
are available because that's how it is implemented:
new Function("functions", "tree", "fileInfo", contents);
@thorn0 less
is also available within a @plugin
call in 3.x.
https://github.com/less/less.js/blob/3.x/lib/less/environment/abstract-plugin-loader.js#L65