npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

express-less-middleware

v3.0.0

Published

Compiles LESS on a per request basis in Express

Downloads

16

Readme

Express LESS Middleware Build Status Coverage Status

This middleware is designed to compile LESS on the fly.

NPM Greenkeeper badge

Installing

npm install --save express-less-middleware

Should only be used for development. LESS should be compiled during a build process

What this does (per request)

  1. Determines if file requested is: (if conditions aren't met it runs next())
    1. requested via GET method
    2. a CSS file
  2. Looks for CSS file requested
    • if found it will let it go through the original flow via next
  3. Looks for a LESS file with the same name as the CSS file requested
    • if LESS file is found it will read that file and compile it to CSS and deliever the response
  4. If no LESS or CSS file is found, it will give you a 404 like usual

What this doesn't do

  1. Look for changes on save (if you use it, you won't need a grunt watch on less files)

Setup

lessMiddleware( options )

  • options
    • required: no
    • default: ./public (string)
    • Type: String or Object
      • String - will be path to express public directory.*
      • Object - less parser options
        • options.publicDir - same value as if options were a string. Same default value
        • options.paths*

* paths should be relative to cwd. path.join is used with process.cwd() as first argument when processing all paths

Example

const http = require("http");
const express = require("express");
const app = express();

// this assumes that the publicly available folder is on the same directory level
// as the file that starts your express server
const lessCompiler = require("express-less-middleware")();

// if that's not the case, initialize it with the path to your public/client-side folder
// the path should be relative to the directory where the file that starts your express server is
// Example below.
//
//    const lessCompiler = require( 'express-less-middleware' );
//    lessCompiler     = lessCompiler( '../path/to/public/folder' );
// OR
//    const lessCompiler = require( 'express-less-middleware' );
//    lessCompiler     = lessCompiler({ publicDir: '../path/to/public/folder', ... });

// ....everything else that has to do with configuring

// you should only use this when developing. Not meant for production
if (process.env.NODE_ENV === "dev") {
  // this must be "used" before express.use( express.static() ) or it will not work (no next())
  app.use(lessCompiler);
}

// ....other stuff relative to your express app

http.createServer(app).listen(8000);

License

MIT