Skip to content
This repository was archived by the owner on Sep 3, 2019. It is now read-only.

Latest commit

 

History

History
52 lines (38 loc) · 1.25 KB

File metadata and controls

52 lines (38 loc) · 1.25 KB

lessobjectify

The fork of cssobjectify by Andrey Popp. Source transform for browserify or dcompose which converts LESS into JSON objects which can be used further by libraries like React to assign styles to UI components.

styles.less:

.block {
  font-size: 12px;
  background-color: red;

  &__element {
    &--modifier {
      background-color: blue;
    }
  }
}

myapp.js:

var React = require('react-tools/build/modules/React');
var Styles = require('./styles.less');

var MyComponent = React.createClass({
  render: function() {
    return (
      <div style={Styles['.block__element--modifier']}>
        Hello, world!
      </div>
    )
  }
});

Usage

Use npm to install the package:

% npm install lessobjectify

And use it with browserify:

% browserify -t lessobjectify ./myapp.js

where ./myapp.js or its dependencies can reference *.css files by require(...) calls.