Created
September 27, 2010 18:39
-
-
Save rmanalan/599562 to your computer and use it in GitHub Desktop.
Psuedo code for a JS/CSS packager for static HTML apps
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//manifest.js: defines the grouping of js/css | |
var $packager.assets = { | |
'app.js': [ | |
{ name:'jquery.js', wait:true }, | |
{ name:'sfasdf.js', wait:true }, | |
{ name:'fasdt.js', wait:true } | |
], | |
'app.css': [ | |
'blueprint.css', | |
'style.css' | |
] | |
} | |
// config.js: defines the environment you're currently in. | |
// if mode == development, non-minified/non-compressed js files are loaded, | |
// else if mode == production, only the minified/compressed version is loaded | |
var $packager.config = { mode: 'development' } | |
//index.html | |
<script src="config.js"></script> | |
<script src="package.js"></script> | |
<script> | |
$packager.use('app.js') | |
</script> | |
// $packager.use is how you load your js. Underneath it uses LABjs | |
$packager.use = function(scriptName){ | |
if($packager.config.mode=='production'){ | |
$LAB.script(scriptName) | |
} else { | |
for(var script in $packager.assets[scriptName]) { | |
if(script.wait) $LAB.script(script.name).wait(); | |
else $LAB.script(script.name); | |
} | |
} | |
} | |
// of course we need a CLI based builder that will spit out | |
// compressed/minified versions of the js/css defined in | |
// the manifest.js | |
// | |
// $ node build.js manifest.js |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment