Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

css

node.js

less

We are using NodeJS to build our project. We have integrated LESS CSS as a part of the project. We are attempting to keep our build clean and would like to be able to call the lessc command (or something comparable) in order to build our LESS files.

The LESS documentation isn't very in depth, but wanted to reach out to the community to find a solution. Google has not be too helpful to me on this topic.

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

like image 944
Bryan Kohlmeier Avatar asked May 03 '12 15:05

Bryan Kohlmeier


People also ask

How do you make a CSS file less?

It has additions such as variables, mixins, operations, and functions. They help make the code cleaner and easier to maintain. Creating and Storing a LESS File: Step 1: Go to your project folder, create a subfolder named CSS and then create a file named styles.

How do I edit less CSS?

Most likely you need to compile you're Less Files into CSS. You can do this manually, or with a task runner like Gulp. If you already have compiled the file, it could be that the compiled css file is cached in the browser and the browser cache needs to be cleared.

How do I include less CSS in HTML?

Make sure you include your stylesheets before the script. You should compile your less-file to css-file and include it in your <head> -section as is without any less- or js-files.

Does less need to be compiled?

Using Less. js in the browser is the easiest way to get started and convenient for developing with Less, but in production, when performance and reliability is important, we recommend pre-compiling using Node.


1 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');
        });
    });
});
like image 200
Ripter Avatar answered Nov 15 '22 10:11

Ripter