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