Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Less Middleware with Express

Tags:

css

node.js

less

I am trying to setup less on my nodejs project and when i request my page from browser less-middleware debug show me wrong path and dest path. When i ask for example '/public/css/index.css' from my webpage i adds '/public/css/' to the source path. Below are mine configures:

app.use(lessMiddleware(__dirname+'/server/less',{
    debug: true,
    dest: __dirname+'/public/css',
    once: true
}));

And debug screen shows:

pathname : /public/css/index.css
source : D\Work\project\server\less\public\css\index.less
destination : D\Work\project\public\css\public\css\index.css

Even if i fix the destination path, i am having problem with source and i dont want to put my less files into public folder. Is there a way of remove that /public/css from compiled less. I have tried to add:

'preprocess.path': function(pathname, req){
    console.log(pathname);
}

but console.log never shows. Also perhaps there is a way to not compile every css file users ask and just compile those less files which i have in less folder.
P.S. every module i am using is under "*" version.

like image 202
Honchar Denys Avatar asked Jul 03 '15 06:07

Honchar Denys


2 Answers

You might try this (accessing "/css/style.css" within your browser):

app.use(lessMiddleware({
  src: __dirname+"/server/less",
  dest: __dirname+"/public/css",
  prefix: "/css",
  // force true recompiles on every request... not the
  // best for production, but fine in debug while working
  // through changes
  force: true,
  debug: true
}));
like image 179
Michael Blankenship Avatar answered Nov 04 '22 01:11

Michael Blankenship


Actually it was simple enough.

app.use(lessMiddleware(__dirname+'/server/less/',{
    debug: true,
    dest: __dirname,
    force: true
}));

So now in the folder /server/less we create folder public/css and everything is pulling in right way. Also if we have folder admin/css it works too. Trick was to create folders in folder /server/less

like image 38
Honchar Denys Avatar answered Nov 04 '22 01:11

Honchar Denys