Giter VIP home page Giter VIP logo

mirror's Introduction

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');

// Mirror guesses the MIME type based on the first file's extension.
var styles = new mirror([
    __dirname + '/assets/main.css',
    __dirname + '/assets/layout.css'
]);

// Proving direct source input requires specifying the MIME type manually.
var configuration = new mirror([
    // Mirror automatically inserts line breaks and semicolons before/after
    // each item in a "js" type mirror.
    mirror('var basepath = "/"'),
    mirror('var config = ' + JSON.stringify(config)),

    // You can add functions to the mirror. They will be called on each request.
    mirror(function(callback, req, res) {
        callback(null, 'var url = ' + JSON.stringify(req.url));
    })
], {
    type: 'js',
    maxAge: 60  // Only cache configuration file for 60 seconds.
});

// Store the array of files and remove or add files on-the-fly.
var files = [
    require.resolve('underscore'),
    require.resolve('backbone'),
    require.resolve('mymodule/client.js'),

    // Add other mirrors
    configuration
];

// Add the mirrors to your express server.
app.get('/assets/style.css', styles.handler);
app.get('/assets/configuration.json', configuration.handler);
app.get('/assets/scripts.js', (new mirror(files, { minify: true })).handler);

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

mirror's People

Contributors

kkaefer avatar ianshward avatar wildintellect avatar

Watchers

JT5D avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.