Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compile less file to css in expressjs 4.x

I want to compile the less file in public folder of expressjs application.

Dependencies which I am using are

"devDependencies": {
    "ejs": "^2.3.1",
    "express": "^4.10.6",
    "mysql": "^2.5.4"
  },
  "dependencies": {
    "less": "^2.5.1",
    "less-middleware": "^2.0.1"
  }

Content in styles.less file

header {
    background-image: url('../img/bg.png');
    height: 380px;

    input#searchBox {
        width: 100%;
        height: 70px;
    }
}

Server file looks like below

var express = require('express'); // call express
var app = express(); // define our app using express
app.use(require('less-middleware')('public'));
// Public folder
app.use(express.static('public'));

The less file is not modified while running it on server.

Remote Address:127.0.0.1:3000
Request URL:http://localhost:3000/css/styles.less
Request Method:GET
Status Code:304 Not Modified

What is the error here.

Directory structure: enter image description here

Edit:

header {
    background-image: url('../img/bg.png');
    height: 380px;
    #cloud-tag span {
        color: #fff;
        font-weight: 800;
        letter-spacing: 2px;
    }
    #cloud-tag_word_0 {
        font-size: 100px !important;
    }
}

I added this css in less file and it is being sent to browser in same format without being compiled.

like image 584
ghost... Avatar asked Jun 02 '15 17:06

ghost...


People also ask

Does LESS compile to CSS?

Less (sometimes stylized as LESS) is one of the dynamic style sheet languages that can be compiled into Cascading Style Sheets (CSS), or can run on the server-side and client-side.

What is LESS file in CSS?

Less (which stands for Leaner Style Sheets) is a backwards-compatible language extension for CSS. This is the official documentation for Less, the language and Less. js, the JavaScript tool that converts your Less styles to CSS styles. Because Less looks just like CSS, learning it is a breeze.

How do I include LESS CSS in HTML?

Create a stylesheet with . less extension and link it in your document using the rel="stylesheet/less" attribute. You are all set and can compose styles within the . less .


1 Answers

You must request the css file, not the less file, in your case http://localhost:3000/css/styles.css not http://localhost:3000/css/styles.less. The middleware will compile the less file to the one you requested.

like image 70
Pierre Inglebert Avatar answered Oct 13 '22 14:10

Pierre Inglebert