node package manager
It’s your turn. Help us improve JavaScript. Take the 2017 JavaScript Ecosystem Survey »



Build Status

Middleware for Connect to allow resource transformation via streams.

This middleware was written to support development with gulp.js, and is not at all (not even a little bit) intended to be used standalone or in any kind of production capacity. So don't do that.

Instead, do this:

var gulp = require('gulp');
var connect = require('connect');
var pipeline = require('connect-resource-pipeline');
var less = require('gulp-less');
gulp.task('serve', function () {
    var app = connect();
    app.use(pipeline({root: 'public'}, [
        // Define URLs to match and map them to globs (that are automatically concatenated) 
        {url: '/all.js', files: ['js/*.js']},
        // Pipe through your favorite gulp plugins! 
        {url: '/styles.css', files: ['less/*.less'], pipeline: function (files) {
            return files.pipe(less());


npm i connect-resource-pipeline --save


var middleware = pipeline([options, ] targets)


An object which may contain:

  • root

    Type: string

    Will be used to prefix all non-absolute paths in files, or the URL path if files is empty.


An array that defines URLs to be matched and what to return as a response. Each entry is an object comprised of:

  • url

    Type: string|RegExp

    The URL to match. Matched against url.parse(req.url).pathname.

  • cache (optional)

    Type: string|boolean

    Enables caching of pipeline output. Set to true to enable with the URL used as the cache key, or any string to enable with string used as the cache key.

  • files (optional)

    Type: string|string[]

    File paths to match. Uses vinyl-fs under the hood, so globs are allowed. If omitted, the pathname of the request will be used.

  • pipeline (optional)

    Type: function(stream.Readable, Request): stream.Readable

    A function that takes a stream of files as an argument and returns the result stream. The request object is passed as the second argument.

  • DEPRECATED factories (optional)

    An array of factories that produce processors (gulp plugins). The matched files will be piped through each factory's plugin, in order, before being concatenated and sent as a response.

    This functionality has been deprecated in favor of the far more flexible and gulp-like pipeline property.


Clear the contents of cacheKey in the internal cache.


If you want to cache output and retain the ability to clear the cache (for example within a watch), save a reference to the middleware instance you pass to app.use().

var gulp = require('gulp');
var connect = require('connect');
var pipeline = require('connect-resource-pipeline');
gulp.task('serve', function () {
    var middleware = pipeline([
        {url: '/all.js', cache: 'js', files: ['public/js/*.js']}
    ]);'public/js/*.js', function () {
    var app = connect();

Connect compatibility

This has been tested with Connect 2.x and 3.x.


Sometimes doing neat things with your build makes running a local development server harder. Wouldn't it be nice if you could use the same plugins your build uses as part of a dynamic dev server? Yes, it would.