koa-bundle
Generic asset pipeline with caching, etags, minification, gzipping and sourcemaps.
The child of node-enchilada and static-cache.
Examples
- Browserify (with a callback and options)
var bundle = )app;
- Duo (using generators)
var bundle = app;
- Gulp (using currying and globbing)
var bundle = ; // ... in another file, single middlewareapp; // multiple endpoints;;
Installation
npm install koa-bundle
API
bundle(settings, handler) => bundler([path]) => middleware
bundle(handler)(glob) => bundler([path]) => middleware
Create a bundler with an optional set of settings
and a handler
.
A handler
can be a synchronous function, asynchronous function, generator or promise. The handler passes a File
object that has the following properties:
var File = type: "js" src: "... JS ..." path: "dashboard.js" root: "/Users/Matt/Projects/..." minify: true debug: false cache: true gzip: true
The available settings
are:
debug
: enables sourcemapsminify
: minify JS and CSScache
: cache responses across requests and add etagsgzip
: gzip the response if it's supported
The default settings depend on the environment (NODE_ENV
):
-
Production:
debug
: falseminify
: truecache
: truegzip
: true
-
Development:
debug
: trueminify
: falsecache
: falsegzip
: false
The bundler returns a function that you can then pass a path
into:
var bundle = ;app;
The path
is relative to settings.root
or process.cwd()
. The script[src]
and link[href]
is relative the root
specified.
TODO
- Warmup cache in production
- More examples
- Testing
Credits
- node-enchilada and browserify-middleware for some ideas and general design.
- static-cache for the caching, etagging and gzipping.
- sponsored by Lapwing Labs.
License
MIT
Copyright (c) 2015 Matthew Mueller <matt@lapwinglabs.com>