less-var-to-css-var
Version:
Convert Less Var To CSS Var
120 lines (77 loc) • 2.71 kB
Markdown
Convert Less Var To CSS Var
[![version][npm-img]][npm-url]
[![license][mit-img]][mit-url]
[![size][size-img]][size-url]
[![download][download-img]][download-url]
```sh
yarn add less-var-to-css-var
```
```bash
less-var-to-css-var -i '~/styles/variables.less' -o '~/styles/variables-css2.less' -t ':root' -h "@import '/src/styles/variables.less';"
```
```js
const lessVarToCssVar = require('less-var-to-css-var');
lessVarToCssVar({
inputPath: '~/styles/variables.less',
outputPath: '~/styles/variables-css.less',
scopeTag: ':root',
header: "@import '/src/styles/variables.less';",
//
// Dark Mode
// supported since v1.5.0
// css var MUST include `--dark` like
// `@color-gray-7:` // normal
// `@color-gray-7--dark:` // dark
scopeTagDark: '.comp-wrapper--alwaysDarkMode,\n' +
':global(.@{THEME--DARK}) .comp-wrapper',
removeAllRootDarkVars: true,
removeAllDarkDarkSuffix: true,
//
// supported since v1.3.0
jsOutputPath: `${CUR_DIR}/variables.js`,
jsVar: 'PAGE_COLOR',
jsheader: "import React, { useEffect } from 'react';",
jsValueObjectKv: true,
//
// supported since v1.3.0
useRealValue: true, // Use real CSS values instead of the --a: @a; mapping
useRealValueFilterLessVar: '____IS_A_LESS_VAR____', // Replace the string of the less variable
});
```
Input
```less
// variables.less (input)
@import '~antd/lib/style/themes/default.less';
@THEME--DARK: ~'theme-dark';
@font-size-base: 14px;
```
Output
```less
// variables-css.less (output)
@import '/src/styles/variables.less';
:root {
--THEME--DARK: @THEME--DARK;
--font-size-base: @font-size-base;
}
// BTW: more details can be found in the `/__test__` folder.
```
MIT © [Jason Feng][author-url]
<!-- badges -->
[]: https://github.com/SolidZORO
[]: https://img.shields.io/npm/l/less-var-to-css-var.svg?style=flat&colorA=000000&colorB=000000
[]: ./LICENSE
[]: https://img.shields.io/npm/v/less-var-to-css-var?style=flat&colorA=000000&colorB=000000
[]: https://www.npmjs.com/package/less-var-to-css-var
[]: https://img.shields.io/bundlephobia/minzip/less-var-to-css-var?label=bundle&style=flat&colorA=000000&colorB=000000
[]: https://www.npmjs.com/package/less-var-to-css-var
[]: https://img.shields.io/npm/dt/less-var-to-css-var.svg?style=flat&colorA=000000&colorB=000000
[]: https://www.npmjs.com/package/less-var-to-css-var
[]: https://github.com/SolidZORO/less-var-to-css-var/workflows/badge.svg
[]: https://github.com/SolidZORO/less-var-to-css-var/actions