How to import LESS through npm ?
LESS stands for Leaner Style Sheets. It is a backward-compatible language extension for CSS. Web pages can be styled by writing appropriate code in a file with .less extension and then converting it in a CSS file.
Steps to install LESS:
Step 1: To install LESS, first make sure that node and npm are already installed in the system. If not, then install them using the instructions given below.
- Download the latest version of node in the system and install it.
- Now open command prompt and move to your project folder.
- Now you need to create a package.json file to manage the dependencies. To do so, use the command given below.
After which you will be asked for the package name of the user’s choice and the description. For other formalities, just press enter and your package.json file will be created.
Step 2: Now install LESS using the command:
npm install less
Note: Install the LESS npm module globally so that it can be used by any project, use the command npm install less -g. If you are executing this on a Mac or Linux machine, you may need to add “sudo” to the beginning of this command.
Step 3: To compile .less file, use the command:
lessc input.less output.css
Note: Make sure that you run this command in the same folder which contains input.less file. This completes the compilation of the LESS file to CSS file which can now be added to the HTML file.