Merge two inactive files into one

Suppose I have two less files, first.less

.a {
  .b {
    font-size: 13px;
  }
  color: lime;
}

and second.less

@import "first.less";
.a {
  font-family: sans-serif;
}

I would like to combine them into one by combining trees:

.a {
  .b {
    font-size: 13px;
  }
  color: lime;
  font-family: sans-serif;
}

So, something similar to compiling on .css, but preserving the structure .less. Is it possible to do this using a command line tool, a library, or programmatically?

+4
source share
1 answer

What @helderdarocha means, you can write your own javascript and run it using node.js. See for example http://lesscss.org/#using-less-usage-in-code and http://onedayitwillmake.com/blog/2013/03/compiling-less-from-a-node-js-script/

  • : npm install less ( node_modules)
  • second.less
  • test.js, :
    var less = require( 'less' );
    var fs = require( 'fs' );
    var parser = new less.Parser();
    fs.readFile( 'second.less', function ( error, data ) {
      var dataString = data.toString();
      parser.parse(dataString, function ( err, tree ) {
        if ( err ) {
          return console.error( err );
        }
        console.log( tree.toCSS() );
      });
    });
  1. : → node test.js

CSS, Less, . , less toLess(), tree , toCSS(). , , , , . , Less (. https://github.com/less/less.js/issues/930). http://css2less.cc/, .

0

Source: https://habr.com/ru/post/1544475/


All Articles