GithubHelp home page GithubHelp logo

artempronevskiy / less.js-middleware Goto Github PK

View Code? Open in Web Editor NEW

This project forked from emberfeather/less.js-middleware

0.0 0.0 0.0 171 KB

Connect Middleware for LESS.js compiling

License: MIT License

JavaScript 100.00%

less.js-middleware's Introduction

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:

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 postprocessing 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 []

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.

less.js-middleware's People

Contributors

zoramite avatar laveklint avatar nyteshade avatar viveksjain avatar courajs avatar hdanak avatar johngeorgewright avatar paton avatar danielhusar avatar emecell avatar taxilian avatar k88hudson avatar federicobond avatar daemonl avatar hazukishiro avatar pdehaan avatar nchase avatar neekey avatar namuol avatar kersten avatar kaareal avatar jorundur avatar jbuck avatar kamikat avatar grahamb avatar edy avatar meatcar avatar rush avatar 0b10011 avatar andreineculau avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.