2

So I'm currently using .Less and want to create a get command to read the .less attributes and push them to an object so that I can then use this data in an angularJS directive. But I'm having trouble figuring out the best way to approach this.

Example .less file contains this:

@lightBg: #f5f8f9;  
@lightText: #f5f8f9;  
@semiLightText: #e7e7e7;  
@semiLightBg: #e7e7e7;

The idea is to get the data from this file and push the data into an object like so:

{name:"@lightBg", hex:"#f5f8f9"};

Example get command in angular so far:

 $scope.hexcss = {};
     $http.get('mixins.less').then((response) => {
     });

Any guidance on the best way to achieve this would be greatly appreciated!

3
  • Might be a better idea to do something like this: jonathanfielding.com/…. Instead doing an HTTP request each time you those less variables, as your less is compiled once, you should be able to get your variables as JSON once :). Commented Jun 2, 2017 at 11:44
  • Please check this, stackoverflow.com/questions/8987550/… Commented Jun 2, 2017 at 12:46
  • See github.com/Craga89/less-plugin-variables-output. Though usually it's more efficient to do the opposite: have a JSON with your custom color and apply them to your Less project/theme during compilation. Commented Jun 2, 2017 at 16:53

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.