Skip to content

luckymore/postcss-transform-css-var

Repository files navigation

PostCSS CSS var to Less var PostCSS Logo

NPM Version BGitter Chat

A PostCSS plugin to convert CSS variables to Less variables

Installation

npm install postcss-transform-css-var

Examples

/* input css/less */
:root { --color: black; }
@prefix: ~'flyfly';
.@prefix {
  &-foo {
    --color: red;
    // --c: 10px;
    &-bar {
      background: var(--color, blue);
    }
  }
}
/* output less */
@color: black;
@prefix: ~'flyfly';
.@prefix {
  &-foo {
    @color: red;
    // --c: 10px;
    &-bar {
      background: @color;
    }
  }
}

Usage

postcss([require('postcss-transform-css-var')]).process(yourCSS);
const gulp = require('gulp');
const postcss = require('gulp-postcss');
const syntax = require('postcss-less');
const varConvert = require('postcss-transform-css-var');
const through = require("through2");

const convertPipe = () =>
  through.obj(async(file, enc, cb) => {
    let result = await postcss([varConvert()]).process(file.contents, {
      from: undefined,
      syntax: syntax
    });
    file.contents = Buffer.from(result.css, enc);
    cb(null, file);
  })

gulp.src('src/**/*.less', { basePath: './' })
  .pipe(convertPipe())
  .pipe(gulp.dest('./', { overwrite: true }))

Tests

npm test

TODO

  • support option type: scss

Special thanks

This package is a fork of postcss-css-var-to-less-var. Thanks a lot lauthieb for this great work!

Star History

Star History Chart

License

This project is licensed under the MIT License.

About

A PostCSS plugin that transforms `css var` to `less var`.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published