postcss-transform-css-var

1.0.0 • Public • Published

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 JS API

postcss([require('postcss-transform-css-var')]).process(yourCSS);

Gulp

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!

License

This project is licensed under the MIT License.

Package Sidebar

Install

npm i postcss-transform-css-var

Weekly Downloads

2

Version

1.0.0

License

MIT

Unpacked Size

6.71 kB

Total Files

6

Last publish

Collaborators

  • luckymore