koa-less2x

2.0.1 • Public • Published

koa-less2x

Less2 middleware for koa2. A wrapper of less-middleware.

Installation

$ npm install koa-less2x

Example

var less = require('koa-less2x');
var serve = require('koa-static');
var koa = require('koa');
var app = new koa();
 
app.use(less('./public'));
 
app.use(serve('./public'));
 
app.listen(3000);

Options

See the less middleware document.

Option Description Default
debug Show more verbose logging? false
dest Destination directory to output the compiled .css files. Same directory as less source files.
force Always re-compile less files on each request. false
once Only recompile once after each server restart. Useful for reducing disk i/o on production. false
pathRoot Common root of the source and destination. It is prepended to both the source and destination before being used. null
postprocess Object containing functions relevant to preprocessing data.
postprocess.css Function that modifies the compiled css output before being stored. function(css, req){...}
preprocess Object containing functions relevant to preprocessing data.
preprocess.less Function that modifies the raw less output before being parsed and compiled. function(src, req){...}
preprocess.path Function that modifies the less pathname before being loaded from the filesystem. function(pathname, req){...}
preprocess.importPaths Function that modifies the import paths used by the less parser per request. function(paths, req){...}
render Options for the less render. See the "render Options" section below.
storeCss Function that is in charge of storing the css in the filesystem. function(pathname, css, req, next){...}
cacheFile Path to a JSON file that will be used to cache less data across server restarts. This can greatly speed up initial load time after a server restart - if the less files haven't changed and the css files still exist, specifying this option will mean that the less files don't need to be recompiled after a server restart.

render Options

The options.render is passed directly into the less.render with minimal defaults or changes by the middleware.

The following are the defaults used by the middleware:

Option Default
compress auto
yuicompress false
paths []

Example of use:

var path=require('path');
app.use(require('koa-less2x')('/my/less/source/path', {
  dest: path.join(__dirname, 'public')
}));

Troubleshooting

My less never recompiles, even when I use {force: true}!

Make sure you're declaring less-middleware before your static middleware, if you're using the same directory, e.g. (with koa-static):

var lessMiddleware = require('koa-less2x');
var app = new koa();
app.use(lessMiddleware(__dirname + '/public'));
app.use(require('koa-static')(__dirname + '/public'));

IIS

If you are hosting your app on IIS you will have to modify your web.config file in order to allow NodeJS to serve your CSS static files. IIS will cache your CSS files, bypassing NodeJS static file serving, which in turn does not allow the middleware to recompile your LESS files.

License

MIT

Readme

Keywords

Package Sidebar

Install

npm i koa-less2x

Weekly Downloads

1

Version

2.0.1

License

MIT

Last publish

Collaborators

  • xujinnet