app.js:
app.use(express.compiler({ src: __dirname + '/public', enable: ['less']}));
app.use(express.static(__dirname + '/public'));
In my jade view:
link(rel="stylesheet", type="text/css", href='/app/stylesheets/app.less)
I’ve got less file in:
public/app/stylesheets/app.less
When I request the page I’ve got in html head:
<link href="/app/stylesheets/app.less" type="text/css" rel="stylesheet">
And noting in server console.
1) So Why does express even doesn’t try to compile app.less? Should it?
2) If everything right: should link in htm be
<link href="/app/stylesheets/**app.less**" ... >
or express should change the file’s extension while render?
<link href="/app/stylesheets/**app.css**" ... >
?
It seems that compiler() was removed from connect and it won’t be supported anymore, according to TJ Holowaychuck (creator of Connect & Express):
https://github.com/visionmedia/express/issues/877
Update 2013-01-16
As of Express 3.0.0 the framework now includes
less-middlewareinstead of thecompilermiddleware that used to be in Connect. It works much the same way as the old middleware.To add it to an existing project, add
less-middlewareto yourpackage.jsonand runnpm installthen add the following to your config:In your Jade template you reference it as a normal CSS file:
Your directory structure will look something like this:
less-middlewarewill look for .less files that have the same name as the .css file that was requested. If it finds one it will compile it and server the resulting CSS.You’ll probably want to exclude compiled CSS files from your source control. If you’re using Git you can add
.cssto your.gitignorefile.