Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I minify CSS using `less` in `express-js`?

  app.use(express.compiler({ src: __dirname + '/public', enable: ['less'] }));

That's the line in my app.js that enables less. How can I pass the { compress: true } parameter to it?

like image 903
Shamoon Avatar asked Sep 10 '11 17:09

Shamoon


People also ask

How do you minify CSS and JavaScript?

To minify CSS, try CSSNano and csso. To minify JavaScript, try UglifyJS. The Closure Compiler is also very effective. You can create a build process that uses these tools to minify and rename the development files and save them to a production directory.


1 Answers

I also had this problem and thought this can be useful to share with others:

var lessMiddleware = require('less-middleware');
app.use(lessMiddleware({ src: __dirname + '/public', compress: true, optimization: 2 }));

More information and settings about the minify-process can be found in the Less-Middleware README.md

like image 152
ndequeker Avatar answered Oct 04 '22 17:10

ndequeker