Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

less-middleware

Package Overview
Dependencies
Maintainers
2
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

less-middleware

LESS.js middleware for connect.

  • 3.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
11K
decreased by-51.34%
Maintainers
2
Weekly downloads
 
Created
Source

This middleware was created to allow processing of Less files for Connect JS framework and by extension the Express JS framework.

CircleCI Dependency Status

Installation

npm install less-middleware --save

Usage

lessMiddleware(source, [{options}])

Express

var lessMiddleware = require('less-middleware');

var app = express();
app.use(lessMiddleware(__dirname + '/public'));
app.use(express.static(__dirname + '/public'));

options

The following options can be used to control the behavior of the middleware:

OptionDescriptionDefault
debugShow more verbose logging?false
destDestination directory to output the compiled .css files.Same directory as less source files.
forceAlways re-compile less files on each request.false
onceOnly recompile once after each server restart. Useful for reducing disk i/o on production.false
pathRootCommon root of the source and destination. It is prepended to both the source and destination before being used.null
postprocessObject containing functions relevant to postprocessing data.
postprocess.cssFunction that modifies the compiled css output before being stored.function(css, req){...}
preprocessObject containing functions relevant to preprocessing data.
preprocess.lessFunction that modifies the raw less output before being parsed and compiled.function(src, req){...}
preprocess.pathFunction that modifies the less pathname before being loaded from the filesystem.function(pathname, req){...}
preprocess.importPathsFunction that modifies the import paths used by the less parser per request.function(paths, req){...}
renderOptions for the less render. See the "render Options" section below.
storeCssFunction that is in charge of storing the css in the filesystem.function(pathname, css, req, next){...}
cacheFilePath 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:

OptionDefault
compressauto
yuicompressfalse
paths[]

Examples

Common examples of using the Less middleware are available in the wiki.

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 express):

var lessMiddleware = require('less-middleware');

var app = express();
app.use(lessMiddleware(__dirname + '/public'));
app.use(express.static(__dirname + '/public'));

not

var lessMiddleware = require('less-middleware');

var app = express();
app.use(express.static(__dirname + '/public'));
app.use(lessMiddleware(__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.

FAQs

Package last updated on 15 Jan 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc