get-less-vars
The way for getting computed variables from less
Last updated 6 months ago by moyuyc .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install get-less-vars 
SYNC missed versions from official npm registry.

get-less-vars

Build status Test coverage NPM version NPM Downloads Prettier Conventional Commits

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

lib/index.js:90-127

Parameters

  • lessText {string}
  • options {{}}
    • options.nameCase {string} Use change-case for varied name case. (optional, default null)

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 or git 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)' or git 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 ????

Current Tags

  • 1.2.1                                ...           latest (6 months ago)

5 Versions

  • 1.2.1                                ...           6 months ago
  • 1.2.0                                ...           a year ago
  • 1.1.0                                ...           a year ago
  • 1.0.1                                ...           a year ago
  • 1.0.0                                ...           a year ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 2
Last Day 0
Last Week 2
Last Month 0
Dependencies (5)
Dev Dependencies (12)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |