Trying to build LESS (less css) using build script with nodeJS

We use NodeJS to create our project. We have included LESS CSS as part of the project. We are trying to keep our assembly clean and would like to be able to invoke the lessc command (or something similar) to create our LESS files.

The LESS documentation is not very deep, but wanted to contact the community to find a solution. Google was not too helpful to me on this topic.

We have a build.sh file that calls various other build.js files (in the corresponding directories). How to run LESSC to compile my LESS files?

+4
source share
2 answers

Using node.js

var less = require('less')
    ,fs = require('fs');

fs.readFile('style.less',function(error,data){
    data = data.toString();
    less.render(data, function (e, css) {
        fs.writeFile('style.css', css, function(err){
            console.log('done');
        });
    });
});
+11
source

... less@3.9.0 :

{
  css: 'rendered css',
  imports: ['source.css']
}

:

const outputFile = 'style-iso.css';

const data = '.bootstrap-iso {
    @import (less) "style.css"; 
} ';

less.render(data).then(
    output => {
        fs.writeFile(outputFile, output.css, err => {
            if (err) {
                throw err;
            }
            console.log('${outputFile} saved!');
        });
    },
    err => {
        console.error(err);
    });
0

All Articles