Mirror
Aggregates JavaScript, CSS and any other text files for serving them to browsers with express. Supports wrapping and postprocessing outputs. A mirror can contain files, plain source code or other mirrors.
Usage
var mirror = require('mirror');
var styles = new mirror([
__dirname + '/assets/main.css',
__dirname + '/assets/layout.css'
]);
var configuration = new mirror([
mirror('var basepath = "/"'),
mirror('var config = ' + JSON.stringify(config)),
mirror(function(callback, req, res) {
callback(null, 'var url = ' + JSON.stringify(req.url));
})
], {
type: 'js',
maxAge: 60
});
var files = [
require.resolve('underscore'),
require.resolve('backbone'),
require.resolve('mymodule/client.js'),
configuration
];
app.get('/assets/style.css', styles);
app.get('/assets/configuration.json', configuration);
app.get('/assets/scripts.js', new mirror(files, { minify: true }));
NOTE: Mirror loads the requested files from disk for every request. It is meant to run behind a reverse proxy that caches. You can control the cache time with maxAge
(in seconds) in the options hash.
Authors