Now less files with @import 'whatever.less' will work #174

wants to merge 9 commits into


None yet

8 participants


(less.compile takes a stat path that connect wasn't giving to it)

I committed a billion times just to get the quick fix in and pull it into the project that already has @imports... tips on how to compress commits into one easier to read one are welcome ;)


masylum commented Mar 21, 2011


I had a similar pull request pending on last connect but never got into the master. I thing is good to have the option to force compilation in development environments.

aseemk commented May 11, 2011


I coincidentally filed this issue with LESS a week ago: less/less.js#255

Here's the super simple test case I wrote:



I think this could be generalized by adding compilerOptions to the compiler middleware.

Essentially what we need is a way to pass options to LESS.render.

That being said, this is what I am using in the meantime:

var less = require('less');
var origRender = less.render;
less.render = function(str, options, fn) {
  if (typeof(options) === 'function') {
    fn = options;
    options = { paths: [__dirname + '/public/css'] };
  return, str, options, fn);
tj commented May 15, 2011

it's getting a bit ridiculous though :p the more we have to tweak things for specific "compilers" the more I think they should each just supply their own if they wish, stylus was to specific for this middleware as well


If you could abstract the compiler middleware a bit so that we could re-use parts of it, I wouldn't mind writing a LESS compiler middleware.

tj commented May 16, 2011

I think we should remove it in 2.0


tips on how to compress commits into one easier to read one are welcome

If the commits you want to compress are at the top of the history (i.e. all the latest commits after a certain point) then its easy to squash commits with an interactive rebase.

This destroys history and can go wrong so do it on a branch git checkout -b squash-branch

Start an interactive rebase on the ref of the last commit immediately before your commits git rebase -i ref

If you did your commits on a new branch off master you could supply e.g. master as the ref to the HEAD commit of master, or if you just did your commits on master you could supply a commit ref like 398662d.

Your editor should launch listing the commits. Leave the top commit as pick while changing pick on all other lines to s. Save and quit. The rebase will start, I guess its possible you will need to resolve conflicts but it usually doesn't happen in cases where squashing commits makes sense.

Your editor should launch again once finished to allow you to edit the final squashed commits message.

Golden rule never ever change history that has been shared with others. only do this with private history before you push to github.


I currently use the following hack to support relative imports:

// Code goes in your app.configure function

// Hack connect.js to allow relative @import statements in less.js
var less = require('less'),
    staticDir = '/static',
    lessDir = staticDir + '/style';
express.compiler.compilers.less.compile = function(str, fn){
    try {
        less.render(str, {paths: [__dirname + lessDir]}, fn);
    } catch (err) {

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

app.use(staticDir, express['static'](__dirname + staticDir, {maxAge: 1000 * 60 * 60 * 24 * 365}));

I use this way to keep my project compatible with vanilla connect.js.

tofutim commented Jun 21, 2012

@adrianlang I found that less.compile is not being called in your hack. Is there something else that is missing?
@cjoudrey Your fix works on my end. Any changes since 10 mos ago?

tj commented Jun 21, 2012

this middleware is deprecated, there's one specific to less now (from the stylus code) called less-middleware I believe

@tj tj closed this Jun 21, 2012
tofutim commented Jun 21, 2012

@visionmedia Thanks! For anyone lese running into this thread, 'less-middleware' does the trick.

sudo npm install less-middleware -g

app.use(require('less-middleware')({ src: __dirname + staticDir}));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment