README
get-less-vars
The way for getting computed variables from less
Why use it?
get-less-vars
use official less
for parsing less
text, then get computed variables.
Rather than using string matching for getting raw value like less-vars-loader.
Installation
npm install less@3.9 get-less-vars
# or use yarn
yarn add less@3.9 get-less-vars
API
getLessVars
- See: less options
Parameters
lessText
{string}options
{{}}options.nameCase
{string} Use change-case for varied name case. (optional, defaultnull
)
Examples
const getLessVars = require('get-less-vars')
const fs = require('fs')
// The contents of `/path/to/main.less`
// @color: white;
// @height: 100px;
// @width: 20px + @height;
// @height: 40px;
;(async () => {
await getLessVars(fs.readFileSync('/path/to/main.less').toString(), {
filename: '/path/to/main.less'
})
// => {color: 'white', height: '40px', width: '60px'}
})()
Returns Promise<{}>
Regard as a webpack loader
Loader Options
The options extend get-less-var
disableWebpackLessPlugin
Whether disable the less plugin from less-loader
which enhanced the @import
like @import '~lib/foo.less'
- Type:
boolean
- Default:
false
nameCase
- Type:
string
- Default:
'camel'
modules
Export variables by which way, It's useful for tree shaking by using 'es'.
- Type:
'es'|'cjs'
- Default:
'es'
Example
main.less
@main_color: red;
@config: {
@size: 20px;
};
main.js
import { config, mainColor } from '!get-less-vars/loader!./main.less'
// => mainColor === 'red'
// => config {size: '20px'}
Contributing
- Fork it!
- Create your new branch:
git checkout -b feature-new
orgit checkout -b fix-which-bug
- Start your magic work now
- Make sure npm test passes
- Commit your changes:
git commit -am 'feat: some description (close #123)'
orgit commit -am 'fix: some description (fix #123)'
- Push to the branch:
git push
- Submit a pull request :)
Authors
This library is written and maintained by imcuttle, moyuyc95@gmail.com.
License
MIT - imcuttle 🐟