compiled-files

statically serve compiled files with gzip & cache
Example
CompiledFiles will generate a route handler that serves a file
including running it through a custom compilation step,
optional caching and optional gzipping.
var CompiledFiles = require("compiled-files")
var resolve = require("resolve")
var path = require("path")
var url = require("url")
var browserify = require("browserify")
var http = require("http")
var ServeBrowserify = CompiledFiles({
findResource: function findResource(req, res, opts) {
var pathname = url.parse(req.url).pathname
var parts = pathname.split("/")
return path.join(opts.root, parts[parts.length - 1])
},
compile: function (location, opts, callback) {
resolve(location, function (err, fileUri) {
if (err) {
return callback(err)
}
var b = browserify([fileUri])
b.bundle(opts, callback)
})
},
contentType: "application/json"
})
http.createServer(ServeBrowserify({
cache: true,
gzip: true,
root: path.join(__dirname, "scripts")
}))
Installation
npm install compiled-files
Contributors
MIT Licenced