0.0.1 • Published 3 years ago

less-plugin-dynamic-variable v0.0.1

Weekly downloads
1
License
MIT
Repository
-
Last release
3 years ago

(⚠️WIP) still unavailable

less-plugin-dynamic-variable

Make less variable dynamic by css variable, compatible with less function

npm i -D less-plugin-dynamic-variable

or

yarn add -D less-plugin-dynamic-variable

lessc usage

and then on the command line,

lessc file.less --dynamic-variable

Programmatic usage

const LessPluginCssDynamicVariable = require('less-plugin-dynamic-variable');

less
  .render(lessString, { plugins: [LessPluginCssDynamicVariable] })
  .then(({ css }) => {
    console.log(css);
  });

Example

// dynamtic-variable.config.js
module.exports = {
  variable: ['base-number', 'multiply-number'],
};
// multiplyTwo is a function to multiply number by 2, just for example
@base-number: 10;
@multiply-number: multiplyTwo(@base-number);

[scope='local'] {
  @base-number: 2;
}

.use {
  base: @base-number;
  multiply: @multiply-number;
}

outputs:

:root {
  --base-number: 10;
  --multiply-number: 20;
}

:root[scope='local'] {
  --base-number: 2;
  --multiply-number: 4;
}

.use {
  color: var(--base-number);
  multiply: var(--multiply-number);
}