1

I have following folder structures and less files to compile using less-middleware. But its not working. I tried all tutorial that I have found on googling. Anyone plz help.

app.use(lessMiddleware(__dirname + '/public/less'));

folder structure is -

public/app.css (where would like to get the output)
//source folders are.
public/less/layout.less, master.less

What I am doing wrong here?

4
  • What are you trying to do, compile the .less in css and then serve these css files, or do you want to serve the less files directly? Wich less middleware are you using? Commented Apr 20, 2016 at 14:10
  • var lessMiddleWare = require('less-middleware'); I am trying to compile all the less files into css files. I would very much like to have all less files compiles down to let's say app.css file. Do i need to use express-less or less-middleware would be fine. cheers. Commented Apr 20, 2016 at 14:20
  • and what exactly is not working, what is your expected behaviour? Commented Apr 20, 2016 at 14:23
  • After running node app.js I was expecting the css folder would contain all less file or more accurately one css with all style from less files. But I am getting nothing. Commented Apr 20, 2016 at 14:24

1 Answer 1

1

The package less-middleware does not compile less Files to Css Files.

For your problem you should look at gulp.

Gulp helps you with building your project like compiling less to css and much more.

With gulp you can use the gulp plugin gulp-less wich compiles your less.

var less = require('gulp-less');
var path = require('path');     

gulp.task('less', function () {
  return gulp.src('./less/**/*.less')
    .pipe(less({
      paths: [ path.join(__dirname, 'less', 'includes') ]
    }))
    .pipe(gulp.dest('./public/css'));
});

Now you just need to run gulp less to compile your less. With gulp you can even watch your less files and compile every time they change.

Sign up to request clarification or add additional context in comments.

4 Comments

Do I need to put this in gulpfile.js?
Yup. put that into gulpfile.js and run it by gulp less
Also, you may want to add a clean task to remove all the css files beforehand.
I have tried that. doesn't work. I have tried with @Nick D's snippet but its not working. here is the link --- jsfiddle.net/5t7sez19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.