0.0.2 • Published 7 years ago

@jasonnutter/less-js-vars v0.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
7 years ago

@jasonnutter/less-js-vars

Utility to parse Less variables into JavaScript variables.

Installation

yarn add @jasonnutter/less-js-vars --save
npm install @jasonnutter/less-js-vars --save

Usage

Assumes that your code has extracted the raw text of the less file, e.g. using raw-loader or fs.readFile.

Variable names will be in camelCase.

colors.less:

@white: #fff;
@black-color: #000;

raw-loader:

import lessJsVars from '@jasonnutter/less-js-vars';
import colors from '!!raw-loader!./colors.less';

const parsedColors = lessJsVars(colors);

console.log(parsedColors.white);
console.log(parsedColors.blackColor);

fs.readFile:

import lessJsVars from '@jasonnutter/less-js-vars';
import fs from 'fs';

fs.readFile('./colors.less', 'utf8', (err, colors) => {
    const parsedColors = lessJsVars(colors);

    console.log(parsedColors.white);
    console.log(parsedColors.blackColor);
});

Prior Art

Inspired by less-vars-to-js.