Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@plugin documentation #328

Open
calvinjuarez opened this issue Apr 30, 2015 · 5 comments
Open

@plugin documentation #328

calvinjuarez opened this issue Apr 30, 2015 · 5 comments
Assignees

Comments

@calvinjuarez
Copy link
Member

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).

@matthew-dean matthew-dean self-assigned this Oct 1, 2015
@matthew-dean
Copy link
Member

Yeah, this needs to happen. It's probably Less's coolest new feature that has yet to be known about.

@Ciantic
Copy link

Ciantic commented Jan 3, 2016

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.

@calvinjuarez
Copy link
Member Author

I'm with @Ciantic, there needs to be an easier way to get to Less from a plugin.

@thorn0
Copy link

thorn0 commented Jan 27, 2018

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);

@matthew-dean
Copy link
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants