开发者

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

开发者 https://www.devze.com 2023-04-03 19:34 出处:网络
app.use(express.compiler({ src: __dirname + \'/public\', enable: [\'less\'] })); Tha开发者_C百科t\'s the line in my app.js that enables less. How can I pass the { compress: true } parameter to it?I
  app.use(express.compiler({ src: __dirname + '/public', enable: ['less'] }));

Tha开发者_C百科t's the line in my app.js that enables less. How can I pass the { compress: true } parameter to it?


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


use less4clients with the compress option

I deprecated and removed the less4clients package which extends a express.js server with a less css rendering middleware to render less files to css on the fly (and cache the results in memory) in favor of a newer project of mine called DocPad that lets you use any pre-processor you want.

As of this time of writing, it does not have an easy to use express middleware like less4clients, however such a thing is on the roadmap soon. Instead you can use it standalone or via its API.

In hindsight I should have kept less4clients available and just stated in it's readme that DocPad is the new way of doing things, but I never realised less4clients was actually being used by anyone as DocPad has already gained so much attention.


Sadly, you can't and use connect's compiler to do it. The connect.compiler, which is what express.compiler is, only allows you to set which compilers to use, but not any options for the individual compilers. If you want to set less.js's compress flag you will need to create you're own middleware that user the less.js module.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号