asset-pipe

A simple asset templating library that turns html template tags into js and css links

A function that replaces {{ js }} and {{ css }} template tags in html with the appropriate script and css link tags

    var AssetPipe = require('AssetPipe');
    var pipe = new AssetPipe(); // instantiates a new asset pipe with scripts and styles loaded from the assets.json file 
    var inputHtml = '<head>{{ js }} {{ css }}</head>';
    var parsedHtml = pipe.parse(inputHtml);

assets.json:

     {
            "environment":"development", 
            "development" :
                {   
                    "scripts" : { "jquery": "jquery.js"}, 
                    "styles" : { "main": "main.css"}
                },
            "production" : 
                {
                    "scripts" : { "jquery" : "jquery.min.js", "build" : "app/build.js" },
                    "styles" : { "main": "main.min.css"}
                }
 
    }

This would output

    <head><script src="/jquery.js" type="text/javascript"></script><link href="/main.css" rel="stylesheet" /></head>

The AssetPipe constructor optionally takes two parameters , "config", and "basePath". "config" replaces the json file with the given config, and the "basePath" parameter prepends a base path before the script and style sources.